@@ -47,13 +47,29 @@ export interface FileInformation {
47
47
definitions : LocalCallDefinition [ ]
48
48
}
49
49
50
+ const log = process . env . VITEST_VSCODE_DEBUG
51
+ ? ( ...args : any [ ] ) => {
52
+ // eslint-disable-next-line no-console
53
+ console . info ( ...args )
54
+ }
55
+ : undefined
56
+
57
+ const verbose = process . env . VITEST_VSCODE_DEBUG === 'verbose'
58
+ ? ( ...args : any [ ] ) => {
59
+ // eslint-disable-next-line no-console
60
+ console . info ( ...args )
61
+ }
62
+ : undefined
63
+
50
64
export async function astCollectTests (
51
65
ctx : WorkspaceProject ,
52
66
filepath : string ,
53
67
) : Promise < null | FileInformation > {
54
68
const request = await ctx . vitenode . transformRequest ( filepath , filepath , 'web' )
55
69
// TODO: error cannot parse
70
+ const testFilepath = relative ( ctx . config . root , filepath )
56
71
if ( ! request ) {
72
+ log ?.( 'Cannot parse' , testFilepath , '(vite didn\'t return anything)' )
57
73
return null
58
74
}
59
75
const ast = parse ( request . code , {
@@ -62,7 +78,6 @@ export async function astCollectTests(
62
78
allowHashBang : true ,
63
79
allowImportExportEverywhere : true ,
64
80
} )
65
- const testFilepath = relative ( ctx . config . root , filepath )
66
81
const file : ParsedFile = {
67
82
filepath,
68
83
type : 'suite' ,
@@ -77,6 +92,7 @@ export async function astCollectTests(
77
92
file : null ! ,
78
93
}
79
94
file . file = file
95
+ log ?.( 'Collecting' , testFilepath )
80
96
const definitions : LocalCallDefinition [ ] = [ ]
81
97
const getName = ( callee : any ) : string | null => {
82
98
if ( ! callee ) {
@@ -108,14 +124,17 @@ export async function astCollectTests(
108
124
const name = getName ( callee )
109
125
let unknown = false
110
126
if ( ! name ) {
127
+ verbose ?.( 'Unknown call' , callee )
111
128
return
112
129
}
113
130
if ( ! [ 'it' , 'test' , 'describe' , 'suite' ] . includes ( name ) ) {
131
+ verbose ?.( `Skipping ${ name } (unknown call)` )
114
132
return
115
133
}
116
134
const property = callee ?. property ?. name
117
135
let mode = ! property || property === name ? 'run' : property
118
136
if ( mode === 'each' ) {
137
+ log ?.( 'Skipping `.each` (support not implemented yet)' , name )
119
138
return
120
139
}
121
140
@@ -156,6 +175,7 @@ export async function astCollectTests(
156
175
if ( mode === 'skipIf' || mode === 'runIf' ) {
157
176
mode = 'skip'
158
177
}
178
+ log ?.( 'Found' , name , message , `(${ mode } )` )
159
179
definitions . push ( {
160
180
start,
161
181
end,
@@ -193,8 +213,20 @@ export async function astCollectTests(
193
213
column : processedLocation . column ,
194
214
} )
195
215
if ( originalLocation . column != null ) {
216
+ verbose ?.(
217
+ `Found location` ,
218
+ `${ processedLocation . column } :${ processedLocation . line } ` ,
219
+ '->' ,
220
+ `${ originalLocation . column } :${ originalLocation . line } ` ,
221
+ )
196
222
location = originalLocation
197
223
}
224
+ else {
225
+ log ?.( 'Cannot find original location' , `${ processedLocation . column } :${ processedLocation . line } ` )
226
+ }
227
+ }
228
+ else {
229
+ log ?.( 'Cannot find original location' , `${ definition . start } ` )
198
230
}
199
231
if ( definition . type === 'suite' ) {
200
232
const task : ParsedSuite = {
@@ -224,7 +256,7 @@ export async function astCollectTests(
224
256
suite : latestSuite ,
225
257
file,
226
258
mode,
227
- context : { } as any , // not used in typecheck
259
+ context : { } as any , // not used on the server
228
260
name : definition . name ,
229
261
end : definition . end ,
230
262
start : definition . start ,
@@ -245,6 +277,17 @@ export async function astCollectTests(
245
277
false ,
246
278
ctx . config . allowOnly ,
247
279
)
280
+ if ( ! file . tasks . length ) {
281
+ file . result = {
282
+ state : 'fail' ,
283
+ errors : [
284
+ {
285
+ name : 'Error' ,
286
+ message : `No test suite found in file ${ filepath } ` ,
287
+ } ,
288
+ ] ,
289
+ }
290
+ }
248
291
return {
249
292
file,
250
293
parsed : request . code ,
@@ -268,7 +311,7 @@ function mergeTemplateLiteral(node: TemplateLiteral): string {
268
311
return result
269
312
}
270
313
271
- export function createIndexMap ( source : string ) {
314
+ function createIndexMap ( source : string ) {
272
315
const map = new Map < number , { line : number ; column : number } > ( )
273
316
let index = 0
274
317
let line = 1
0 commit comments