@@ -66,7 +66,7 @@ You can get access to this API by calling `vitest.state.getReportedEntity(runner
66
66
``` ts twoslash
67
67
import type { Vitest } from ' vitest/node'
68
68
import type { RunnerTestFile } from ' vitest'
69
- import type { Reporter , TestFile } from ' vitest/reporters'
69
+ import type { Reporter , TestModule } from ' vitest/reporters'
70
70
71
71
class MyReporter implements Reporter {
72
72
ctx! : Vitest
@@ -77,9 +77,10 @@ class MyReporter implements Reporter {
77
77
78
78
onFinished(files : RunnerTestFile []) {
79
79
for (const fileTask of files ) {
80
- const testFile = this .ctx .state .getReportedEntity (fileTask ) as TestFile
81
- for (const task of testFile .children ) {
82
- // ^?
80
+ // note that the old task implementation uses "file" instead of "module"
81
+ const testModule = this .ctx .state .getReportedEntity (fileTask ) as TestModule
82
+ for (const task of testModule .children ) {
83
+ // ^?
83
84
console .log (' finished' , task .type , task .fullName )
84
85
}
85
86
}
@@ -107,9 +108,9 @@ declare class TestCase {
107
108
*/
108
109
readonly project: TestProject
109
110
/**
110
- * Direct reference to the test file where the test is defined.
111
+ * Direct reference to the test module where the test is defined.
111
112
*/
112
- readonly file : TestFile
113
+ readonly module : TestModule
113
114
/**
114
115
* Name of the test.
115
116
*/
@@ -121,18 +122,18 @@ declare class TestCase {
121
122
/**
122
123
* Unique identifier.
123
124
* This ID is deterministic and will be the same for the same test across multiple runs.
124
- * The ID is based on the project name, file path and test position.
125
+ * The ID is based on the project name, module id and test position.
125
126
*/
126
127
readonly id: string
127
128
/**
128
- * Location in the file where the test was defined.
129
+ * Location in the module where the test was defined.
129
130
* Locations are collected only if `includeTaskLocation` is enabled in the config.
130
131
*/
131
132
readonly location: { line: number ; column: number } | undefined
132
133
/**
133
- * Parent suite. If the test was called directly inside the file , the parent will be the file .
134
+ * Parent suite. If the test was called directly inside the module , the parent will be the module itself .
134
135
*/
135
- readonly parent: TestSuite | TestFile
136
+ readonly parent: TestSuite | TestModule
136
137
/**
137
138
* Options that test was initiated with.
138
139
*/
@@ -241,9 +242,9 @@ declare class TestSuite {
241
242
*/
242
243
readonly project: TestProject
243
244
/**
244
- * Direct reference to the test file where the suite is defined.
245
+ * Direct reference to the test module where the suite is defined.
245
246
*/
246
- readonly file : TestFile
247
+ readonly module : TestModule
247
248
/**
248
249
* Name of the suite.
249
250
*/
@@ -255,11 +256,11 @@ declare class TestSuite {
255
256
/**
256
257
* Unique identifier.
257
258
* This ID is deterministic and will be the same for the same test across multiple runs.
258
- * The ID is based on the project name, file path and test position.
259
+ * The ID is based on the project name, module id and test position.
259
260
*/
260
261
readonly id: string
261
262
/**
262
- * Location in the file where the suite was defined.
263
+ * Location in the module where the suite was defined.
263
264
* Locations are collected only if `includeTaskLocation` is enabled in the config.
264
265
*/
265
266
readonly location: { line: number ; column: number } | undefined
@@ -274,20 +275,20 @@ declare class TestSuite {
274
275
}
275
276
```
276
277
277
- ### TestFile
278
+ ### TestModule
278
279
279
- ` TestFile ` represents a single file that contains suites and tests.
280
+ ` TestModule ` represents a single file that contains suites and tests.
280
281
281
282
``` ts
282
- declare class TestFile extends SuiteImplementation {
283
- readonly type = ' file '
283
+ declare class TestModule extends SuiteImplementation {
284
+ readonly type = ' module '
284
285
/**
285
286
* Task instance.
286
287
* @experimental Public task API is experimental and does not follow semver.
287
288
*/
288
289
readonly task: RunnerTestFile
289
290
/**
290
- * Collection of suites and tests that are part of this file .
291
+ * Collection of suites and tests that are part of this module .
291
292
*/
292
293
readonly children: TestCollection
293
294
/**
@@ -297,13 +298,13 @@ declare class TestFile extends SuiteImplementation {
297
298
*/
298
299
readonly moduleId: string
299
300
/**
300
- * Useful information about the file like duration, memory usage, etc.
301
- * If the file was not executed yet, all diagnostic values will return `0`.
301
+ * Useful information about the module like duration, memory usage, etc.
302
+ * If the module was not executed yet, all diagnostic values will return `0`.
302
303
*/
303
- diagnostic(): FileDiagnostic
304
+ diagnostic(): ModuleDiagnostic
304
305
}
305
306
306
- export interface FileDiagnostic {
307
+ export interface ModuleDiagnostic {
307
308
/**
308
309
* The time it takes to import and initiate an environment.
309
310
*/
@@ -313,16 +314,16 @@ export interface FileDiagnostic {
313
314
*/
314
315
prepareDuration: number
315
316
/**
316
- * The time it takes to import the test file .
317
- * This includes importing everything in the file and executing suite callbacks.
317
+ * The time it takes to import the test module .
318
+ * This includes importing everything in the module and executing suite callbacks.
318
319
*/
319
320
collectDuration: number
320
321
/**
321
- * The time it takes to import the setup file .
322
+ * The time it takes to import the setup module .
322
323
*/
323
324
setupDuration: number
324
325
/**
325
- * Accumulated duration of all tests and hooks in the file .
326
+ * Accumulated duration of all tests and hooks in the module .
326
327
*/
327
328
duration: number
328
329
}
@@ -366,22 +367,22 @@ declare class TestCollection {
366
367
}
367
368
```
368
369
369
- For example, you can iterate over all tests inside a file by calling ` testFile .children.allTests()` :
370
+ For example, you can iterate over all tests inside a module by calling ` testModule .children.allTests()` :
370
371
371
372
``` ts
372
- function onFileCollected(testFile : TestFile ): void {
373
- console .log (' collecting tests in' , testFile .moduleId )
373
+ function onFileCollected(testModule : TestModule ): void {
374
+ console .log (' collecting tests in' , testModule .moduleId )
374
375
375
- // iterate over all tests and suites in the file
376
- for (const task of testFile .children .allTests ()) {
376
+ // iterate over all tests and suites in the module
377
+ for (const task of testModule .children .allTests ()) {
377
378
console .log (' collected' , task .type , task .fullName )
378
379
}
379
380
}
380
381
```
381
382
382
383
### TestProject
383
384
384
- ` TestProject ` is a project assosiated with the file . Every test and suite inside that file will reference the same project.
385
+ ` TestProject ` is a project assosiated with the module . Every test and suite inside that module will reference the same project.
385
386
386
387
Project is useful to get the configuration or provided context.
387
388
0 commit comments