Commit 1be07ed 1 parent 82894d3 commit 1be07ed Copy full SHA for 1be07ed
File tree 5 files changed +127
-5
lines changed
5 files changed +127
-5
lines changed Original file line number Diff line number Diff line change @@ -98,8 +98,8 @@ export class EvaluationTestDiscoverer implements ITestDiscoverer {
98
98
sourceMap ?: TraceMap | undefined ,
99
99
directive ?: string ,
100
100
) {
101
- const fn = ( name : string , callback : ( ) => void ) => {
102
- if ( typeof name !== 'string' || typeof callback !== 'function' ) {
101
+ const fn = ( name : string , callback : ( ( ) => void ) | undefined ) => {
102
+ if ( typeof name !== 'string' ) {
103
103
return placeholder ( ) ;
104
104
}
105
105
@@ -114,7 +114,7 @@ export class EvaluationTestDiscoverer implements ITestDiscoverer {
114
114
let startColumn = frame . columnNumber || 1 ;
115
115
116
116
// approximate the length of the test case:
117
- const functionLines = String ( callback ) . split ( '\n' ) ;
117
+ const functionLines = String ( callback ?? '' ) . split ( '\n' ) ;
118
118
let endLine = startLine + functionLines . length - 1 ;
119
119
let endColumn = functionLines [ functionLines . length - 1 ] . length + 1 ;
120
120
@@ -167,7 +167,7 @@ export class EvaluationTestDiscoverer implements ITestDiscoverer {
167
167
if ( kind === NodeKind . Suite ) {
168
168
stack . push ( node ) ;
169
169
try {
170
- return callback . call ( placeholder ( ) ) ;
170
+ return typeof callback === 'function' ? callback . call ( placeholder ( ) ) : placeholder ( ) ;
171
171
} catch ( e ) {
172
172
node . error = e instanceof Error ? e . message : String ( e ) ;
173
173
} finally {
Original file line number Diff line number Diff line change @@ -104,7 +104,7 @@ export class SyntaxTestDiscoverer implements ITestDiscoverer {
104
104
105
105
traverse ( ast , {
106
106
enter ( node ) {
107
- if ( node . type !== C . CallExpression || node . arguments . length < 2 ) {
107
+ if ( node . type !== C . CallExpression || node . arguments . length === 0 ) {
108
108
return ;
109
109
}
110
110
Original file line number Diff line number Diff line change @@ -197,4 +197,37 @@ describe('evaluate typescript', () => {
197
197
} ,
198
198
] ) ;
199
199
} ) ;
200
+
201
+ it ( 'works with pending test' , async ( ) => {
202
+ const src = await extractWithEvaluation (
203
+ 'function topLevel(a: number): string {' , //
204
+ ' return a.toString() as string;' ,
205
+ '}' ,
206
+ '' ,
207
+ "suite('hello', () => {" , //
208
+ " it('works');" ,
209
+ '})' ,
210
+ ) ;
211
+ expect ( src ) . to . deep . equal ( [
212
+ {
213
+ name : 'hello' ,
214
+ kind : NodeKind . Suite ,
215
+ startLine : 4 ,
216
+ startColumn : 0 ,
217
+ endColumn : 1 ,
218
+ endLine : 6 ,
219
+ children : [
220
+ {
221
+ name : 'works' ,
222
+ kind : NodeKind . Test ,
223
+ startLine : 5 ,
224
+ startColumn : 2 ,
225
+ endColumn : Number . MAX_SAFE_INTEGER ,
226
+ endLine : 5 ,
227
+ children : [ ] ,
228
+ } ,
229
+ ] ,
230
+ } ,
231
+ ] ) ;
232
+ } ) ;
200
233
} ) ;
Original file line number Diff line number Diff line change @@ -162,6 +162,51 @@ describe('evaluate', () => {
162
162
] ) ;
163
163
} ) ;
164
164
165
+ it ( 'works with pending test' , async ( ) => {
166
+ const src = await extractWithEvaluation (
167
+ "suite('hello', () => {" , //
168
+ " it('works');" ,
169
+ '})' ,
170
+ ) ;
171
+ expect ( src ) . to . deep . equal ( [
172
+ {
173
+ name : 'hello' ,
174
+ startLine : 0 ,
175
+ kind : NodeKind . Suite ,
176
+ startColumn : 0 ,
177
+ endColumn : 1 ,
178
+ endLine : 2 ,
179
+ children : [
180
+ {
181
+ name : 'works' ,
182
+ kind : NodeKind . Test ,
183
+ startLine : 1 ,
184
+ startColumn : 2 ,
185
+ endColumn : Number . MAX_SAFE_INTEGER ,
186
+ endLine : 1 ,
187
+ children : [ ] ,
188
+ } ,
189
+ ] ,
190
+ } ,
191
+ ] ) ;
192
+ } ) ;
193
+
194
+ it ( 'works with pending suite' , async ( ) => {
195
+ const src = await extractWithEvaluation ( "suite('hello')" ) ;
196
+ expect ( src ) . to . deep . equal ( [
197
+ {
198
+ name : 'hello' ,
199
+ startLine : 0 ,
200
+ kind : NodeKind . Suite ,
201
+ startColumn : 0 ,
202
+ endColumn : Number . MAX_SAFE_INTEGER ,
203
+ endLine : 0 ,
204
+ children : [ ] ,
205
+ } ,
206
+ ] ) ;
207
+ } ) ;
208
+
209
+
165
210
it ( 'stubs out requires and placeholds correctly' , async ( ) => {
166
211
const src = await extractWithEvaluation (
167
212
'require("some invalid module").doing().other.things()' ,
Original file line number Diff line number Diff line change @@ -94,6 +94,50 @@ describe('syntax', () => {
94
94
] ) ;
95
95
} ) ;
96
96
97
+ it ( 'works with pending test' , async ( ) => {
98
+ const src = await extractWithAst (
99
+ "suite('hello', () => {" , //
100
+ " it('works');" ,
101
+ '})' ,
102
+ ) ;
103
+ expect ( src ) . to . deep . equal ( [
104
+ {
105
+ name : 'hello' ,
106
+ startLine : 0 ,
107
+ kind : NodeKind . Suite ,
108
+ startColumn : 0 ,
109
+ endColumn : 2 ,
110
+ endLine : 2 ,
111
+ children : [
112
+ {
113
+ name : 'works' ,
114
+ kind : NodeKind . Test ,
115
+ startLine : 1 ,
116
+ startColumn : 2 ,
117
+ endColumn : 13 ,
118
+ endLine : 1 ,
119
+ children : [ ] ,
120
+ } ,
121
+ ] ,
122
+ } ,
123
+ ] ) ;
124
+ } ) ;
125
+
126
+ it ( 'works with pending suite' , async ( ) => {
127
+ const src = await extractWithAst ( "suite('hello')" ) ;
128
+ expect ( src ) . to . deep . equal ( [
129
+ {
130
+ name : 'hello' ,
131
+ startLine : 0 ,
132
+ kind : NodeKind . Suite ,
133
+ startColumn : 0 ,
134
+ endColumn : 14 ,
135
+ endLine : 0 ,
136
+ children : [ ] ,
137
+ } ,
138
+ ] ) ;
139
+ } ) ;
140
+
97
141
it ( 'can detect suite but not dynamic tests' , async ( ) => {
98
142
const src = await extractWithAst (
99
143
"suite('hello', () => {" , //
You can’t perform that action at this time.
0 commit comments