@vitest/runner 2.0.4 → 2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  import { VitestRunner } from './types.js';
2
2
  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-zB5uPauP.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-zB5uPauP.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-C13WjyUB.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-C13WjyUB.js';
5
5
  import { Awaitable } from '@vitest/utils';
6
6
  export { processError } from '@vitest/utils/error';
7
7
  import '@vitest/utils/diff';
@@ -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
@@ -307,13 +307,20 @@ const it = test;
307
307
  let runner;
308
308
  let defaultSuite;
309
309
  let currentTestFilepath;
310
+ function assert(condition, message) {
311
+ if (!condition) {
312
+ throw new Error(`Vitest failed to find ${message}. This is a bug in Vitest. Please, open an issue with reproduction.`);
313
+ }
314
+ }
310
315
  function getDefaultSuite() {
316
+ assert(defaultSuite, "the default suite");
311
317
  return defaultSuite;
312
318
  }
313
319
  function getTestFilepath() {
314
320
  return currentTestFilepath;
315
321
  }
316
322
  function getRunner() {
323
+ assert(runner, "the runner");
317
324
  return runner;
318
325
  }
319
326
  function createDefaultSuite(runner2) {
@@ -333,7 +340,9 @@ function clearCollectorContext(filepath, currentRunner) {
333
340
  collectorContext.currentSuite = defaultSuite;
334
341
  }
335
342
  function getCurrentSuite() {
336
- return collectorContext.currentSuite || defaultSuite;
343
+ const currentSuite = collectorContext.currentSuite || defaultSuite;
344
+ assert(currentSuite, "the current suite");
345
+ return currentSuite;
337
346
  }
338
347
  function createSuiteHooks() {
339
348
  return {
@@ -518,7 +527,7 @@ function createSuiteCollector(name, factory = () => {
518
527
  function createSuite() {
519
528
  function suiteFn(name, factoryOrOptions, optionsOrFactory = {}) {
520
529
  const mode = this.only ? "only" : this.skip ? "skip" : this.todo ? "todo" : "run";
521
- const currentSuite = getCurrentSuite();
530
+ const currentSuite = collectorContext.currentSuite || defaultSuite;
522
531
  let { options, handler: factory } = parseArguments(
523
532
  factoryOrOptions,
524
533
  optionsOrFactory
@@ -727,8 +736,7 @@ function findTestFileStackTrace(error, each) {
727
736
  }
728
737
  }
729
738
 
730
- async function runSetupFiles(config, runner) {
731
- const files = toArray(config.setupFiles);
739
+ async function runSetupFiles(config, files, runner) {
732
740
  if (config.sequence.setupFiles === "parallel") {
733
741
  await Promise.all(
734
742
  files.map(async (fsPath) => {
@@ -752,10 +760,16 @@ async function collectTests(paths, runner) {
752
760
  (_a = runner.onCollectStart) == null ? void 0 : _a.call(runner, file);
753
761
  clearCollectorContext(filepath, runner);
754
762
  try {
755
- const setupStart = now$1();
756
- await runSetupFiles(config, runner);
763
+ const setupFiles = toArray(config.setupFiles);
764
+ if (setupFiles.length) {
765
+ const setupStart = now$1();
766
+ await runSetupFiles(config, setupFiles, runner);
767
+ const setupEnd = now$1();
768
+ file.setupDuration = setupEnd - setupStart;
769
+ } else {
770
+ file.setupDuration = 0;
771
+ }
757
772
  const collectStart = now$1();
758
- file.setupDuration = collectStart - setupStart;
759
773
  await runner.importFile(filepath, "collect");
760
774
  const defaultTasks = await getDefaultSuite().collect(file);
761
775
  const fileHooks = createSuiteHooks();
@@ -783,6 +797,12 @@ async function collectTests(paths, runner) {
783
797
  };
784
798
  }
785
799
  calculateSuiteHash(file);
800
+ file.tasks.forEach((task) => {
801
+ var _a2;
802
+ if (((_a2 = task.suite) == null ? void 0 : _a2.id) === "") {
803
+ delete task.suite;
804
+ }
805
+ });
786
806
  const hasOnlyTasks = someTasksAreOnly(file);
787
807
  interpretTaskModes(
788
808
  file,
@@ -791,12 +811,6 @@ async function collectTests(paths, runner) {
791
811
  false,
792
812
  config.allowOnly
793
813
  );
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
814
  files.push(file);
801
815
  }
802
816
  return files;
@@ -23,74 +23,216 @@ interface FixtureItem extends FixtureOptions {
23
23
  type RunMode = 'run' | 'skip' | 'only' | 'todo';
24
24
  type TaskState = RunMode | 'pass' | 'fail';
25
25
  interface TaskBase {
26
+ /**
27
+ * Unique task identifier. Based on the file id and the position of the task.
28
+ * The id of the file task is based on the file path relative to root and project name.
29
+ * It will not change between runs.
30
+ * @example `1201091390`, `1201091390_0`, `1201091390_0_1`
31
+ */
26
32
  id: string;
33
+ /**
34
+ * Task name provided by the user. If no name was provided, it will be an empty string.
35
+ */
27
36
  name: string;
37
+ /**
38
+ * Task mode.
39
+ * - **skip**: task is skipped
40
+ * - **only**: only this task and other tasks with `only` mode will run
41
+ * - **todo**: task is marked as a todo, alias for `skip`
42
+ * - **run**: task will run or already ran
43
+ */
28
44
  mode: RunMode;
45
+ /**
46
+ * Custom metadata for the task. JSON reporter will save this data.
47
+ */
29
48
  meta: TaskMeta;
49
+ /**
50
+ * Whether the task was produced with `.each()` method.
51
+ */
30
52
  each?: boolean;
53
+ /**
54
+ * Whether the task should run concurrently with other tasks.
55
+ */
31
56
  concurrent?: boolean;
57
+ /**
58
+ * Whether the tasks of the suite run in a random order.
59
+ */
32
60
  shuffle?: boolean;
61
+ /**
62
+ * Suite that this task is part of. File task or the global suite will have no parent.
63
+ */
33
64
  suite?: Suite;
65
+ /**
66
+ * Result of the task. Suite and file tasks will only have the result if there
67
+ * was an error during collection or inside `afterAll`/`beforeAll`.
68
+ */
34
69
  result?: TaskResult;
70
+ /**
71
+ * The amount of times the task should be retried if it fails.
72
+ * @default 0
73
+ */
35
74
  retry?: number;
75
+ /**
76
+ * The amount of times the task should be repeated after the successful run.
77
+ * If the task fails, it will not be retried unless `retry` is specified.
78
+ * @default 0
79
+ */
36
80
  repeats?: number;
81
+ /**
82
+ * Location of the task in the file. This field is populated only if
83
+ * `includeTaskLocation` option is set. It is generated by calling `new Error`
84
+ * and parsing the stack trace, so the location might differ depending on the runtime.
85
+ */
37
86
  location?: {
38
87
  line: number;
39
88
  column: number;
40
89
  };
41
90
  }
42
91
  interface TaskPopulated extends TaskBase {
92
+ /**
93
+ * File task. It's the root task of the file.
94
+ */
43
95
  file: File;
96
+ /**
97
+ * Whether the task was skipped by calling `t.skip()`.
98
+ */
44
99
  pending?: boolean;
45
- result?: TaskResult;
100
+ /**
101
+ * Whether the task should succeed if it fails. If the task fails, it will be marked as passed.
102
+ */
46
103
  fails?: boolean;
104
+ /**
105
+ * Hooks that will run if the task fails. The order depends on the `sequence.hooks` option.
106
+ */
47
107
  onFailed?: OnTestFailedHandler[];
108
+ /**
109
+ * Hooks that will run after the task finishes. The order depends on the `sequence.hooks` option.
110
+ */
48
111
  onFinished?: OnTestFinishedHandler[];
49
112
  /**
50
113
  * Store promises (from async expects) to wait for them before finishing the test
51
114
  */
52
115
  promises?: Promise<any>[];
53
116
  }
117
+ /**
118
+ * Custom metadata that can be used in reporters.
119
+ */
54
120
  interface TaskMeta {
55
121
  }
122
+ /**
123
+ * The result of calling a task.
124
+ */
56
125
  interface TaskResult {
126
+ /**
127
+ * State of the task. Inherits the `task.mode` during collection.
128
+ * When the task has finished, it will be changed to `pass` or `fail`.
129
+ * - **pass**: task ran successfully
130
+ * - **fail**: task failed
131
+ */
57
132
  state: TaskState;
133
+ /**
134
+ * Errors that occurred during the task execution. It is possible to have several errors
135
+ * if `expect.soft()` failed multiple times.
136
+ */
137
+ errors?: ErrorWithDiff[];
138
+ /**
139
+ * How long in milliseconds the task took to run.
140
+ */
58
141
  duration?: number;
142
+ /**
143
+ * Time in milliseconds when the task started running.
144
+ */
59
145
  startTime?: number;
146
+ /**
147
+ * Heap size in bytes after the task finished.
148
+ * Only available if `logHeapUsage` option is set and `process.memoryUsage` is defined.
149
+ */
60
150
  heap?: number;
61
- errors?: ErrorWithDiff[];
62
- htmlError?: string;
151
+ /**
152
+ * State of related to this task hooks. Useful during reporting.
153
+ */
63
154
  hooks?: Partial<Record<keyof SuiteHooks, TaskState>>;
155
+ /**
156
+ * The amount of times the task was retried. The task is retried only if it
157
+ * failed and `retry` option is set.
158
+ */
64
159
  retryCount?: number;
160
+ /**
161
+ * The amount of times the task was repeated. The task is repeated only if
162
+ * `repeats` option is set. This number also contains `retryCount`.
163
+ */
65
164
  repeatCount?: number;
66
165
  }
166
+ /**
167
+ * The tuple representing a single task update.
168
+ * Usually reported after the task finishes.
169
+ */
67
170
  type TaskResultPack = [
171
+ /**
172
+ * Unique task identifier from `task.id`.
173
+ */
68
174
  id: string,
175
+ /**
176
+ * The result of running the task from `task.result`.
177
+ */
69
178
  result: TaskResult | undefined,
179
+ /**
180
+ * Custom metadata from `task.meta`.
181
+ */
70
182
  meta: TaskMeta
71
183
  ];
72
184
  interface Suite extends TaskBase {
73
- file: File;
74
185
  type: 'suite';
186
+ /**
187
+ * File task. It's the root task of the file.
188
+ */
189
+ file: File;
190
+ /**
191
+ * An array of tasks that are part of the suite.
192
+ */
75
193
  tasks: Task[];
76
194
  }
77
195
  interface File extends Suite {
196
+ /**
197
+ * The name of the pool that the file belongs to.
198
+ * @default 'forks'
199
+ */
78
200
  pool?: string;
201
+ /**
202
+ * The path to the file in UNIX format.
203
+ */
79
204
  filepath: string;
205
+ /**
206
+ * The name of the workspace project the file belongs to.
207
+ */
80
208
  projectName: string | undefined;
209
+ /**
210
+ * The time it took to collect all tests in the file.
211
+ * This time also includes importing all the file dependencies.
212
+ */
81
213
  collectDuration?: number;
214
+ /**
215
+ * The time it took to import the setup file.
216
+ */
82
217
  setupDuration?: number;
83
218
  /**
84
219
  * Whether the file is initiated without running any tests.
220
+ * This is done to populate state on the server side by Vitest.
85
221
  */
86
222
  local?: boolean;
87
223
  }
88
224
  interface Test<ExtraContext = object> extends TaskPopulated {
89
225
  type: 'test';
226
+ /**
227
+ * Test context that will be passed to the test function.
228
+ */
90
229
  context: TaskContext<Test> & ExtraContext & TestContext;
91
230
  }
92
231
  interface Custom<ExtraContext = object> extends TaskPopulated {
93
232
  type: 'custom';
233
+ /**
234
+ * Task context that will be passed to the test function.
235
+ */
94
236
  context: TaskContext<Custom> & ExtraContext & TestContext;
95
237
  }
96
238
  type Task = Test | Suite | Custom | File;
@@ -156,7 +298,7 @@ interface TestOptions {
156
298
  */
157
299
  retry?: number;
158
300
  /**
159
- * How many times the test will run.
301
+ * How many times the test will run again.
160
302
  * Only inner tests will repeat if set on `describe()`, nested `describe()` will inherit parent's repeat by default.
161
303
  *
162
304
  * @default 0
@@ -198,11 +340,7 @@ type CustomAPI<ExtraContext = object> = ChainableTestAPI<ExtraContext> & Extende
198
340
  [K in keyof T | keyof ExtraContext]: K extends keyof T ? T[K] : K extends keyof ExtraContext ? ExtraContext[K] : never;
199
341
  }>;
200
342
  };
201
- type TestAPI<ExtraContext = object> = ChainableTestAPI<ExtraContext> & ExtendedAPI<ExtraContext> & {
202
- extend: <T extends Record<string, any> = object>(fixtures: Fixtures<T, ExtraContext>) => TestAPI<{
203
- [K in keyof T | keyof ExtraContext]: K extends keyof T ? T[K] : K extends keyof ExtraContext ? ExtraContext[K] : never;
204
- }>;
205
- };
343
+ type TestAPI<ExtraContext = object> = CustomAPI<ExtraContext>;
206
344
  interface FixtureOptions {
207
345
  /**
208
346
  * Whether to automatically set up current fixture, even though it's not being used in tests.
@@ -255,15 +393,23 @@ interface SuiteHooks<ExtraContext = object> {
255
393
  afterEach: AfterEachListener<ExtraContext>[];
256
394
  }
257
395
  interface TaskCustomOptions extends TestOptions {
258
- concurrent?: boolean;
259
- sequential?: boolean;
260
- skip?: boolean;
261
- only?: boolean;
262
- todo?: boolean;
263
- fails?: boolean;
396
+ /**
397
+ * Whether the task was produced with `.each()` method.
398
+ */
264
399
  each?: boolean;
400
+ /**
401
+ * Custom metadata for the task that will be assigned to `task.meta`.
402
+ */
265
403
  meta?: Record<string, unknown>;
404
+ /**
405
+ * Task fixtures.
406
+ */
266
407
  fixtures?: FixtureItem[];
408
+ /**
409
+ * Function that will be called when the task is executed.
410
+ * If nothing is provided, the runner will try to get the function using `getFn(task)`.
411
+ * If the runner cannot find the function, the task will be marked as failed.
412
+ */
267
413
  handler?: (context: TaskContext<Custom>) => Awaitable<void>;
268
414
  }
269
415
  interface SuiteCollector<ExtraContext = object> {
@@ -300,6 +446,7 @@ interface TaskContext<Task extends Custom | Test = Custom | Test> {
300
446
  onTestFinished: (fn: OnTestFinishedHandler) => void;
301
447
  /**
302
448
  * Mark tests as skipped. All execution after this call will be skipped.
449
+ * This function throws an error, so make sure you are not catching it accidentally.
303
450
  */
304
451
  skip: () => void;
305
452
  }
package/dist/types.d.ts CHANGED
@@ -1,12 +1,15 @@
1
- import { M as SequenceHooks, N as SequenceSetupFiles, F as File, T as Task, S as Suite, r as TaskResultPack, a as Test, C as Custom, K as TaskContext, L as ExtendedContext } from './tasks-zB5uPauP.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-zB5uPauP.js';
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-C13WjyUB.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-C13WjyUB.js';
3
3
  import { DiffOptions } from '@vitest/utils/diff';
4
4
  import '@vitest/utils';
5
5
 
6
+ /**
7
+ * This is a subset of Vitest config that's required for the runner to work.
8
+ */
6
9
  interface VitestRunnerConfig {
7
10
  root: string;
8
- setupFiles: string[] | string;
9
- name: string;
11
+ setupFiles: string[];
12
+ name?: string;
10
13
  passWithNoTests: boolean;
11
14
  testNamePattern?: RegExp;
12
15
  allowOnly?: boolean;
@@ -65,7 +68,7 @@ interface VitestRunner {
65
68
  /**
66
69
  * When the task has finished running, but before cleanup hooks are called
67
70
  */
68
- onTaskFinished?: (test: Task) => unknown;
71
+ onTaskFinished?: (test: Test | Custom) => unknown;
69
72
  /**
70
73
  * Called after result and state are set.
71
74
  */
@@ -108,7 +111,7 @@ interface VitestRunner {
108
111
  */
109
112
  onAfterRunFiles?: (files: File[]) => unknown;
110
113
  /**
111
- * Called when new context for a test is defined. Useful, if you want to add custom properties to the context.
114
+ * Called when new context for a test is defined. Useful if you want to add custom properties to the context.
112
115
  * If you only want to define custom context, consider using "beforeAll" in "setupFiles" instead.
113
116
  *
114
117
  * This method is called for both "test" and "custom" handlers.
@@ -117,7 +120,7 @@ interface VitestRunner {
117
120
  */
118
121
  extendTaskContext?: <T extends Test | Custom>(context: TaskContext<T>) => ExtendedContext<T>;
119
122
  /**
120
- * Called, when files are imported. Can be called in two situations: when collecting tests and when importing setup files.
123
+ * Called when test and setup files are imported. Can be called in two situations: when collecting tests and when importing setup files.
121
124
  */
122
125
  importFile: (filepath: string, source: VitestRunnerImportSource) => unknown;
123
126
  /**
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-zB5uPauP.js';
2
- export { b as ChainableFunction, c as createChainable } from './tasks-zB5uPauP.js';
1
+ import { S as Suite, F as File, T as Task, a as Test, C as Custom } from './tasks-C13WjyUB.js';
2
+ export { b as ChainableFunction, c as createChainable } from './tasks-C13WjyUB.js';
3
3
  import { Arrayable } from '@vitest/utils';
4
4
 
5
5
  /**
@@ -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",
4
+ "version": "2.1.0-beta.1",
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.4"
42
+ "@vitest/utils": "2.1.0-beta.1"
43
43
  },
44
44
  "scripts": {
45
45
  "build": "rimraf dist && rollup -c",