@vitest/runner 0.34.7 → 1.0.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 SuiteHooks, O as OnTestFailedHandler, a as Test } from './tasks-d7d578d8.js';
4
- export { D as DoneCallback, o as Fixture, p as Fixtures, q as HookCleanupCallback, H as HookListener, I as InferFixturesTypes, R as RunMode, s as RuntimeContext, u as SequenceHooks, v as SequenceSetupFiles, S as Suite, r as SuiteFactory, i as TaskBase, b as TaskCustom, j as TaskMeta, k as TaskResult, l as TaskResultPack, h as TaskState, t as TestContext, m as TestFunction, n as TestOptions } from './tasks-d7d578d8.js';
3
+ import { T as Task, F as File, d as SuiteAPI, e as TestAPI, f as SuiteCollector, g as CustomAPI, h as SuiteHooks, O as OnTestFailedHandler, a as Test, C as Custom } from './tasks-b31a73cb.js';
4
+ export { D as DoneCallback, E as ExtendedContext, q as Fixture, r as Fixtures, s as HookCleanupCallback, H as HookListener, I as InferFixturesTypes, R as RunMode, v as RuntimeContext, y as SequenceHooks, z as SequenceSetupFiles, S as Suite, u as SuiteFactory, j as TaskBase, x as TaskContext, t as TaskCustomOptions, l as TaskMeta, k as TaskPopulated, m as TaskResult, n as TaskResultPack, i as TaskState, w as TestContext, o as TestFunction, p as TestOptions } from './tasks-b31a73cb.js';
5
5
  import { Awaitable } from '@vitest/utils';
6
6
 
7
7
  declare function updateTask(task: Task, runner: VitestRunner): void;
@@ -12,6 +12,7 @@ declare const test: TestAPI;
12
12
  declare const describe: SuiteAPI;
13
13
  declare const it: TestAPI;
14
14
  declare function getCurrentSuite<ExtraContext = {}>(): SuiteCollector<ExtraContext>;
15
+ declare function createTaskCollector(fn: (...args: any[]) => any, context?: Record<string, unknown>): CustomAPI;
15
16
 
16
17
  declare function beforeAll(fn: SuiteHooks['beforeAll'][0], timeout?: number): void;
17
18
  declare function afterAll(fn: SuiteHooks['afterAll'][0], timeout?: number): void;
@@ -19,9 +20,9 @@ declare function beforeEach<ExtraContext = {}>(fn: SuiteHooks<ExtraContext>['bef
19
20
  declare function afterEach<ExtraContext = {}>(fn: SuiteHooks<ExtraContext>['afterEach'][0], timeout?: number): void;
20
21
  declare const onTestFailed: (fn: OnTestFailedHandler) => void;
21
22
 
22
- declare function setFn(key: Test, fn: (() => Awaitable<void>)): void;
23
- declare function getFn<Task = Test>(key: Task): (() => Awaitable<void>);
23
+ declare function setFn(key: Test | Custom, fn: (() => Awaitable<void>)): void;
24
+ declare function getFn<Task = Test | Custom>(key: Task): (() => Awaitable<void>);
24
25
 
25
- declare function getCurrentTest(): Test<{}> | undefined;
26
+ declare function getCurrentTest<T extends Test | Custom | undefined>(): T;
26
27
 
27
- export { File, OnTestFailedHandler, SuiteAPI, SuiteCollector, SuiteHooks, Task, Test, TestAPI, VitestRunner, afterAll, afterEach, beforeAll, beforeEach, describe, getCurrentSuite, getCurrentTest, getFn, it, onTestFailed, setFn, startTests, suite, test, updateTask };
28
+ export { Custom, CustomAPI, File, OnTestFailedHandler, SuiteAPI, SuiteCollector, SuiteHooks, Task, Test, TestAPI, VitestRunner, afterAll, afterEach, beforeAll, beforeEach, createTaskCollector, describe, getCurrentSuite, getCurrentTest, getFn, it, onTestFailed, setFn, startTests, suite, test, updateTask };
package/dist/index.js CHANGED
@@ -70,7 +70,6 @@ function createTestContext(test, runner) {
70
70
  const context = function() {
71
71
  throw new Error("done() callback is deprecated, use promise instead");
72
72
  };
73
- context.meta = test;
74
73
  context.task = test;
75
74
  context.skip = () => {
76
75
  test.pending = true;
@@ -80,7 +79,7 @@ function createTestContext(test, runner) {
80
79
  test.onFailed || (test.onFailed = []);
81
80
  test.onFailed.push(fn);
82
81
  };
83
- return ((_a = runner.extendTestContext) == null ? void 0 : _a.call(runner, context)) || context;
82
+ return ((_a = runner.extendTaskContext) == null ? void 0 : _a.call(runner, context)) || context;
84
83
  }
85
84
  function makeTimeoutMsg(isHook, timeout) {
86
85
  return `${isHook ? "Hook" : "Test"} timed out in ${timeout}ms.
@@ -274,52 +273,51 @@ function createSuiteCollector(name, factory = () => {
274
273
  const factoryQueue = [];
275
274
  let suite2;
276
275
  initSuite();
277
- const test2 = createTest(function(name2, fn = noop, options) {
278
- const mode2 = this.only ? "only" : this.skip ? "skip" : this.todo ? "todo" : "run";
279
- if (typeof options === "number")
280
- options = { timeout: options };
281
- if (typeof suiteOptions === "object")
282
- options = Object.assign({}, suiteOptions, options);
283
- const test3 = {
276
+ const task = function(name2 = "", options = {}) {
277
+ const task2 = {
284
278
  id: "",
285
- type: "test",
286
- name: formatName(name2),
287
- each: this.each,
288
- mode: mode2,
279
+ name: name2,
289
280
  suite: void 0,
290
- fails: this.fails,
291
- retry: (options == null ? void 0 : options.retry) ?? runner.config.retry,
292
- repeats: options == null ? void 0 : options.repeats,
293
- meta: /* @__PURE__ */ Object.create(null)
281
+ each: options.each,
282
+ fails: options.fails,
283
+ context: void 0,
284
+ type: "custom",
285
+ retry: options.retry ?? runner.config.retry,
286
+ repeats: options.repeats,
287
+ mode: options.only ? "only" : options.skip ? "skip" : options.todo ? "todo" : "run",
288
+ meta: options.meta ?? /* @__PURE__ */ Object.create(null)
294
289
  };
295
- if (this.concurrent || !sequential && (concurrent || runner.config.sequence.concurrent))
296
- test3.concurrent = true;
290
+ const handler = options.handler;
291
+ if (options.concurrent || !sequential && (concurrent || runner.config.sequence.concurrent))
292
+ task2.concurrent = true;
297
293
  if (shuffle)
298
- test3.shuffle = true;
299
- const context = createTestContext(test3, runner);
300
- Object.defineProperty(test3, "context", {
294
+ task2.shuffle = true;
295
+ const context = createTestContext(task2, runner);
296
+ Object.defineProperty(task2, "context", {
301
297
  value: context,
302
298
  enumerable: false
303
299
  });
304
- setFixture(context, this.fixtures);
305
- setFn(test3, withTimeout(
306
- withFixtures(fn, context),
307
- (options == null ? void 0 : options.timeout) ?? runner.config.testTimeout
308
- ));
309
- tasks.push(test3);
310
- });
311
- const custom = function(name2 = "") {
312
- const self = this || {};
313
- const task = {
314
- id: "",
315
- name: name2,
316
- type: "custom",
317
- mode: self.only ? "only" : self.skip ? "skip" : self.todo ? "todo" : "run",
318
- meta: /* @__PURE__ */ Object.create(null)
319
- };
320
- tasks.push(task);
321
- return task;
300
+ setFixture(context, options.fixtures);
301
+ if (handler) {
302
+ setFn(task2, withTimeout(
303
+ withFixtures(handler, context),
304
+ (options == null ? void 0 : options.timeout) ?? runner.config.testTimeout
305
+ ));
306
+ }
307
+ tasks.push(task2);
308
+ return task2;
322
309
  };
310
+ const test2 = createTest(function(name2, fn = noop, options) {
311
+ if (typeof options === "number")
312
+ options = { timeout: options };
313
+ if (typeof suiteOptions === "object")
314
+ options = Object.assign({}, suiteOptions, options);
315
+ const test3 = task(
316
+ formatName(name2),
317
+ { ...this, ...options, handler: fn }
318
+ );
319
+ test3.type = "test";
320
+ });
323
321
  const collector = {
324
322
  type: "collector",
325
323
  name,
@@ -328,7 +326,7 @@ function createSuiteCollector(name, factory = () => {
328
326
  test: test2,
329
327
  tasks,
330
328
  collect,
331
- custom,
329
+ task,
332
330
  clear,
333
331
  on: addHook
334
332
  };
@@ -364,10 +362,10 @@ function createSuiteCollector(name, factory = () => {
364
362
  allChildren.push(i.type === "collector" ? await i.collect(file) : i);
365
363
  suite2.file = file;
366
364
  suite2.tasks = allChildren;
367
- allChildren.forEach((task) => {
368
- task.suite = suite2;
365
+ allChildren.forEach((task2) => {
366
+ task2.suite = suite2;
369
367
  if (file)
370
- task.file = file;
368
+ task2.file = file;
371
369
  });
372
370
  return suite2;
373
371
  }
@@ -406,9 +404,9 @@ function createSuite() {
406
404
  suiteFn
407
405
  );
408
406
  }
409
- function createTest(fn, context) {
410
- const testFn = fn;
411
- testFn.each = function(cases, ...args) {
407
+ function createTaskCollector(fn, context) {
408
+ const taskFn = fn;
409
+ taskFn.each = function(cases, ...args) {
412
410
  const test2 = this.withContext();
413
411
  this.setContext("each", true);
414
412
  if (Array.isArray(cases) && args.length)
@@ -423,9 +421,9 @@ function createTest(fn, context) {
423
421
  this.setContext("each", void 0);
424
422
  };
425
423
  };
426
- testFn.skipIf = (condition) => condition ? test.skip : test;
427
- testFn.runIf = (condition) => condition ? test : test.skip;
428
- testFn.extend = function(fixtures) {
424
+ taskFn.skipIf = (condition) => condition ? test.skip : test;
425
+ taskFn.runIf = (condition) => condition ? test : test.skip;
426
+ taskFn.extend = function(fixtures) {
429
427
  const _context = mergeContextFixtures(fixtures, context);
430
428
  return createTest(function fn2(name, fn2, options) {
431
429
  getCurrentSuite().test.fn.call(this, formatName(name), fn2, options);
@@ -433,12 +431,15 @@ function createTest(fn, context) {
433
431
  };
434
432
  const _test = createChainable(
435
433
  ["concurrent", "skip", "only", "todo", "fails"],
436
- testFn
434
+ taskFn
437
435
  );
438
436
  if (context)
439
437
  _test.mergeContext(context);
440
438
  return _test;
441
439
  }
440
+ function createTest(fn, context) {
441
+ return createTaskCollector(fn, context);
442
+ }
442
443
  function formatName(name) {
443
444
  return typeof name === "string" ? name : name instanceof Function ? name.name || "<anonymous>" : String(name);
444
445
  }
@@ -630,7 +631,7 @@ async function callCleanupHooks(cleanups) {
630
631
  }
631
632
  async function runTest(test, runner) {
632
633
  var _a, _b, _c, _d, _e, _f, _g;
633
- await ((_a = runner.onBeforeRunTest) == null ? void 0 : _a.call(runner, test));
634
+ await ((_a = runner.onBeforeRunTask) == null ? void 0 : _a.call(runner, test));
634
635
  if (test.mode !== "run")
635
636
  return;
636
637
  if (((_b = test.result) == null ? void 0 : _b.state) === "fail") {
@@ -651,11 +652,11 @@ async function runTest(test, runner) {
651
652
  for (let retryCount = 0; retryCount <= retry; retryCount++) {
652
653
  let beforeEachCleanups = [];
653
654
  try {
654
- await ((_c = runner.onBeforeTryTest) == null ? void 0 : _c.call(runner, test, { retry: retryCount, repeats: repeatCount }));
655
+ await ((_c = runner.onBeforeTryTask) == null ? void 0 : _c.call(runner, test, { retry: retryCount, repeats: repeatCount }));
655
656
  test.result.repeatCount = repeatCount;
656
657
  beforeEachCleanups = await callSuiteHook(test.suite, test, "beforeEach", runner, [test.context, test.suite]);
657
- if (runner.runTest) {
658
- await runner.runTest(test);
658
+ if (runner.runTask) {
659
+ await runner.runTask(test);
659
660
  } else {
660
661
  const fn = getFn(test);
661
662
  if (!fn)
@@ -668,7 +669,7 @@ async function runTest(test, runner) {
668
669
  if (errors.length)
669
670
  throw errors;
670
671
  }
671
- await ((_d = runner.onAfterTryTest) == null ? void 0 : _d.call(runner, test, { retry: retryCount, repeats: repeatCount }));
672
+ await ((_d = runner.onAfterTryTask) == null ? void 0 : _d.call(runner, test, { retry: retryCount, repeats: repeatCount }));
672
673
  if (test.result.state !== "fail") {
673
674
  if (!test.repeats)
674
675
  test.result.state = "pass";
@@ -715,7 +716,7 @@ async function runTest(test, runner) {
715
716
  }
716
717
  setCurrentTest(void 0);
717
718
  test.result.duration = now() - start;
718
- await ((_g = runner.onAfterRunTest) == null ? void 0 : _g.call(runner, test));
719
+ await ((_g = runner.onAfterRunTask) == null ? void 0 : _g.call(runner, test));
719
720
  updateTask(test, runner);
720
721
  }
721
722
  function failTask(result, err, diffOptions) {
@@ -813,7 +814,7 @@ async function runSuite(suite, runner) {
813
814
  }
814
815
  }
815
816
  async function runSuiteChild(c, runner) {
816
- if (c.type === "test")
817
+ if (c.type === "test" || c.type === "custom")
817
818
  return runTest(c, runner);
818
819
  else if (c.type === "suite")
819
820
  return runSuite(c, runner);
@@ -839,9 +840,9 @@ async function startTests(paths, runner) {
839
840
  await ((_a = runner.onBeforeCollect) == null ? void 0 : _a.call(runner, paths));
840
841
  const files = await collectTests(paths, runner);
841
842
  (_b = runner.onCollected) == null ? void 0 : _b.call(runner, files);
842
- await ((_c = runner.onBeforeRun) == null ? void 0 : _c.call(runner, files));
843
+ await ((_c = runner.onBeforeRunFiles) == null ? void 0 : _c.call(runner, files));
843
844
  await runFiles(files, runner);
844
- await ((_d = runner.onAfterRun) == null ? void 0 : _d.call(runner, files));
845
+ await ((_d = runner.onAfterRunFiles) == null ? void 0 : _d.call(runner, files));
845
846
  await sendTasksUpdate(runner);
846
847
  return files;
847
848
  }
@@ -874,4 +875,4 @@ function createTestHook(name, handler) {
874
875
  };
875
876
  }
876
877
 
877
- export { afterAll, afterEach, beforeAll, beforeEach, describe, getCurrentSuite, getCurrentTest, getFn, it, onTestFailed, setFn, startTests, suite, test, updateTask };
878
+ export { afterAll, afterEach, beforeAll, beforeEach, createTaskCollector, describe, getCurrentSuite, getCurrentTest, getFn, it, onTestFailed, setFn, startTests, suite, test, updateTask };
@@ -9,6 +9,20 @@ type ChainableFunction<T extends string, Args extends any[], R = any, E = {}> =
9
9
  } & E;
10
10
  declare function createChainable<T extends string, Args extends any[], R = any, E = {}>(keys: T[], fn: (this: Record<T, any>, ...args: Args) => R): ChainableFunction<T, Args, R, E>;
11
11
 
12
+ interface FixtureItem {
13
+ prop: string;
14
+ value: any;
15
+ index: number;
16
+ /**
17
+ * Indicates whether the fixture is a function
18
+ */
19
+ isFn: boolean;
20
+ /**
21
+ * The dependencies(fixtures) of current fixture function.
22
+ */
23
+ deps?: FixtureItem[];
24
+ }
25
+
12
26
  type RunMode = 'run' | 'skip' | 'only' | 'todo';
13
27
  type TaskState = RunMode | 'pass' | 'fail';
14
28
  interface TaskBase {
@@ -25,10 +39,18 @@ interface TaskBase {
25
39
  retry?: number;
26
40
  repeats?: number;
27
41
  }
28
- interface TaskMeta {
42
+ interface TaskPopulated extends TaskBase {
43
+ suite: Suite;
44
+ pending?: boolean;
45
+ result?: TaskResult;
46
+ fails?: boolean;
47
+ onFailed?: OnTestFailedHandler[];
48
+ /**
49
+ * Store promises (from async expects) to wait for them before finishing the test
50
+ */
51
+ promises?: Promise<any>[];
29
52
  }
30
- interface TaskCustom extends TaskBase {
31
- type: 'custom';
53
+ interface TaskMeta {
32
54
  }
33
55
  interface TaskResult {
34
56
  state: TaskState;
@@ -57,22 +79,17 @@ interface File extends Suite {
57
79
  collectDuration?: number;
58
80
  setupDuration?: number;
59
81
  }
60
- interface Test<ExtraContext = {}> extends TaskBase {
82
+ interface Test<ExtraContext = {}> extends TaskPopulated {
61
83
  type: 'test';
62
- suite: Suite;
63
- pending?: boolean;
64
- result?: TaskResult;
65
- fails?: boolean;
66
- context: TestContext & ExtraContext;
67
- onFailed?: OnTestFailedHandler[];
68
- /**
69
- * Store promises (from async expects) to wait for them before finishing the test
70
- */
71
- promises?: Promise<any>[];
84
+ context: TaskContext<Test> & ExtraContext & TestContext;
72
85
  }
73
- type Task = Test | Suite | TaskCustom | File;
86
+ interface Custom<ExtraContext = {}> extends TaskPopulated {
87
+ type: 'custom';
88
+ context: TaskContext<Custom> & ExtraContext & TestContext;
89
+ }
90
+ type Task = Test | Suite | Custom | File;
74
91
  type DoneCallback = (error?: any) => void;
75
- type TestFunction<ExtraContext = {}> = (context: TestContext & ExtraContext) => Awaitable<any> | void;
92
+ type TestFunction<ExtraContext = {}> = (context: ExtendedContext<Test> & ExtraContext) => Awaitable<any> | void;
76
93
  type ExtractEachCallbackArgs<T extends ReadonlyArray<any>> = {
77
94
  1: [T[0]];
78
95
  2: [T[0], T[1]];
@@ -125,10 +142,17 @@ interface TestOptions {
125
142
  */
126
143
  repeats?: number;
127
144
  }
128
- type TestAPI<ExtraContext = {}> = ChainableTestAPI<ExtraContext> & {
145
+ interface ExtendedAPI<ExtraContext> {
129
146
  each: TestEachFunction;
130
147
  skipIf(condition: any): ChainableTestAPI<ExtraContext>;
131
148
  runIf(condition: any): ChainableTestAPI<ExtraContext>;
149
+ }
150
+ type CustomAPI<ExtraContext = {}> = ChainableTestAPI<ExtraContext> & ExtendedAPI<ExtraContext> & {
151
+ extend<T extends Record<string, any> = {}>(fixtures: Fixtures<T, ExtraContext>): CustomAPI<{
152
+ [K in keyof T | keyof ExtraContext]: K extends keyof T ? T[K] : K extends keyof ExtraContext ? ExtraContext[K] : never;
153
+ }>;
154
+ };
155
+ type TestAPI<ExtraContext = {}> = ChainableTestAPI<ExtraContext> & ExtendedAPI<ExtraContext> & {
132
156
  extend<T extends Record<string, any> = {}>(fixtures: Fixtures<T, ExtraContext>): TestAPI<{
133
157
  [K in keyof T | keyof ExtraContext]: K extends keyof T ? T[K] : K extends keyof ExtraContext ? ExtraContext[K] : never;
134
158
  }>;
@@ -161,8 +185,20 @@ type HookCleanupCallback = (() => Awaitable<unknown>) | void;
161
185
  interface SuiteHooks<ExtraContext = {}> {
162
186
  beforeAll: HookListener<[Readonly<Suite | File>], HookCleanupCallback>[];
163
187
  afterAll: HookListener<[Readonly<Suite | File>]>[];
164
- beforeEach: HookListener<[TestContext & ExtraContext, Readonly<Suite>], HookCleanupCallback>[];
165
- afterEach: HookListener<[TestContext & ExtraContext, Readonly<Suite>]>[];
188
+ beforeEach: HookListener<[ExtendedContext<Test | Custom> & ExtraContext, Readonly<Suite>], HookCleanupCallback>[];
189
+ afterEach: HookListener<[ExtendedContext<Test | Custom> & ExtraContext, Readonly<Suite>]>[];
190
+ }
191
+ interface TaskCustomOptions extends TestOptions {
192
+ concurrent?: boolean;
193
+ sequential?: boolean;
194
+ skip?: boolean;
195
+ only?: boolean;
196
+ todo?: boolean;
197
+ fails?: boolean;
198
+ each?: boolean;
199
+ meta?: Record<string, unknown>;
200
+ fixtures?: FixtureItem[];
201
+ handler?: (context: TaskContext<Custom>) => Awaitable<void>;
166
202
  }
167
203
  interface SuiteCollector<ExtraContext = {}> {
168
204
  readonly name: string;
@@ -170,8 +206,8 @@ interface SuiteCollector<ExtraContext = {}> {
170
206
  options?: TestOptions;
171
207
  type: 'collector';
172
208
  test: TestAPI<ExtraContext>;
173
- tasks: (Suite | TaskCustom | Test | SuiteCollector<ExtraContext>)[];
174
- custom: (name: string) => TaskCustom;
209
+ tasks: (Suite | Custom<ExtraContext> | Test<ExtraContext> | SuiteCollector<ExtraContext>)[];
210
+ task: (name: string, options?: TaskCustomOptions) => Custom<ExtraContext>;
175
211
  collect: (file?: File) => Promise<Suite>;
176
212
  clear: () => void;
177
213
  on: <T extends keyof SuiteHooks<ExtraContext>>(name: T, ...fn: SuiteHooks<ExtraContext>[T]) => void;
@@ -182,16 +218,12 @@ interface RuntimeContext {
182
218
  currentSuite: SuiteCollector | null;
183
219
  }
184
220
  interface TestContext {
185
- /**
186
- * Metadata of the current test
187
- *
188
- * @deprecated Use `task` instead
189
- */
190
- meta: Readonly<Test>;
221
+ }
222
+ interface TaskContext<Task extends Custom | Test = Custom | Test> {
191
223
  /**
192
224
  * Metadata of the current test
193
225
  */
194
- task: Readonly<Test>;
226
+ task: Readonly<Task>;
195
227
  /**
196
228
  * Extract hooks on test failed
197
229
  */
@@ -201,8 +233,9 @@ interface TestContext {
201
233
  */
202
234
  skip: () => void;
203
235
  }
236
+ type ExtendedContext<T extends Custom | Test> = TaskContext<T> & TestContext;
204
237
  type OnTestFailedHandler = (result: TaskResult) => Awaitable<void>;
205
238
  type SequenceHooks = 'stack' | 'list' | 'parallel';
206
239
  type SequenceSetupFiles = 'list' | 'parallel';
207
240
 
208
- export { ChainableFunction as C, DoneCallback as D, File as F, HookListener as H, InferFixturesTypes as I, OnTestFailedHandler as O, RunMode as R, Suite as S, Task as T, Test as a, TaskCustom as b, createChainable as c, SuiteAPI as d, TestAPI as e, SuiteCollector as f, SuiteHooks as g, TaskState as h, TaskBase as i, TaskMeta as j, TaskResult as k, TaskResultPack as l, TestFunction as m, TestOptions as n, Fixture as o, Fixtures as p, HookCleanupCallback as q, SuiteFactory as r, RuntimeContext as s, TestContext as t, SequenceHooks as u, SequenceSetupFiles as v };
241
+ export { Custom as C, DoneCallback as D, ExtendedContext as E, File as F, HookListener as H, InferFixturesTypes as I, OnTestFailedHandler as O, RunMode as R, Suite as S, Task as T, Test as a, ChainableFunction as b, createChainable as c, SuiteAPI as d, TestAPI as e, SuiteCollector as f, CustomAPI as g, SuiteHooks as h, TaskState as i, TaskBase as j, TaskPopulated as k, TaskMeta as l, TaskResult as m, TaskResultPack as n, TestFunction as o, TestOptions as p, Fixture as q, Fixtures as r, HookCleanupCallback as s, TaskCustomOptions as t, SuiteFactory as u, RuntimeContext as v, TestContext as w, TaskContext as x, SequenceHooks as y, SequenceSetupFiles as z };
package/dist/types.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { u as SequenceHooks, v as SequenceSetupFiles, F as File, a as Test, S as Suite, l as TaskResultPack, t as TestContext } from './tasks-d7d578d8.js';
2
- export { D as DoneCallback, o as Fixture, p as Fixtures, q as HookCleanupCallback, H as HookListener, I as InferFixturesTypes, O as OnTestFailedHandler, R as RunMode, s as RuntimeContext, d as SuiteAPI, f as SuiteCollector, r as SuiteFactory, g as SuiteHooks, T as Task, i as TaskBase, b as TaskCustom, j as TaskMeta, k as TaskResult, h as TaskState, e as TestAPI, m as TestFunction, n as TestOptions } from './tasks-d7d578d8.js';
1
+ import { y as SequenceHooks, z as SequenceSetupFiles, F as File, k as TaskPopulated, S as Suite, n as TaskResultPack, a as Test, C as Custom, x as TaskContext, E as ExtendedContext } from './tasks-b31a73cb.js';
2
+ export { g as CustomAPI, D as DoneCallback, q as Fixture, r as Fixtures, s as HookCleanupCallback, H as HookListener, I as InferFixturesTypes, O as OnTestFailedHandler, R as RunMode, v as RuntimeContext, d as SuiteAPI, f as SuiteCollector, u as SuiteFactory, h as SuiteHooks, T as Task, j as TaskBase, t as TaskCustomOptions, l as TaskMeta, m as TaskResult, i as TaskState, e as TestAPI, w as TestContext, o as TestFunction, p as TestOptions } from './tasks-b31a73cb.js';
3
3
  import '@vitest/utils';
4
4
 
5
5
  /**
@@ -84,28 +84,28 @@ interface VitestRunner {
84
84
  /**
85
85
  * Called when test runner should cancel next test runs.
86
86
  * Runner should listen for this method and mark tests and suites as skipped in
87
- * "onBeforeRunSuite" and "onBeforeRunTest" when called.
87
+ * "onBeforeRunSuite" and "onBeforeRunTask" when called.
88
88
  */
89
89
  onCancel?(reason: CancelReason): unknown;
90
90
  /**
91
91
  * Called before running a single test. Doesn't have "result" yet.
92
92
  */
93
- onBeforeRunTest?(test: Test): unknown;
93
+ onBeforeRunTask?(test: TaskPopulated): unknown;
94
94
  /**
95
95
  * Called before actually running the test function. Already has "result" with "state" and "startTime".
96
96
  */
97
- onBeforeTryTest?(test: Test, options: {
97
+ onBeforeTryTask?(test: TaskPopulated, options: {
98
98
  retry: number;
99
99
  repeats: number;
100
100
  }): unknown;
101
101
  /**
102
102
  * Called after result and state are set.
103
103
  */
104
- onAfterRunTest?(test: Test): unknown;
104
+ onAfterRunTask?(test: TaskPopulated): unknown;
105
105
  /**
106
106
  * Called right after running the test function. Doesn't have new state yet. Will not be called, if the test function throws.
107
107
  */
108
- onAfterTryTest?(test: Test, options: {
108
+ onAfterTryTask?(test: TaskPopulated, options: {
109
109
  retry: number;
110
110
  repeats: number;
111
111
  }): unknown;
@@ -126,7 +126,7 @@ interface VitestRunner {
126
126
  * If defined, will be called instead of usual Vitest handling. Useful, if you have your custom test function.
127
127
  * "before" and "after" hooks will not be ignored.
128
128
  */
129
- runTest?(test: Test): Promise<void>;
129
+ runTask?(test: TaskPopulated): Promise<void>;
130
130
  /**
131
131
  * Called, when a task is updated. The same as "onTaskUpdate" in a reporter, but this is running in the same thread as tests.
132
132
  */
@@ -134,16 +134,20 @@ interface VitestRunner {
134
134
  /**
135
135
  * Called before running all tests in collected paths.
136
136
  */
137
- onBeforeRun?(files: File[]): unknown;
137
+ onBeforeRunFiles?(files: File[]): unknown;
138
138
  /**
139
139
  * Called right after running all tests in collected paths.
140
140
  */
141
- onAfterRun?(files: File[]): unknown;
141
+ onAfterRunFiles?(files: File[]): unknown;
142
142
  /**
143
143
  * Called when new context for a test is defined. Useful, if you want to add custom properties to the context.
144
144
  * If you only want to define custom context, consider using "beforeAll" in "setupFiles" instead.
145
+ *
146
+ * This method is called for both "test" and "custom" handlers.
147
+ *
148
+ * @see https://vitest.dev/advanced/runner.html#your-task-function
145
149
  */
146
- extendTestContext?(context: TestContext): TestContext;
150
+ extendTaskContext?<T extends Test | Custom>(context: TaskContext<T>): ExtendedContext<T>;
147
151
  /**
148
152
  * Called, when files are imported. Can be called in two situations: when collecting tests and when importing setup files.
149
153
  */
@@ -154,4 +158,4 @@ interface VitestRunner {
154
158
  config: VitestRunnerConfig;
155
159
  }
156
160
 
157
- export { CancelReason, File, SequenceHooks, SequenceSetupFiles, Suite, TaskResultPack, Test, TestContext, VitestRunner, VitestRunnerConfig, VitestRunnerConstructor, VitestRunnerImportSource };
161
+ export { CancelReason, Custom, ExtendedContext, File, SequenceHooks, SequenceSetupFiles, Suite, TaskContext, TaskPopulated, TaskResultPack, Test, VitestRunner, VitestRunnerConfig, VitestRunnerConstructor, VitestRunnerImportSource };
package/dist/utils.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { S as Suite, T as Task, a as Test, b as TaskCustom } from './tasks-d7d578d8.js';
2
- export { C as ChainableFunction, c as createChainable } from './tasks-d7d578d8.js';
1
+ import { S as Suite, T as Task, a as Test, C as Custom } from './tasks-b31a73cb.js';
2
+ export { b as ChainableFunction, c as createChainable } from './tasks-b31a73cb.js';
3
3
  import { Arrayable } from '@vitest/utils';
4
4
 
5
5
  /**
@@ -15,7 +15,7 @@ declare function calculateSuiteHash(parent: Suite): void;
15
15
  */
16
16
  declare function partitionSuiteChildren(suite: Suite): Task[][];
17
17
 
18
- declare function getTests(suite: Arrayable<Task>): (Test | TaskCustom)[];
18
+ declare function getTests(suite: Arrayable<Task>): (Test | Custom)[];
19
19
  declare function getTasks(tasks?: Arrayable<Task>): Task[];
20
20
  declare function getSuites(suite: Arrayable<Task>): Suite[];
21
21
  declare function hasTests(suite: Arrayable<Suite>): boolean;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vitest/runner",
3
3
  "type": "module",
4
- "version": "0.34.7",
4
+ "version": "1.0.0-beta.1",
5
5
  "description": "Vitest test runner",
6
6
  "license": "MIT",
7
7
  "funding": "https://opencollective.com/vitest",
@@ -40,7 +40,7 @@
40
40
  "dependencies": {
41
41
  "p-limit": "^4.0.0",
42
42
  "pathe": "^1.1.1",
43
- "@vitest/utils": "0.34.7"
43
+ "@vitest/utils": "1.0.0-beta.1"
44
44
  },
45
45
  "scripts": {
46
46
  "build": "rimraf dist && rollup -c",