@vitest/runner 2.1.3 → 2.1.4
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/chunk-tasks.js +70 -64
- package/dist/index.d.ts +124 -124
- package/dist/index.js +85 -85
- package/dist/{tasks-SNKRxoD7.d.ts → tasks-3ZnPj1LR.d.ts} +11 -11
- package/dist/types.d.ts +2 -2
- package/dist/utils.d.ts +10 -8
- package/dist/utils.js +1 -1
- package/package.json +2 -2
package/dist/chunk-tasks.js
CHANGED
@@ -2,48 +2,31 @@ import { processError } from '@vitest/utils/error';
|
|
2
2
|
import { relative } from 'pathe';
|
3
3
|
import { toArray } from '@vitest/utils';
|
4
4
|
|
5
|
-
function
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
5
|
+
function createChainable(keys, fn) {
|
6
|
+
function create(context) {
|
7
|
+
const chain2 = function(...args) {
|
8
|
+
return fn.apply(context, args);
|
9
|
+
};
|
10
|
+
Object.assign(chain2, fn);
|
11
|
+
chain2.withContext = () => chain2.bind(context);
|
12
|
+
chain2.setContext = (key, value) => {
|
13
|
+
context[key] = value;
|
14
|
+
};
|
15
|
+
chain2.mergeContext = (ctx) => {
|
16
|
+
Object.assign(context, ctx);
|
17
|
+
};
|
18
|
+
for (const key of keys) {
|
19
|
+
Object.defineProperty(chain2, key, {
|
20
|
+
get() {
|
21
|
+
return create({ ...context, [key]: true });
|
22
|
+
}
|
23
|
+
});
|
14
24
|
}
|
25
|
+
return chain2;
|
15
26
|
}
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
return tasksGroups;
|
20
|
-
}
|
21
|
-
|
22
|
-
function limitConcurrency(concurrency = Infinity) {
|
23
|
-
let count = 0;
|
24
|
-
let head;
|
25
|
-
let tail;
|
26
|
-
const finish = () => {
|
27
|
-
count--;
|
28
|
-
if (head) {
|
29
|
-
head[0]();
|
30
|
-
head = head[1];
|
31
|
-
tail = head && tail;
|
32
|
-
}
|
33
|
-
};
|
34
|
-
return (func, ...args) => {
|
35
|
-
return new Promise((resolve) => {
|
36
|
-
if (count++ < concurrency) {
|
37
|
-
resolve();
|
38
|
-
} else if (tail) {
|
39
|
-
tail = tail[1] = [resolve];
|
40
|
-
} else {
|
41
|
-
head = tail = [resolve];
|
42
|
-
}
|
43
|
-
}).then(() => {
|
44
|
-
return func(...args);
|
45
|
-
}).finally(finish);
|
46
|
-
};
|
27
|
+
const chain = create({});
|
28
|
+
chain.fn = fn;
|
29
|
+
return chain;
|
47
30
|
}
|
48
31
|
|
49
32
|
function interpretTaskModes(suite, namePattern, onlyMode, parentIsOnly, allowOnly) {
|
@@ -151,31 +134,48 @@ function createFileTask(filepath, root, projectName, pool) {
|
|
151
134
|
return file;
|
152
135
|
}
|
153
136
|
|
154
|
-
function
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
}
|
137
|
+
function limitConcurrency(concurrency = Infinity) {
|
138
|
+
let count = 0;
|
139
|
+
let head;
|
140
|
+
let tail;
|
141
|
+
const finish = () => {
|
142
|
+
count--;
|
143
|
+
if (head) {
|
144
|
+
head[0]();
|
145
|
+
head = head[1];
|
146
|
+
tail = head && tail;
|
147
|
+
}
|
148
|
+
};
|
149
|
+
return (func, ...args) => {
|
150
|
+
return new Promise((resolve) => {
|
151
|
+
if (count++ < concurrency) {
|
152
|
+
resolve();
|
153
|
+
} else if (tail) {
|
154
|
+
tail = tail[1] = [resolve];
|
155
|
+
} else {
|
156
|
+
head = tail = [resolve];
|
157
|
+
}
|
158
|
+
}).then(() => {
|
159
|
+
return func(...args);
|
160
|
+
}).finally(finish);
|
161
|
+
};
|
162
|
+
}
|
163
|
+
|
164
|
+
function partitionSuiteChildren(suite) {
|
165
|
+
let tasksGroup = [];
|
166
|
+
const tasksGroups = [];
|
167
|
+
for (const c of suite.tasks) {
|
168
|
+
if (tasksGroup.length === 0 || c.concurrent === tasksGroup[0].concurrent) {
|
169
|
+
tasksGroup.push(c);
|
170
|
+
} else {
|
171
|
+
tasksGroups.push(tasksGroup);
|
172
|
+
tasksGroup = [c];
|
173
173
|
}
|
174
|
-
return chain2;
|
175
174
|
}
|
176
|
-
|
177
|
-
|
178
|
-
|
175
|
+
if (tasksGroup.length > 0) {
|
176
|
+
tasksGroups.push(tasksGroup);
|
177
|
+
}
|
178
|
+
return tasksGroups;
|
179
179
|
}
|
180
180
|
|
181
181
|
function isAtomTest(s) {
|
@@ -239,5 +239,11 @@ function getNames(task) {
|
|
239
239
|
}
|
240
240
|
return names;
|
241
241
|
}
|
242
|
+
function getFullName(task, separator = " > ") {
|
243
|
+
return getNames(task).join(separator);
|
244
|
+
}
|
245
|
+
function getTestName(task, separator = " > ") {
|
246
|
+
return getNames(task).slice(1).join(separator);
|
247
|
+
}
|
242
248
|
|
243
|
-
export {
|
249
|
+
export { calculateSuiteHash as a, createFileTask as b, createChainable as c, getFullName as d, getNames as e, getSuites as f, generateHash as g, getTasks as h, interpretTaskModes as i, getTestName as j, getTests as k, limitConcurrency as l, hasFailed as m, hasTests as n, isAtomTest as o, partitionSuiteChildren as p, someTasksAreOnly as s };
|
package/dist/index.d.ts
CHANGED
@@ -1,11 +1,130 @@
|
|
1
|
+
import { B as BeforeAllListener, A as AfterAllListener, d as BeforeEachListener, e as AfterEachListener, f as TaskHook, O as OnTestFailedHandler, g as OnTestFinishedHandler, a as Test, C as Custom, S as Suite, h as SuiteHooks, T as Task, F as File, i as SuiteAPI, j as TestAPI, k as SuiteCollector } from './tasks-3ZnPj1LR.js';
|
2
|
+
export { D as DoneCallback, E as ExtendedContext, l as Fixture, m as FixtureFn, n as FixtureOptions, o as Fixtures, H as HookCleanupCallback, p as HookListener, I as InferFixturesTypes, R as RunMode, q as RuntimeContext, r as SequenceHooks, s as SequenceSetupFiles, t as SuiteFactory, u as TaskBase, v as TaskContext, w as TaskCustomOptions, x as TaskMeta, y as TaskPopulated, z as TaskResult, G as TaskResultPack, J as TaskState, K as TestContext, L as TestFunction, M as TestOptions, U as Use } from './tasks-3ZnPj1LR.js';
|
3
|
+
import { Awaitable } from '@vitest/utils';
|
1
4
|
import { VitestRunner } from './types.js';
|
2
5
|
export { CancelReason, VitestRunnerConfig, VitestRunnerConstructor, VitestRunnerImportSource } from './types.js';
|
3
|
-
import { T as Task, F as File, d as SuiteAPI, e as TestAPI, f as SuiteCollector, g as CustomAPI, B as BeforeAllListener, A as AfterAllListener, h as BeforeEachListener, i as AfterEachListener, j as TaskHook, O as OnTestFailedHandler, k as OnTestFinishedHandler, a as Test, C as Custom, S as Suite, l as SuiteHooks } from './tasks-SNKRxoD7.js';
|
4
|
-
export { D as DoneCallback, L as ExtendedContext, w as Fixture, v as FixtureFn, u as FixtureOptions, x as Fixtures, y as HookCleanupCallback, H as HookListener, I as InferFixturesTypes, R as RunMode, G as RuntimeContext, M as SequenceHooks, N as SequenceSetupFiles, E as SuiteFactory, n as TaskBase, K as TaskContext, z as TaskCustomOptions, p as TaskMeta, o as TaskPopulated, q as TaskResult, r as TaskResultPack, m as TaskState, J as TestContext, s as TestFunction, t as TestOptions, U as Use } from './tasks-SNKRxoD7.js';
|
5
|
-
import { Awaitable } from '@vitest/utils';
|
6
6
|
export { processError } from '@vitest/utils/error';
|
7
7
|
import '@vitest/utils/diff';
|
8
8
|
|
9
|
+
/**
|
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
|
+
declare function beforeAll(fn: BeforeAllListener, timeout?: number): void;
|
27
|
+
/**
|
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
|
+
declare function afterAll(fn: AfterAllListener, timeout?: number): void;
|
45
|
+
/**
|
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
|
+
declare function beforeEach<ExtraContext = object>(fn: BeforeEachListener<ExtraContext>, timeout?: number): void;
|
63
|
+
/**
|
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
|
+
declare function afterEach<ExtraContext = object>(fn: AfterEachListener<ExtraContext>, timeout?: number): void;
|
81
|
+
/**
|
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
|
+
declare const onTestFailed: TaskHook<OnTestFailedHandler>;
|
100
|
+
/**
|
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
|
+
* @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.
|
109
|
+
* @param {number} [timeout] - Optional timeout in milliseconds for the hook. If not provided, the default hook timeout from the runner's configuration is used.
|
110
|
+
* @throws {Error} Throws an error if the function is not called within a test.
|
111
|
+
* @returns {void}
|
112
|
+
* @example
|
113
|
+
* ```ts
|
114
|
+
* // Example of using onTestFinished for cleanup
|
115
|
+
* const db = await connectToDatabase();
|
116
|
+
* onTestFinished(async () => {
|
117
|
+
* await db.disconnect();
|
118
|
+
* });
|
119
|
+
* ```
|
120
|
+
*/
|
121
|
+
declare const onTestFinished: TaskHook<OnTestFinishedHandler>;
|
122
|
+
|
123
|
+
declare function setFn(key: Test | Custom, fn: () => Awaitable<void>): void;
|
124
|
+
declare function getFn<Task = Test | Custom>(key: Task): () => Awaitable<void>;
|
125
|
+
declare function setHooks(key: Suite, hooks: SuiteHooks): void;
|
126
|
+
declare function getHooks(key: Suite): SuiteHooks;
|
127
|
+
|
9
128
|
declare function updateTask(task: Task, runner: VitestRunner): void;
|
10
129
|
declare function startTests(paths: string[], runner: VitestRunner): Promise<File[]>;
|
11
130
|
declare function publicCollect(paths: string[], runner: VitestRunner): Promise<File[]>;
|
@@ -133,127 +252,8 @@ declare const describe: SuiteAPI;
|
|
133
252
|
*/
|
134
253
|
declare const it: TestAPI;
|
135
254
|
declare function getCurrentSuite<ExtraContext = object>(): SuiteCollector<ExtraContext>;
|
136
|
-
declare function createTaskCollector(fn: (...args: any[]) => any, context?: Record<string, unknown>):
|
137
|
-
|
138
|
-
/**
|
139
|
-
* Registers a callback function to be executed once before all tests within the current suite.
|
140
|
-
* 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.
|
141
|
-
*
|
142
|
-
* **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.
|
143
|
-
*
|
144
|
-
* @param {Function} fn - The callback function to be executed before all tests.
|
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.
|
146
|
-
* @returns {void}
|
147
|
-
* @example
|
148
|
-
* ```ts
|
149
|
-
* // Example of using beforeAll to set up a database connection
|
150
|
-
* beforeAll(async () => {
|
151
|
-
* await database.connect();
|
152
|
-
* });
|
153
|
-
* ```
|
154
|
-
*/
|
155
|
-
declare function beforeAll(fn: BeforeAllListener, timeout?: number): void;
|
156
|
-
/**
|
157
|
-
* Registers a callback function to be executed once after all tests within the current suite have completed.
|
158
|
-
* 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.
|
159
|
-
*
|
160
|
-
* **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.
|
161
|
-
*
|
162
|
-
* @param {Function} fn - The callback function to be executed after all tests.
|
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.
|
164
|
-
* @returns {void}
|
165
|
-
* @example
|
166
|
-
* ```ts
|
167
|
-
* // Example of using afterAll to close a database connection
|
168
|
-
* afterAll(async () => {
|
169
|
-
* await database.disconnect();
|
170
|
-
* });
|
171
|
-
* ```
|
172
|
-
*/
|
173
|
-
declare function afterAll(fn: AfterAllListener, timeout?: number): void;
|
174
|
-
/**
|
175
|
-
* Registers a callback function to be executed before each test within the current suite.
|
176
|
-
* 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.
|
177
|
-
*
|
178
|
-
* **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.
|
179
|
-
*
|
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.
|
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.
|
182
|
-
* @returns {void}
|
183
|
-
* @example
|
184
|
-
* ```ts
|
185
|
-
* // Example of using beforeEach to reset a database state
|
186
|
-
* beforeEach(async () => {
|
187
|
-
* await database.reset();
|
188
|
-
* });
|
189
|
-
* ```
|
190
|
-
*/
|
191
|
-
declare function beforeEach<ExtraContext = object>(fn: BeforeEachListener<ExtraContext>, timeout?: number): void;
|
192
|
-
/**
|
193
|
-
* Registers a callback function to be executed after each test within the current suite has completed.
|
194
|
-
* 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.
|
195
|
-
*
|
196
|
-
* **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.
|
197
|
-
*
|
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.
|
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.
|
200
|
-
* @returns {void}
|
201
|
-
* @example
|
202
|
-
* ```ts
|
203
|
-
* // Example of using afterEach to delete temporary files created during a test
|
204
|
-
* afterEach(async () => {
|
205
|
-
* await fileSystem.deleteTempFiles();
|
206
|
-
* });
|
207
|
-
* ```
|
208
|
-
*/
|
209
|
-
declare function afterEach<ExtraContext = object>(fn: AfterEachListener<ExtraContext>, timeout?: number): void;
|
210
|
-
/**
|
211
|
-
* Registers a callback function to be executed when a test fails within the current suite.
|
212
|
-
* This function allows for custom actions to be performed in response to test failures, such as logging, cleanup, or additional diagnostics.
|
213
|
-
*
|
214
|
-
* **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.
|
215
|
-
*
|
216
|
-
* @param {Function} fn - The callback function to be executed upon a test failure. The function receives the test result (including errors).
|
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.
|
218
|
-
* @throws {Error} Throws an error if the function is not called within a test.
|
219
|
-
* @returns {void}
|
220
|
-
* @example
|
221
|
-
* ```ts
|
222
|
-
* // Example of using onTestFailed to log failure details
|
223
|
-
* onTestFailed(({ errors }) => {
|
224
|
-
* console.log(`Test failed: ${test.name}`, errors);
|
225
|
-
* });
|
226
|
-
* ```
|
227
|
-
*/
|
228
|
-
declare const onTestFailed: TaskHook<OnTestFailedHandler>;
|
229
|
-
/**
|
230
|
-
* Registers a callback function to be executed when the current test finishes, regardless of the outcome (pass or fail).
|
231
|
-
* This function is ideal for performing actions that should occur after every test execution, such as cleanup, logging, or resetting shared resources.
|
232
|
-
*
|
233
|
-
* 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`.
|
234
|
-
*
|
235
|
-
* **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.
|
236
|
-
*
|
237
|
-
* @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.
|
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.
|
239
|
-
* @throws {Error} Throws an error if the function is not called within a test.
|
240
|
-
* @returns {void}
|
241
|
-
* @example
|
242
|
-
* ```ts
|
243
|
-
* // Example of using onTestFinished for cleanup
|
244
|
-
* const db = await connectToDatabase();
|
245
|
-
* onTestFinished(async () => {
|
246
|
-
* await db.disconnect();
|
247
|
-
* });
|
248
|
-
* ```
|
249
|
-
*/
|
250
|
-
declare const onTestFinished: TaskHook<OnTestFinishedHandler>;
|
251
|
-
|
252
|
-
declare function setFn(key: Test | Custom, fn: () => Awaitable<void>): void;
|
253
|
-
declare function getFn<Task = Test | Custom>(key: Task): () => Awaitable<void>;
|
254
|
-
declare function setHooks(key: Suite, hooks: SuiteHooks): void;
|
255
|
-
declare function getHooks(key: Suite): SuiteHooks;
|
255
|
+
declare function createTaskCollector(fn: (...args: any[]) => any, context?: Record<string, unknown>): TestAPI;
|
256
256
|
|
257
257
|
declare function getCurrentTest<T extends Test | Custom | undefined>(): T;
|
258
258
|
|
259
|
-
export { AfterAllListener, AfterEachListener, BeforeAllListener, BeforeEachListener, Custom, CustomAPI, File, OnTestFailedHandler, OnTestFinishedHandler, Suite, SuiteAPI, SuiteCollector, SuiteHooks, Task, TaskHook, Test, TestAPI, VitestRunner, afterAll, afterEach, beforeAll, beforeEach, publicCollect as collectTests, createTaskCollector, describe, getCurrentSuite, getCurrentTest, getFn, getHooks, it, onTestFailed, onTestFinished, setFn, setHooks, startTests, suite, test, updateTask };
|
259
|
+
export { AfterAllListener, AfterEachListener, BeforeAllListener, BeforeEachListener, Custom, TestAPI as CustomAPI, File, OnTestFailedHandler, OnTestFinishedHandler, Suite, SuiteAPI, SuiteCollector, SuiteHooks, Task, TaskHook, Test, TestAPI, VitestRunner, afterAll, afterEach, beforeAll, beforeEach, publicCollect as collectTests, createTaskCollector, describe, getCurrentSuite, getCurrentTest, getFn, getHooks, it, onTestFailed, onTestFinished, setFn, setHooks, startTests, suite, test, updateTask };
|
package/dist/index.js
CHANGED
@@ -1,32 +1,10 @@
|
|
1
|
-
import { getSafeTimers, isObject, createDefer, isNegativeNaN, format, objDisplay, objectAttr, toArray,
|
1
|
+
import { getSafeTimers, isObject, createDefer, isNegativeNaN, format, objDisplay, objectAttr, toArray, assertTypes, shuffle } from '@vitest/utils';
|
2
|
+
import { parseSingleStack } from '@vitest/utils/source-map';
|
3
|
+
import { c as createChainable, b as createFileTask, a as calculateSuiteHash, s as someTasksAreOnly, i as interpretTaskModes, l as limitConcurrency, p as partitionSuiteChildren, n as hasTests, m as hasFailed } from './chunk-tasks.js';
|
2
4
|
import { processError } from '@vitest/utils/error';
|
3
5
|
export { processError } from '@vitest/utils/error';
|
4
|
-
import { l as createChainable, a as createFileTask, c as calculateSuiteHash, s as someTasksAreOnly, i as interpretTaskModes, m as limitConcurrency, p as partitionSuiteChildren, h as hasTests, j as hasFailed } from './chunk-tasks.js';
|
5
|
-
import { parseSingleStack } from '@vitest/utils/source-map';
|
6
6
|
import 'pathe';
|
7
7
|
|
8
|
-
const fnMap = /* @__PURE__ */ new WeakMap();
|
9
|
-
const fixtureMap = /* @__PURE__ */ new WeakMap();
|
10
|
-
const hooksMap = /* @__PURE__ */ new WeakMap();
|
11
|
-
function setFn(key, fn) {
|
12
|
-
fnMap.set(key, fn);
|
13
|
-
}
|
14
|
-
function getFn(key) {
|
15
|
-
return fnMap.get(key);
|
16
|
-
}
|
17
|
-
function setFixture(key, fixture) {
|
18
|
-
fixtureMap.set(key, fixture);
|
19
|
-
}
|
20
|
-
function getFixture(key) {
|
21
|
-
return fixtureMap.get(key);
|
22
|
-
}
|
23
|
-
function setHooks(key, hooks) {
|
24
|
-
hooksMap.set(key, hooks);
|
25
|
-
}
|
26
|
-
function getHooks(key) {
|
27
|
-
return hooksMap.get(key);
|
28
|
-
}
|
29
|
-
|
30
8
|
class PendingError extends Error {
|
31
9
|
constructor(message, task) {
|
32
10
|
super(message);
|
@@ -95,6 +73,28 @@ function makeTimeoutMsg(isHook, timeout) {
|
|
95
73
|
If this is a long-running ${isHook ? "hook" : "test"}, pass a timeout value as the last argument or configure it globally with "${isHook ? "hookTimeout" : "testTimeout"}".`;
|
96
74
|
}
|
97
75
|
|
76
|
+
const fnMap = /* @__PURE__ */ new WeakMap();
|
77
|
+
const fixtureMap = /* @__PURE__ */ new WeakMap();
|
78
|
+
const hooksMap = /* @__PURE__ */ new WeakMap();
|
79
|
+
function setFn(key, fn) {
|
80
|
+
fnMap.set(key, fn);
|
81
|
+
}
|
82
|
+
function getFn(key) {
|
83
|
+
return fnMap.get(key);
|
84
|
+
}
|
85
|
+
function setFixture(key, fixture) {
|
86
|
+
fixtureMap.set(key, fixture);
|
87
|
+
}
|
88
|
+
function getFixture(key) {
|
89
|
+
return fixtureMap.get(key);
|
90
|
+
}
|
91
|
+
function setHooks(key, hooks) {
|
92
|
+
hooksMap.set(key, hooks);
|
93
|
+
}
|
94
|
+
function getHooks(key) {
|
95
|
+
return hooksMap.get(key);
|
96
|
+
}
|
97
|
+
|
98
98
|
function mergeContextFixtures(fixtures, context = {}) {
|
99
99
|
const fixtureOptionKeys = ["auto"];
|
100
100
|
const fixtureArray = Object.entries(fixtures).map(
|
@@ -754,6 +754,66 @@ function findTestFileStackTrace(error, each) {
|
|
754
754
|
}
|
755
755
|
}
|
756
756
|
|
757
|
+
function getDefaultHookTimeout() {
|
758
|
+
return getRunner().config.hookTimeout;
|
759
|
+
}
|
760
|
+
function beforeAll(fn, timeout) {
|
761
|
+
assertTypes(fn, '"beforeAll" callback', ["function"]);
|
762
|
+
return getCurrentSuite().on(
|
763
|
+
"beforeAll",
|
764
|
+
withTimeout(fn, timeout ?? getDefaultHookTimeout(), true)
|
765
|
+
);
|
766
|
+
}
|
767
|
+
function afterAll(fn, timeout) {
|
768
|
+
assertTypes(fn, '"afterAll" callback', ["function"]);
|
769
|
+
return getCurrentSuite().on(
|
770
|
+
"afterAll",
|
771
|
+
withTimeout(fn, timeout ?? getDefaultHookTimeout(), true)
|
772
|
+
);
|
773
|
+
}
|
774
|
+
function beforeEach(fn, timeout) {
|
775
|
+
assertTypes(fn, '"beforeEach" callback', ["function"]);
|
776
|
+
return getCurrentSuite().on(
|
777
|
+
"beforeEach",
|
778
|
+
withTimeout(withFixtures(fn), timeout ?? getDefaultHookTimeout(), true)
|
779
|
+
);
|
780
|
+
}
|
781
|
+
function afterEach(fn, timeout) {
|
782
|
+
assertTypes(fn, '"afterEach" callback', ["function"]);
|
783
|
+
return getCurrentSuite().on(
|
784
|
+
"afterEach",
|
785
|
+
withTimeout(withFixtures(fn), timeout ?? getDefaultHookTimeout(), true)
|
786
|
+
);
|
787
|
+
}
|
788
|
+
const onTestFailed = createTestHook(
|
789
|
+
"onTestFailed",
|
790
|
+
(test, handler, timeout) => {
|
791
|
+
test.onFailed || (test.onFailed = []);
|
792
|
+
test.onFailed.push(
|
793
|
+
withTimeout(handler, timeout ?? getDefaultHookTimeout(), true)
|
794
|
+
);
|
795
|
+
}
|
796
|
+
);
|
797
|
+
const onTestFinished = createTestHook(
|
798
|
+
"onTestFinished",
|
799
|
+
(test, handler, timeout) => {
|
800
|
+
test.onFinished || (test.onFinished = []);
|
801
|
+
test.onFinished.push(
|
802
|
+
withTimeout(handler, timeout ?? getDefaultHookTimeout(), true)
|
803
|
+
);
|
804
|
+
}
|
805
|
+
);
|
806
|
+
function createTestHook(name, handler) {
|
807
|
+
return (fn, timeout) => {
|
808
|
+
assertTypes(fn, `"${name}" callback`, ["function"]);
|
809
|
+
const current = getCurrentTest();
|
810
|
+
if (!current) {
|
811
|
+
throw new Error(`Hook ${name}() can only be called inside a test`);
|
812
|
+
}
|
813
|
+
return handler(current, fn, timeout);
|
814
|
+
};
|
815
|
+
}
|
816
|
+
|
757
817
|
async function runSetupFiles(config, files, runner) {
|
758
818
|
if (config.sequence.setupFiles === "parallel") {
|
759
819
|
await Promise.all(
|
@@ -1220,64 +1280,4 @@ async function publicCollect(paths, runner) {
|
|
1220
1280
|
return files;
|
1221
1281
|
}
|
1222
1282
|
|
1223
|
-
function getDefaultHookTimeout() {
|
1224
|
-
return getRunner().config.hookTimeout;
|
1225
|
-
}
|
1226
|
-
function beforeAll(fn, timeout) {
|
1227
|
-
assertTypes(fn, '"beforeAll" callback', ["function"]);
|
1228
|
-
return getCurrentSuite().on(
|
1229
|
-
"beforeAll",
|
1230
|
-
withTimeout(fn, timeout ?? getDefaultHookTimeout(), true)
|
1231
|
-
);
|
1232
|
-
}
|
1233
|
-
function afterAll(fn, timeout) {
|
1234
|
-
assertTypes(fn, '"afterAll" callback', ["function"]);
|
1235
|
-
return getCurrentSuite().on(
|
1236
|
-
"afterAll",
|
1237
|
-
withTimeout(fn, timeout ?? getDefaultHookTimeout(), true)
|
1238
|
-
);
|
1239
|
-
}
|
1240
|
-
function beforeEach(fn, timeout) {
|
1241
|
-
assertTypes(fn, '"beforeEach" callback', ["function"]);
|
1242
|
-
return getCurrentSuite().on(
|
1243
|
-
"beforeEach",
|
1244
|
-
withTimeout(withFixtures(fn), timeout ?? getDefaultHookTimeout(), true)
|
1245
|
-
);
|
1246
|
-
}
|
1247
|
-
function afterEach(fn, timeout) {
|
1248
|
-
assertTypes(fn, '"afterEach" callback', ["function"]);
|
1249
|
-
return getCurrentSuite().on(
|
1250
|
-
"afterEach",
|
1251
|
-
withTimeout(withFixtures(fn), timeout ?? getDefaultHookTimeout(), true)
|
1252
|
-
);
|
1253
|
-
}
|
1254
|
-
const onTestFailed = createTestHook(
|
1255
|
-
"onTestFailed",
|
1256
|
-
(test, handler, timeout) => {
|
1257
|
-
test.onFailed || (test.onFailed = []);
|
1258
|
-
test.onFailed.push(
|
1259
|
-
withTimeout(handler, timeout ?? getDefaultHookTimeout(), true)
|
1260
|
-
);
|
1261
|
-
}
|
1262
|
-
);
|
1263
|
-
const onTestFinished = createTestHook(
|
1264
|
-
"onTestFinished",
|
1265
|
-
(test, handler, timeout) => {
|
1266
|
-
test.onFinished || (test.onFinished = []);
|
1267
|
-
test.onFinished.push(
|
1268
|
-
withTimeout(handler, timeout ?? getDefaultHookTimeout(), true)
|
1269
|
-
);
|
1270
|
-
}
|
1271
|
-
);
|
1272
|
-
function createTestHook(name, handler) {
|
1273
|
-
return (fn, timeout) => {
|
1274
|
-
assertTypes(fn, `"${name}" callback`, ["function"]);
|
1275
|
-
const current = getCurrentTest();
|
1276
|
-
if (!current) {
|
1277
|
-
throw new Error(`Hook ${name}() can only be called inside a test`);
|
1278
|
-
}
|
1279
|
-
return handler(current, fn, timeout);
|
1280
|
-
};
|
1281
|
-
}
|
1282
|
-
|
1283
1283
|
export { afterAll, afterEach, beforeAll, beforeEach, publicCollect as collectTests, createTaskCollector, describe, getCurrentSuite, getCurrentTest, getFn, getHooks, it, onTestFailed, onTestFinished, setFn, setHooks, startTests, suite, test, updateTask };
|
@@ -1,12 +1,5 @@
|
|
1
1
|
import { ErrorWithDiff, Awaitable } from '@vitest/utils';
|
2
2
|
|
3
|
-
type ChainableFunction<T extends string, F extends (...args: any) => any, C = object> = F & {
|
4
|
-
[x in T]: ChainableFunction<T, F, C>;
|
5
|
-
} & {
|
6
|
-
fn: (this: Record<T, any>, ...args: Parameters<F>) => ReturnType<F>;
|
7
|
-
} & C;
|
8
|
-
declare function createChainable<T extends string, Args extends any[], R = any>(keys: T[], fn: (this: Record<T, any>, ...args: Args) => R): ChainableFunction<T, (...args: Args) => R>;
|
9
|
-
|
10
3
|
interface FixtureItem extends FixtureOptions {
|
11
4
|
prop: string;
|
12
5
|
value: any;
|
@@ -20,6 +13,13 @@ interface FixtureItem extends FixtureOptions {
|
|
20
13
|
deps?: FixtureItem[];
|
21
14
|
}
|
22
15
|
|
16
|
+
type ChainableFunction<T extends string, F extends (...args: any) => any, C = object> = F & {
|
17
|
+
[x in T]: ChainableFunction<T, F, C>;
|
18
|
+
} & {
|
19
|
+
fn: (this: Record<T, any>, ...args: Parameters<F>) => ReturnType<F>;
|
20
|
+
} & C;
|
21
|
+
declare function createChainable<T extends string, Args extends any[], R = any>(keys: T[], fn: (this: Record<T, any>, ...args: Args) => R): ChainableFunction<T, (...args: Args) => R>;
|
22
|
+
|
23
23
|
type RunMode = 'run' | 'skip' | 'only' | 'todo';
|
24
24
|
type TaskState = RunMode | 'pass' | 'fail';
|
25
25
|
interface TaskBase {
|
@@ -335,12 +335,12 @@ interface ExtendedAPI<ExtraContext> {
|
|
335
335
|
skipIf: (condition: any) => ChainableTestAPI<ExtraContext>;
|
336
336
|
runIf: (condition: any) => ChainableTestAPI<ExtraContext>;
|
337
337
|
}
|
338
|
-
type
|
339
|
-
extend: <T extends Record<string, any> = object>(fixtures: Fixtures<T, ExtraContext>) =>
|
338
|
+
type TestAPI<ExtraContext = object> = ChainableTestAPI<ExtraContext> & ExtendedAPI<ExtraContext> & {
|
339
|
+
extend: <T extends Record<string, any> = object>(fixtures: Fixtures<T, ExtraContext>) => TestAPI<{
|
340
340
|
[K in keyof T | keyof ExtraContext]: K extends keyof T ? T[K] : K extends keyof ExtraContext ? ExtraContext[K] : never;
|
341
341
|
}>;
|
342
342
|
};
|
343
|
-
|
343
|
+
|
344
344
|
interface FixtureOptions {
|
345
345
|
/**
|
346
346
|
* Whether to automatically set up current fixture, even though it's not being used in tests.
|
@@ -468,4 +468,4 @@ interface TaskHook<HookListener> {
|
|
468
468
|
type SequenceHooks = 'stack' | 'list' | 'parallel';
|
469
469
|
type SequenceSetupFiles = 'list' | 'parallel';
|
470
470
|
|
471
|
-
export { type AfterAllListener as A, type BeforeAllListener as B, type Custom as C, type DoneCallback as D, type
|
471
|
+
export { type AfterAllListener as A, type BeforeAllListener as B, type Custom as C, type DoneCallback as D, type ExtendedContext as E, type File as F, type TaskResultPack as G, type HookCleanupCallback as H, type InferFixturesTypes as I, type TaskState as J, type TestContext as K, type TestFunction as L, type TestOptions as M, type OnTestFailedHandler as O, type RunMode as R, type Suite as S, type Task as T, type Use as U, type Test as a, type ChainableFunction as b, createChainable as c, type BeforeEachListener as d, type AfterEachListener as e, type TaskHook as f, type OnTestFinishedHandler as g, type SuiteHooks as h, type SuiteAPI as i, type TestAPI as j, type SuiteCollector as k, type Fixture as l, type FixtureFn as m, type FixtureOptions as n, type Fixtures as o, type HookListener as p, type RuntimeContext as q, type SequenceHooks as r, type SequenceSetupFiles as s, type SuiteFactory as t, type TaskBase as u, type TaskContext as v, type TaskCustomOptions as w, type TaskMeta as x, type TaskPopulated as y, type TaskResult as z };
|
package/dist/types.d.ts
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
import { M as SequenceHooks, N as SequenceSetupFiles, F as File, T as Task, a as Test, C as Custom, S as Suite, r as TaskResultPack, K as TaskContext, L as ExtendedContext } from './tasks-SNKRxoD7.js';
|
2
|
-
export { A as AfterAllListener, i as AfterEachListener, B as BeforeAllListener, h as BeforeEachListener, g as CustomAPI, D as DoneCallback, w as Fixture, v as FixtureFn, u as FixtureOptions, x as Fixtures, y as HookCleanupCallback, H as HookListener, I as InferFixturesTypes, O as OnTestFailedHandler, k as OnTestFinishedHandler, R as RunMode, G as RuntimeContext, d as SuiteAPI, f as SuiteCollector, E as SuiteFactory, l as SuiteHooks, n as TaskBase, z as TaskCustomOptions, j as TaskHook, p as TaskMeta, o as TaskPopulated, q as TaskResult, m as TaskState, e as TestAPI, J as TestContext, s as TestFunction, t as TestOptions, U as Use } from './tasks-SNKRxoD7.js';
|
3
1
|
import { DiffOptions } from '@vitest/utils/diff';
|
2
|
+
import { r as SequenceHooks, s as SequenceSetupFiles, F as File, T as Task, a as Test, C as Custom, S as Suite, G as TaskResultPack, v as TaskContext, E as ExtendedContext } from './tasks-3ZnPj1LR.js';
|
3
|
+
export { A as AfterAllListener, e as AfterEachListener, B as BeforeAllListener, d as BeforeEachListener, j as CustomAPI, D as DoneCallback, l as Fixture, m as FixtureFn, n as FixtureOptions, o as Fixtures, H as HookCleanupCallback, p as HookListener, I as InferFixturesTypes, O as OnTestFailedHandler, g as OnTestFinishedHandler, R as RunMode, q as RuntimeContext, i as SuiteAPI, k as SuiteCollector, t as SuiteFactory, h as SuiteHooks, u as TaskBase, w as TaskCustomOptions, f as TaskHook, x as TaskMeta, y as TaskPopulated, z as TaskResult, J as TaskState, j as TestAPI, K as TestContext, L as TestFunction, M as TestOptions, U as Use } from './tasks-3ZnPj1LR.js';
|
4
4
|
import '@vitest/utils';
|
5
5
|
|
6
6
|
/**
|
package/dist/utils.d.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
import { S as Suite, F as File, T as Task, a as Test, C as Custom } from './tasks-
|
2
|
-
export { b as ChainableFunction, c as createChainable } from './tasks-
|
1
|
+
import { S as Suite, F as File, T as Task, a as Test, C as Custom } from './tasks-3ZnPj1LR.js';
|
2
|
+
export { b as ChainableFunction, c as createChainable } from './tasks-3ZnPj1LR.js';
|
3
3
|
import { Arrayable } from '@vitest/utils';
|
4
4
|
|
5
5
|
/**
|
@@ -11,6 +11,11 @@ declare function generateHash(str: string): string;
|
|
11
11
|
declare function calculateSuiteHash(parent: Suite): void;
|
12
12
|
declare function createFileTask(filepath: string, root: string, projectName: string | undefined, pool?: string): File;
|
13
13
|
|
14
|
+
/**
|
15
|
+
* Return a function for running multiple async operations with limited concurrency.
|
16
|
+
*/
|
17
|
+
declare function limitConcurrency(concurrency?: number): <Args extends unknown[], T>(func: (...args: Args) => PromiseLike<T> | T, ...args: Args) => Promise<T>;
|
18
|
+
|
14
19
|
/**
|
15
20
|
* Partition in tasks groups by consecutive concurrent
|
16
21
|
*/
|
@@ -23,10 +28,7 @@ declare function getSuites(suite: Arrayable<Task>): Suite[];
|
|
23
28
|
declare function hasTests(suite: Arrayable<Suite>): boolean;
|
24
29
|
declare function hasFailed(suite: Arrayable<Task>): boolean;
|
25
30
|
declare function getNames(task: Task): string[];
|
31
|
+
declare function getFullName(task: Task, separator?: string): string;
|
32
|
+
declare function getTestName(task: Task, separator?: string): string;
|
26
33
|
|
27
|
-
|
28
|
-
* Return a function for running multiple async operations with limited concurrency.
|
29
|
-
*/
|
30
|
-
declare function limitConcurrency(concurrency?: number): <Args extends unknown[], T>(func: (...args: Args) => PromiseLike<T> | T, ...args: Args) => Promise<T>;
|
31
|
-
|
32
|
-
export { calculateSuiteHash, createFileTask, generateHash, getNames, getSuites, getTasks, getTests, hasFailed, hasTests, interpretTaskModes, isAtomTest, limitConcurrency, partitionSuiteChildren, someTasksAreOnly };
|
34
|
+
export { calculateSuiteHash, createFileTask, generateHash, getFullName, getNames, getSuites, getTasks, getTestName, getTests, hasFailed, hasTests, interpretTaskModes, isAtomTest, limitConcurrency, partitionSuiteChildren, someTasksAreOnly };
|
package/dist/utils.js
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
export {
|
1
|
+
export { a as calculateSuiteHash, c as createChainable, b as createFileTask, g as generateHash, d as getFullName, e as getNames, f as getSuites, h as getTasks, j as getTestName, k as getTests, m as hasFailed, n as hasTests, i as interpretTaskModes, o as isAtomTest, l as limitConcurrency, p as partitionSuiteChildren, s as someTasksAreOnly } from './chunk-tasks.js';
|
2
2
|
import '@vitest/utils/error';
|
3
3
|
import 'pathe';
|
4
4
|
import '@vitest/utils';
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@vitest/runner",
|
3
3
|
"type": "module",
|
4
|
-
"version": "2.1.
|
4
|
+
"version": "2.1.4",
|
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.1.
|
42
|
+
"@vitest/utils": "2.1.4"
|
43
43
|
},
|
44
44
|
"scripts": {
|
45
45
|
"build": "rimraf dist && rollup -c",
|