@vitest/runner 3.0.8 → 3.1.0-beta.1
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 +219 -219
- package/dist/index.js +97 -33
- package/dist/tasks.d-D-sw4YOL.d.ts +487 -0
- package/dist/types.d.ts +130 -130
- package/dist/utils.d.ts +18 -15
- package/package.json +2 -2
- package/dist/tasks-CPSpEF1h.d.ts +0 -485
package/dist/index.d.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
import { A as AfterAllListener, b as AfterEachListener, B as BeforeAllListener, d as BeforeEachListener, e as TaskHook, O as OnTestFailedHandler, f as OnTestFinishedHandler, a as Test, g as Custom, S as Suite, h as SuiteHooks, F as File, i as TaskUpdateEvent, T as Task, j as TestAPI, k as SuiteAPI, l as SuiteCollector } from './tasks-
|
2
|
-
export { D as DoneCallback, E as ExtendedContext, m as Fixture, n as FixtureFn, o as FixtureOptions, p as Fixtures, H as HookCleanupCallback, q as HookListener, I as InferFixturesTypes, R as RunMode, r as RuntimeContext, s as SequenceHooks, t as SequenceSetupFiles, u as SuiteFactory, v as TaskBase, w as TaskContext, x as TaskCustomOptions, y as TaskEventPack, z as TaskMeta, G as TaskPopulated, J as TaskResult, K as TaskResultPack, L as TaskState, M as TestContext, N as TestFunction, P as TestOptions, U as Use } from './tasks-
|
1
|
+
import { A as AfterAllListener, b as AfterEachListener, B as BeforeAllListener, d as BeforeEachListener, e as TaskHook, O as OnTestFailedHandler, f as OnTestFinishedHandler, a as Test, g as Custom, S as Suite, h as SuiteHooks, F as File, i as TaskUpdateEvent, T as Task, j as TestAPI, k as SuiteAPI, l as SuiteCollector } from './tasks.d-D-sw4YOL.js';
|
2
|
+
export { D as DoneCallback, E as ExtendedContext, m as Fixture, n as FixtureFn, o as FixtureOptions, p as Fixtures, H as HookCleanupCallback, q as HookListener, I as InferFixturesTypes, R as RunMode, r as RuntimeContext, s as SequenceHooks, t as SequenceSetupFiles, u as SuiteFactory, v as TaskBase, w as TaskContext, x as TaskCustomOptions, y as TaskEventPack, z as TaskMeta, G as TaskPopulated, J as TaskResult, K as TaskResultPack, L as TaskState, M as TestContext, N as TestFunction, P as TestOptions, U as Use } from './tasks.d-D-sw4YOL.js';
|
3
3
|
import { Awaitable } from '@vitest/utils';
|
4
4
|
import { FileSpecification, VitestRunner } from './types.js';
|
5
5
|
export { CancelReason, VitestRunnerConfig, VitestRunnerConstructor, VitestRunnerImportSource } from './types.js';
|
@@ -7,119 +7,119 @@ export { processError } from '@vitest/utils/error';
|
|
7
7
|
import '@vitest/utils/diff';
|
8
8
|
|
9
9
|
/**
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
10
|
+
* Registers a callback function to be executed once before all tests within the current suite.
|
11
|
+
* This hook is useful for scenarios where you need to perform setup operations that are common to all tests in a suite, such as initializing a database connection or setting up a test environment.
|
12
|
+
*
|
13
|
+
* **Note:** The `beforeAll` hooks are executed in the order they are defined one after another. You can configure this by changing the `sequence.hooks` option in the config file.
|
14
|
+
*
|
15
|
+
* @param {Function} fn - The callback function to be executed before all tests.
|
16
|
+
* @param {number} [timeout] - Optional timeout in milliseconds for the hook. If not provided, the default hook timeout from the runner's configuration is used.
|
17
|
+
* @returns {void}
|
18
|
+
* @example
|
19
|
+
* ```ts
|
20
|
+
* // Example of using beforeAll to set up a database connection
|
21
|
+
* beforeAll(async () => {
|
22
|
+
* await database.connect();
|
23
|
+
* });
|
24
|
+
* ```
|
25
|
+
*/
|
26
26
|
declare function beforeAll(fn: BeforeAllListener, timeout?: number): void;
|
27
27
|
/**
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
28
|
+
* Registers a callback function to be executed once after all tests within the current suite have completed.
|
29
|
+
* This hook is useful for scenarios where you need to perform cleanup operations after all tests in a suite have run, such as closing database connections or cleaning up temporary files.
|
30
|
+
*
|
31
|
+
* **Note:** The `afterAll` hooks are running in reverse order of their registration. You can configure this by changing the `sequence.hooks` option in the config file.
|
32
|
+
*
|
33
|
+
* @param {Function} fn - The callback function to be executed after all tests.
|
34
|
+
* @param {number} [timeout] - Optional timeout in milliseconds for the hook. If not provided, the default hook timeout from the runner's configuration is used.
|
35
|
+
* @returns {void}
|
36
|
+
* @example
|
37
|
+
* ```ts
|
38
|
+
* // Example of using afterAll to close a database connection
|
39
|
+
* afterAll(async () => {
|
40
|
+
* await database.disconnect();
|
41
|
+
* });
|
42
|
+
* ```
|
43
|
+
*/
|
44
44
|
declare function afterAll(fn: AfterAllListener, timeout?: number): void;
|
45
45
|
/**
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
46
|
+
* Registers a callback function to be executed before each test within the current suite.
|
47
|
+
* This hook is useful for scenarios where you need to reset or reinitialize the test environment before each test runs, such as resetting database states, clearing caches, or reinitializing variables.
|
48
|
+
*
|
49
|
+
* **Note:** The `beforeEach` hooks are executed in the order they are defined one after another. You can configure this by changing the `sequence.hooks` option in the config file.
|
50
|
+
*
|
51
|
+
* @param {Function} fn - The callback function to be executed before each test. This function receives an `TestContext` parameter if additional test context is needed.
|
52
|
+
* @param {number} [timeout] - Optional timeout in milliseconds for the hook. If not provided, the default hook timeout from the runner's configuration is used.
|
53
|
+
* @returns {void}
|
54
|
+
* @example
|
55
|
+
* ```ts
|
56
|
+
* // Example of using beforeEach to reset a database state
|
57
|
+
* beforeEach(async () => {
|
58
|
+
* await database.reset();
|
59
|
+
* });
|
60
|
+
* ```
|
61
|
+
*/
|
62
62
|
declare function beforeEach<ExtraContext = object>(fn: BeforeEachListener<ExtraContext>, timeout?: number): void;
|
63
63
|
/**
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
64
|
+
* Registers a callback function to be executed after each test within the current suite has completed.
|
65
|
+
* This hook is useful for scenarios where you need to clean up or reset the test environment after each test runs, such as deleting temporary files, clearing test-specific database entries, or resetting mocked functions.
|
66
|
+
*
|
67
|
+
* **Note:** The `afterEach` hooks are running in reverse order of their registration. You can configure this by changing the `sequence.hooks` option in the config file.
|
68
|
+
*
|
69
|
+
* @param {Function} fn - The callback function to be executed after each test. This function receives an `TestContext` parameter if additional test context is needed.
|
70
|
+
* @param {number} [timeout] - Optional timeout in milliseconds for the hook. If not provided, the default hook timeout from the runner's configuration is used.
|
71
|
+
* @returns {void}
|
72
|
+
* @example
|
73
|
+
* ```ts
|
74
|
+
* // Example of using afterEach to delete temporary files created during a test
|
75
|
+
* afterEach(async () => {
|
76
|
+
* await fileSystem.deleteTempFiles();
|
77
|
+
* });
|
78
|
+
* ```
|
79
|
+
*/
|
80
80
|
declare function afterEach<ExtraContext = object>(fn: AfterEachListener<ExtraContext>, timeout?: number): void;
|
81
81
|
/**
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
82
|
+
* Registers a callback function to be executed when a test fails within the current suite.
|
83
|
+
* This function allows for custom actions to be performed in response to test failures, such as logging, cleanup, or additional diagnostics.
|
84
|
+
*
|
85
|
+
* **Note:** The `onTestFailed` hooks are running in reverse order of their registration. You can configure this by changing the `sequence.hooks` option in the config file.
|
86
|
+
*
|
87
|
+
* @param {Function} fn - The callback function to be executed upon a test failure. The function receives the test result (including errors).
|
88
|
+
* @param {number} [timeout] - Optional timeout in milliseconds for the hook. If not provided, the default hook timeout from the runner's configuration is used.
|
89
|
+
* @throws {Error} Throws an error if the function is not called within a test.
|
90
|
+
* @returns {void}
|
91
|
+
* @example
|
92
|
+
* ```ts
|
93
|
+
* // Example of using onTestFailed to log failure details
|
94
|
+
* onTestFailed(({ errors }) => {
|
95
|
+
* console.log(`Test failed: ${test.name}`, errors);
|
96
|
+
* });
|
97
|
+
* ```
|
98
|
+
*/
|
99
99
|
declare const onTestFailed: TaskHook<OnTestFailedHandler>;
|
100
100
|
/**
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
101
|
+
* Registers a callback function to be executed when the current test finishes, regardless of the outcome (pass or fail).
|
102
|
+
* This function is ideal for performing actions that should occur after every test execution, such as cleanup, logging, or resetting shared resources.
|
103
|
+
*
|
104
|
+
* This hook is useful if you have access to a resource in the test itself and you want to clean it up after the test finishes. It is a more compact way to clean up resources than using the combination of `beforeEach` and `afterEach`.
|
105
|
+
*
|
106
|
+
* **Note:** The `onTestFinished` hooks are running in reverse order of their registration. You can configure this by changing the `sequence.hooks` option in the config file.
|
107
|
+
*
|
108
|
+
* **Note:** The `onTestFinished` hook is not called if the test is canceled with a dynamic `ctx.skip()` call.
|
109
|
+
*
|
110
|
+
* @param {Function} fn - The callback function to be executed after a test finishes. The function can receive parameters providing details about the completed test, including its success or failure status.
|
111
|
+
* @param {number} [timeout] - Optional timeout in milliseconds for the hook. If not provided, the default hook timeout from the runner's configuration is used.
|
112
|
+
* @throws {Error} Throws an error if the function is not called within a test.
|
113
|
+
* @returns {void}
|
114
|
+
* @example
|
115
|
+
* ```ts
|
116
|
+
* // Example of using onTestFinished for cleanup
|
117
|
+
* const db = await connectToDatabase();
|
118
|
+
* onTestFinished(async () => {
|
119
|
+
* await db.disconnect();
|
120
|
+
* });
|
121
|
+
* ```
|
122
|
+
*/
|
123
123
|
declare const onTestFinished: TaskHook<OnTestFinishedHandler>;
|
124
124
|
|
125
125
|
declare function setFn(key: Test | Custom, fn: () => Awaitable<void>): void;
|
@@ -132,126 +132,126 @@ declare function startTests(specs: string[] | FileSpecification[], runner: Vites
|
|
132
132
|
declare function publicCollect(specs: string[] | FileSpecification[], runner: VitestRunner): Promise<File[]>;
|
133
133
|
|
134
134
|
/**
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
135
|
+
* Creates a suite of tests, allowing for grouping and hierarchical organization of tests.
|
136
|
+
* Suites can contain both tests and other suites, enabling complex test structures.
|
137
|
+
*
|
138
|
+
* @param {string} name - The name of the suite, used for identification and reporting.
|
139
|
+
* @param {Function} fn - A function that defines the tests and suites within this suite.
|
140
|
+
* @example
|
141
|
+
* ```ts
|
142
|
+
* // Define a suite with two tests
|
143
|
+
* suite('Math operations', () => {
|
144
|
+
* test('should add two numbers', () => {
|
145
|
+
* expect(add(1, 2)).toBe(3);
|
146
|
+
* });
|
147
|
+
*
|
148
|
+
* test('should subtract two numbers', () => {
|
149
|
+
* expect(subtract(5, 2)).toBe(3);
|
150
|
+
* });
|
151
|
+
* });
|
152
|
+
* ```
|
153
|
+
* @example
|
154
|
+
* ```ts
|
155
|
+
* // Define nested suites
|
156
|
+
* suite('String operations', () => {
|
157
|
+
* suite('Trimming', () => {
|
158
|
+
* test('should trim whitespace from start and end', () => {
|
159
|
+
* expect(' hello '.trim()).toBe('hello');
|
160
|
+
* });
|
161
|
+
* });
|
162
|
+
*
|
163
|
+
* suite('Concatenation', () => {
|
164
|
+
* test('should concatenate two strings', () => {
|
165
|
+
* expect('hello' + ' ' + 'world').toBe('hello world');
|
166
|
+
* });
|
167
|
+
* });
|
168
|
+
* });
|
169
|
+
* ```
|
170
|
+
*/
|
171
171
|
declare const suite: SuiteAPI;
|
172
172
|
/**
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
173
|
+
* Defines a test case with a given name and test function. The test function can optionally be configured with test options.
|
174
|
+
*
|
175
|
+
* @param {string | Function} name - The name of the test or a function that will be used as a test name.
|
176
|
+
* @param {TestOptions | TestFunction} [optionsOrFn] - Optional. The test options or the test function if no explicit name is provided.
|
177
|
+
* @param {number | TestOptions | TestFunction} [optionsOrTest] - Optional. The test function or options, depending on the previous parameters.
|
178
|
+
* @throws {Error} If called inside another test function.
|
179
|
+
* @example
|
180
|
+
* ```ts
|
181
|
+
* // Define a simple test
|
182
|
+
* test('should add two numbers', () => {
|
183
|
+
* expect(add(1, 2)).toBe(3);
|
184
|
+
* });
|
185
|
+
* ```
|
186
|
+
* @example
|
187
|
+
* ```ts
|
188
|
+
* // Define a test with options
|
189
|
+
* test('should subtract two numbers', { retry: 3 }, () => {
|
190
|
+
* expect(subtract(5, 2)).toBe(3);
|
191
|
+
* });
|
192
|
+
* ```
|
193
|
+
*/
|
194
194
|
declare const test: TestAPI;
|
195
195
|
/**
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
196
|
+
* Creates a suite of tests, allowing for grouping and hierarchical organization of tests.
|
197
|
+
* Suites can contain both tests and other suites, enabling complex test structures.
|
198
|
+
*
|
199
|
+
* @param {string} name - The name of the suite, used for identification and reporting.
|
200
|
+
* @param {Function} fn - A function that defines the tests and suites within this suite.
|
201
|
+
* @example
|
202
|
+
* ```ts
|
203
|
+
* // Define a suite with two tests
|
204
|
+
* describe('Math operations', () => {
|
205
|
+
* test('should add two numbers', () => {
|
206
|
+
* expect(add(1, 2)).toBe(3);
|
207
|
+
* });
|
208
|
+
*
|
209
|
+
* test('should subtract two numbers', () => {
|
210
|
+
* expect(subtract(5, 2)).toBe(3);
|
211
|
+
* });
|
212
|
+
* });
|
213
|
+
* ```
|
214
|
+
* @example
|
215
|
+
* ```ts
|
216
|
+
* // Define nested suites
|
217
|
+
* describe('String operations', () => {
|
218
|
+
* describe('Trimming', () => {
|
219
|
+
* test('should trim whitespace from start and end', () => {
|
220
|
+
* expect(' hello '.trim()).toBe('hello');
|
221
|
+
* });
|
222
|
+
* });
|
223
|
+
*
|
224
|
+
* describe('Concatenation', () => {
|
225
|
+
* test('should concatenate two strings', () => {
|
226
|
+
* expect('hello' + ' ' + 'world').toBe('hello world');
|
227
|
+
* });
|
228
|
+
* });
|
229
|
+
* });
|
230
|
+
* ```
|
231
|
+
*/
|
232
232
|
declare const describe: SuiteAPI;
|
233
233
|
/**
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
234
|
+
* Defines a test case with a given name and test function. The test function can optionally be configured with test options.
|
235
|
+
*
|
236
|
+
* @param {string | Function} name - The name of the test or a function that will be used as a test name.
|
237
|
+
* @param {TestOptions | TestFunction} [optionsOrFn] - Optional. The test options or the test function if no explicit name is provided.
|
238
|
+
* @param {number | TestOptions | TestFunction} [optionsOrTest] - Optional. The test function or options, depending on the previous parameters.
|
239
|
+
* @throws {Error} If called inside another test function.
|
240
|
+
* @example
|
241
|
+
* ```ts
|
242
|
+
* // Define a simple test
|
243
|
+
* it('adds two numbers', () => {
|
244
|
+
* expect(add(1, 2)).toBe(3);
|
245
|
+
* });
|
246
|
+
* ```
|
247
|
+
* @example
|
248
|
+
* ```ts
|
249
|
+
* // Define a test with options
|
250
|
+
* it('subtracts two numbers', { retry: 3 }, () => {
|
251
|
+
* expect(subtract(5, 2)).toBe(3);
|
252
|
+
* });
|
253
|
+
* ```
|
254
|
+
*/
|
255
255
|
declare const it: TestAPI;
|
256
256
|
declare function getCurrentSuite<ExtraContext = object>(): SuiteCollector<ExtraContext>;
|
257
257
|
declare function createTaskCollector(fn: (...args: any[]) => any, context?: Record<string, unknown>): TestAPI;
|