@vitest/runner 2.0.4 → 2.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +28 -14
- package/dist/index.js +16 -11
- package/dist/types.d.ts +2 -2
- package/dist/utils.d.ts +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
@@ -16,8 +16,8 @@ declare function publicCollect(paths: string[], runner: VitestRunner): Promise<F
|
|
16
16
|
*
|
17
17
|
* @param {string} name - The name of the suite, used for identification and reporting.
|
18
18
|
* @param {Function} fn - A function that defines the tests and suites within this suite.
|
19
|
-
*
|
20
19
|
* @example
|
20
|
+
* ```ts
|
21
21
|
* // Define a suite with two tests
|
22
22
|
* suite('Math operations', () => {
|
23
23
|
* test('should add two numbers', () => {
|
@@ -28,8 +28,9 @@ declare function publicCollect(paths: string[], runner: VitestRunner): Promise<F
|
|
28
28
|
* expect(subtract(5, 2)).toBe(3);
|
29
29
|
* });
|
30
30
|
* });
|
31
|
-
*
|
31
|
+
* ```
|
32
32
|
* @example
|
33
|
+
* ```ts
|
33
34
|
* // Define nested suites
|
34
35
|
* suite('String operations', () => {
|
35
36
|
* suite('Trimming', () => {
|
@@ -44,6 +45,7 @@ declare function publicCollect(paths: string[], runner: VitestRunner): Promise<F
|
|
44
45
|
* });
|
45
46
|
* });
|
46
47
|
* });
|
48
|
+
* ```
|
47
49
|
*/
|
48
50
|
declare const suite: SuiteAPI;
|
49
51
|
/**
|
@@ -53,18 +55,20 @@ declare const suite: SuiteAPI;
|
|
53
55
|
* @param {TestOptions | TestFunction} [optionsOrFn] - Optional. The test options or the test function if no explicit name is provided.
|
54
56
|
* @param {number | TestOptions | TestFunction} [optionsOrTest] - Optional. The test function or options, depending on the previous parameters.
|
55
57
|
* @throws {Error} If called inside another test function.
|
56
|
-
*
|
57
58
|
* @example
|
59
|
+
* ```ts
|
58
60
|
* // Define a simple test
|
59
61
|
* test('should add two numbers', () => {
|
60
62
|
* expect(add(1, 2)).toBe(3);
|
61
63
|
* });
|
62
|
-
*
|
64
|
+
* ```
|
63
65
|
* @example
|
66
|
+
* ```ts
|
64
67
|
* // Define a test with options
|
65
68
|
* test('should subtract two numbers', { retry: 3 }, () => {
|
66
69
|
* expect(subtract(5, 2)).toBe(3);
|
67
70
|
* });
|
71
|
+
* ```
|
68
72
|
*/
|
69
73
|
declare const test: TestAPI;
|
70
74
|
/**
|
@@ -73,8 +77,8 @@ declare const test: TestAPI;
|
|
73
77
|
*
|
74
78
|
* @param {string} name - The name of the suite, used for identification and reporting.
|
75
79
|
* @param {Function} fn - A function that defines the tests and suites within this suite.
|
76
|
-
*
|
77
80
|
* @example
|
81
|
+
* ```ts
|
78
82
|
* // Define a suite with two tests
|
79
83
|
* describe('Math operations', () => {
|
80
84
|
* test('should add two numbers', () => {
|
@@ -85,8 +89,9 @@ declare const test: TestAPI;
|
|
85
89
|
* expect(subtract(5, 2)).toBe(3);
|
86
90
|
* });
|
87
91
|
* });
|
88
|
-
*
|
92
|
+
* ```
|
89
93
|
* @example
|
94
|
+
* ```ts
|
90
95
|
* // Define nested suites
|
91
96
|
* describe('String operations', () => {
|
92
97
|
* describe('Trimming', () => {
|
@@ -101,6 +106,7 @@ declare const test: TestAPI;
|
|
101
106
|
* });
|
102
107
|
* });
|
103
108
|
* });
|
109
|
+
* ```
|
104
110
|
*/
|
105
111
|
declare const describe: SuiteAPI;
|
106
112
|
/**
|
@@ -110,18 +116,20 @@ declare const describe: SuiteAPI;
|
|
110
116
|
* @param {TestOptions | TestFunction} [optionsOrFn] - Optional. The test options or the test function if no explicit name is provided.
|
111
117
|
* @param {number | TestOptions | TestFunction} [optionsOrTest] - Optional. The test function or options, depending on the previous parameters.
|
112
118
|
* @throws {Error} If called inside another test function.
|
113
|
-
*
|
114
119
|
* @example
|
120
|
+
* ```ts
|
115
121
|
* // Define a simple test
|
116
122
|
* it('adds two numbers', () => {
|
117
123
|
* expect(add(1, 2)).toBe(3);
|
118
124
|
* });
|
119
|
-
*
|
125
|
+
* ```
|
120
126
|
* @example
|
127
|
+
* ```ts
|
121
128
|
* // Define a test with options
|
122
129
|
* it('subtracts two numbers', { retry: 3 }, () => {
|
123
130
|
* expect(subtract(5, 2)).toBe(3);
|
124
131
|
* });
|
132
|
+
* ```
|
125
133
|
*/
|
126
134
|
declare const it: TestAPI;
|
127
135
|
declare function getCurrentSuite<ExtraContext = object>(): SuiteCollector<ExtraContext>;
|
@@ -136,12 +144,13 @@ declare function createTaskCollector(fn: (...args: any[]) => any, context?: Reco
|
|
136
144
|
* @param {Function} fn - The callback function to be executed before all tests.
|
137
145
|
* @param {number} [timeout] - Optional timeout in milliseconds for the hook. If not provided, the default hook timeout from the runner's configuration is used.
|
138
146
|
* @returns {void}
|
139
|
-
*
|
140
147
|
* @example
|
148
|
+
* ```ts
|
141
149
|
* // Example of using beforeAll to set up a database connection
|
142
150
|
* beforeAll(async () => {
|
143
151
|
* await database.connect();
|
144
152
|
* });
|
153
|
+
* ```
|
145
154
|
*/
|
146
155
|
declare function beforeAll(fn: BeforeAllListener, timeout?: number): void;
|
147
156
|
/**
|
@@ -153,12 +162,13 @@ declare function beforeAll(fn: BeforeAllListener, timeout?: number): void;
|
|
153
162
|
* @param {Function} fn - The callback function to be executed after all tests.
|
154
163
|
* @param {number} [timeout] - Optional timeout in milliseconds for the hook. If not provided, the default hook timeout from the runner's configuration is used.
|
155
164
|
* @returns {void}
|
156
|
-
*
|
157
165
|
* @example
|
166
|
+
* ```ts
|
158
167
|
* // Example of using afterAll to close a database connection
|
159
168
|
* afterAll(async () => {
|
160
169
|
* await database.disconnect();
|
161
170
|
* });
|
171
|
+
* ```
|
162
172
|
*/
|
163
173
|
declare function afterAll(fn: AfterAllListener, timeout?: number): void;
|
164
174
|
/**
|
@@ -170,12 +180,13 @@ declare function afterAll(fn: AfterAllListener, timeout?: number): void;
|
|
170
180
|
* @param {Function} fn - The callback function to be executed before each test. This function receives an `TestContext` parameter if additional test context is needed.
|
171
181
|
* @param {number} [timeout] - Optional timeout in milliseconds for the hook. If not provided, the default hook timeout from the runner's configuration is used.
|
172
182
|
* @returns {void}
|
173
|
-
*
|
174
183
|
* @example
|
184
|
+
* ```ts
|
175
185
|
* // Example of using beforeEach to reset a database state
|
176
186
|
* beforeEach(async () => {
|
177
187
|
* await database.reset();
|
178
188
|
* });
|
189
|
+
* ```
|
179
190
|
*/
|
180
191
|
declare function beforeEach<ExtraContext = object>(fn: BeforeEachListener<ExtraContext>, timeout?: number): void;
|
181
192
|
/**
|
@@ -187,12 +198,13 @@ declare function beforeEach<ExtraContext = object>(fn: BeforeEachListener<ExtraC
|
|
187
198
|
* @param {Function} fn - The callback function to be executed after each test. This function receives an `TestContext` parameter if additional test context is needed.
|
188
199
|
* @param {number} [timeout] - Optional timeout in milliseconds for the hook. If not provided, the default hook timeout from the runner's configuration is used.
|
189
200
|
* @returns {void}
|
190
|
-
*
|
191
201
|
* @example
|
202
|
+
* ```ts
|
192
203
|
* // Example of using afterEach to delete temporary files created during a test
|
193
204
|
* afterEach(async () => {
|
194
205
|
* await fileSystem.deleteTempFiles();
|
195
206
|
* });
|
207
|
+
* ```
|
196
208
|
*/
|
197
209
|
declare function afterEach<ExtraContext = object>(fn: AfterEachListener<ExtraContext>, timeout?: number): void;
|
198
210
|
/**
|
@@ -205,12 +217,13 @@ declare function afterEach<ExtraContext = object>(fn: AfterEachListener<ExtraCon
|
|
205
217
|
* @param {number} [timeout] - Optional timeout in milliseconds for the hook. If not provided, the default hook timeout from the runner's configuration is used.
|
206
218
|
* @throws {Error} Throws an error if the function is not called within a test.
|
207
219
|
* @returns {void}
|
208
|
-
*
|
209
220
|
* @example
|
221
|
+
* ```ts
|
210
222
|
* // Example of using onTestFailed to log failure details
|
211
223
|
* onTestFailed(({ errors }) => {
|
212
224
|
* console.log(`Test failed: ${test.name}`, errors);
|
213
225
|
* });
|
226
|
+
* ```
|
214
227
|
*/
|
215
228
|
declare const onTestFailed: TaskHook<OnTestFailedHandler>;
|
216
229
|
/**
|
@@ -225,13 +238,14 @@ declare const onTestFailed: TaskHook<OnTestFailedHandler>;
|
|
225
238
|
* @param {number} [timeout] - Optional timeout in milliseconds for the hook. If not provided, the default hook timeout from the runner's configuration is used.
|
226
239
|
* @throws {Error} Throws an error if the function is not called within a test.
|
227
240
|
* @returns {void}
|
228
|
-
*
|
229
241
|
* @example
|
242
|
+
* ```ts
|
230
243
|
* // Example of using onTestFinished for cleanup
|
231
244
|
* const db = await connectToDatabase();
|
232
245
|
* onTestFinished(async () => {
|
233
246
|
* await db.disconnect();
|
234
247
|
* });
|
248
|
+
* ```
|
235
249
|
*/
|
236
250
|
declare const onTestFinished: TaskHook<OnTestFinishedHandler>;
|
237
251
|
|
package/dist/index.js
CHANGED
@@ -727,8 +727,7 @@ function findTestFileStackTrace(error, each) {
|
|
727
727
|
}
|
728
728
|
}
|
729
729
|
|
730
|
-
async function runSetupFiles(config, runner) {
|
731
|
-
const files = toArray(config.setupFiles);
|
730
|
+
async function runSetupFiles(config, files, runner) {
|
732
731
|
if (config.sequence.setupFiles === "parallel") {
|
733
732
|
await Promise.all(
|
734
733
|
files.map(async (fsPath) => {
|
@@ -752,10 +751,16 @@ async function collectTests(paths, runner) {
|
|
752
751
|
(_a = runner.onCollectStart) == null ? void 0 : _a.call(runner, file);
|
753
752
|
clearCollectorContext(filepath, runner);
|
754
753
|
try {
|
755
|
-
const
|
756
|
-
|
754
|
+
const setupFiles = toArray(config.setupFiles);
|
755
|
+
if (setupFiles.length) {
|
756
|
+
const setupStart = now$1();
|
757
|
+
await runSetupFiles(config, setupFiles, runner);
|
758
|
+
const setupEnd = now$1();
|
759
|
+
file.setupDuration = setupEnd - setupStart;
|
760
|
+
} else {
|
761
|
+
file.setupDuration = 0;
|
762
|
+
}
|
757
763
|
const collectStart = now$1();
|
758
|
-
file.setupDuration = collectStart - setupStart;
|
759
764
|
await runner.importFile(filepath, "collect");
|
760
765
|
const defaultTasks = await getDefaultSuite().collect(file);
|
761
766
|
const fileHooks = createSuiteHooks();
|
@@ -783,6 +788,12 @@ async function collectTests(paths, runner) {
|
|
783
788
|
};
|
784
789
|
}
|
785
790
|
calculateSuiteHash(file);
|
791
|
+
file.tasks.forEach((task) => {
|
792
|
+
var _a2;
|
793
|
+
if (((_a2 = task.suite) == null ? void 0 : _a2.id) === "") {
|
794
|
+
delete task.suite;
|
795
|
+
}
|
796
|
+
});
|
786
797
|
const hasOnlyTasks = someTasksAreOnly(file);
|
787
798
|
interpretTaskModes(
|
788
799
|
file,
|
@@ -791,12 +802,6 @@ async function collectTests(paths, runner) {
|
|
791
802
|
false,
|
792
803
|
config.allowOnly
|
793
804
|
);
|
794
|
-
file.tasks.forEach((task) => {
|
795
|
-
var _a2;
|
796
|
-
if (((_a2 = task.suite) == null ? void 0 : _a2.id) === "") {
|
797
|
-
delete task.suite;
|
798
|
-
}
|
799
|
-
});
|
800
805
|
files.push(file);
|
801
806
|
}
|
802
807
|
return files;
|
package/dist/types.d.ts
CHANGED
package/dist/utils.d.ts
CHANGED
@@ -9,7 +9,7 @@ declare function interpretTaskModes(suite: Suite, namePattern?: string | RegExp,
|
|
9
9
|
declare function someTasksAreOnly(suite: Suite): boolean;
|
10
10
|
declare function generateHash(str: string): string;
|
11
11
|
declare function calculateSuiteHash(parent: Suite): void;
|
12
|
-
declare function createFileTask(filepath: string, root: string, projectName: string, pool?: string): File;
|
12
|
+
declare function createFileTask(filepath: string, root: string, projectName: string | undefined, pool?: string): File;
|
13
13
|
|
14
14
|
/**
|
15
15
|
* Partition in tasks groups by consecutive concurrent
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@vitest/runner",
|
3
3
|
"type": "module",
|
4
|
-
"version": "2.0.
|
4
|
+
"version": "2.0.5",
|
5
5
|
"description": "Vitest test runner",
|
6
6
|
"license": "MIT",
|
7
7
|
"funding": "https://opencollective.com/vitest",
|
@@ -39,7 +39,7 @@
|
|
39
39
|
],
|
40
40
|
"dependencies": {
|
41
41
|
"pathe": "^1.1.2",
|
42
|
-
"@vitest/utils": "2.0.
|
42
|
+
"@vitest/utils": "2.0.5"
|
43
43
|
},
|
44
44
|
"scripts": {
|
45
45
|
"build": "rimraf dist && rollup -c",
|