@vitest/runner 1.6.0 → 2.0.0-beta.2

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.
@@ -160,11 +160,13 @@ function hasFailed(suite) {
160
160
  function getNames(task) {
161
161
  const names = [task.name];
162
162
  let current = task;
163
- while ((current == null ? void 0 : current.suite) || (current == null ? void 0 : current.file)) {
164
- current = current.suite || current.file;
163
+ while (current == null ? void 0 : current.suite) {
164
+ current = current.suite;
165
165
  if (current == null ? void 0 : current.name)
166
166
  names.unshift(current.name);
167
167
  }
168
+ if (current !== task.file)
169
+ names.unshift(task.file.name);
168
170
  return names;
169
171
  }
170
172
 
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, h as SuiteHooks, O as OnTestFailedHandler, i as OnTestFinishedHandler, a as Test, C as Custom, S as Suite } from './tasks-K5XERDtv.js';
4
- export { D as DoneCallback, E as ExtendedContext, t as Fixture, s as FixtureFn, r as FixtureOptions, u as Fixtures, v as HookCleanupCallback, H as HookListener, I as InferFixturesTypes, R as RunMode, y as RuntimeContext, B as SequenceHooks, G as SequenceSetupFiles, x as SuiteFactory, k as TaskBase, A as TaskContext, w as TaskCustomOptions, m as TaskMeta, l as TaskPopulated, n as TaskResult, o as TaskResultPack, j as TaskState, z as TestContext, p as TestFunction, q as TestOptions, U as Use } from './tasks-K5XERDtv.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, i as OnTestFinishedHandler, a as Test, C as Custom, S as Suite } from './tasks-Ck0GpLiZ.js';
4
+ export { D as DoneCallback, E as ExtendedContext, t as Fixture, s as FixtureFn, r as FixtureOptions, u as Fixtures, v as HookCleanupCallback, H as HookListener, I as InferFixturesTypes, R as RunMode, y as RuntimeContext, B as SequenceHooks, G as SequenceSetupFiles, x as SuiteFactory, k as TaskBase, A as TaskContext, w as TaskCustomOptions, m as TaskMeta, l as TaskPopulated, n as TaskResult, o as TaskResultPack, j as TaskState, z as TestContext, p as TestFunction, q as TestOptions, U as Use } from './tasks-Ck0GpLiZ.js';
5
5
  import { Awaitable } from '@vitest/utils';
6
6
  export { processError } from '@vitest/utils/error';
7
7
  import '@vitest/utils/diff';
package/dist/index.js CHANGED
@@ -271,9 +271,15 @@ function getTestFilepath() {
271
271
  function getRunner() {
272
272
  return runner;
273
273
  }
274
+ function createDefaultSuite(runner2) {
275
+ const config = runner2.config.sequence;
276
+ const api = config.shuffle ? suite.shuffle : suite;
277
+ return api("", { concurrent: config.concurrent }, () => {
278
+ });
279
+ }
274
280
  function clearCollectorContext(filepath, currentRunner) {
275
281
  if (!defaultSuite)
276
- defaultSuite = currentRunner.config.sequence.shuffle ? suite.shuffle("") : currentRunner.config.sequence.concurrent ? suite.concurrent("") : suite("");
282
+ defaultSuite = createDefaultSuite(currentRunner);
277
283
  runner = currentRunner;
278
284
  currentTestFilepath = filepath;
279
285
  collectorContext.tasks.length = 0;
@@ -331,6 +337,7 @@ function createSuiteCollector(name, factory = () => {
331
337
  fails: options.fails,
332
338
  context: void 0,
333
339
  type: "custom",
340
+ file: void 0,
334
341
  retry: options.retry ?? runner.config.retry,
335
342
  repeats: options.repeats,
336
343
  mode: options.only ? "only" : options.skip ? "skip" : options.todo ? "todo" : "run",
@@ -404,10 +411,10 @@ function createSuiteCollector(name, factory = () => {
404
411
  name,
405
412
  mode,
406
413
  each,
414
+ file: void 0,
407
415
  shuffle,
408
416
  tasks: [],
409
- meta: /* @__PURE__ */ Object.create(null),
410
- projectName: ""
417
+ meta: /* @__PURE__ */ Object.create(null)
411
418
  };
412
419
  if (runner && includeLocation && runner.config.includeTaskLocation) {
413
420
  const limit = Error.stackTraceLimit;
@@ -426,6 +433,8 @@ function createSuiteCollector(name, factory = () => {
426
433
  initSuite(false);
427
434
  }
428
435
  async function collect(file) {
436
+ if (!file)
437
+ throw new TypeError("File is required to collect tasks.");
429
438
  factoryQueue.length = 0;
430
439
  if (factory)
431
440
  await runWithSuite(collector, () => factory(test2));
@@ -436,8 +445,7 @@ function createSuiteCollector(name, factory = () => {
436
445
  suite2.tasks = allChildren;
437
446
  allChildren.forEach((task2) => {
438
447
  task2.suite = suite2;
439
- if (file)
440
- task2.file = file;
448
+ task2.file = file;
441
449
  });
442
450
  return suite2;
443
451
  }
@@ -617,8 +625,10 @@ async function collectTests(paths, runner) {
617
625
  filepath,
618
626
  tasks: [],
619
627
  meta: /* @__PURE__ */ Object.create(null),
620
- projectName: config.name
628
+ projectName: config.name,
629
+ file: void 0
621
630
  };
631
+ file.file = file;
622
632
  clearCollectorContext(filepath, runner);
623
633
  try {
624
634
  const setupStart = now$1();
@@ -627,20 +637,22 @@ async function collectTests(paths, runner) {
627
637
  file.setupDuration = collectStart - setupStart;
628
638
  await runner.importFile(filepath, "collect");
629
639
  const defaultTasks = await getDefaultSuite().collect(file);
630
- setHooks(file, getHooks(defaultTasks));
640
+ const fileHooks = createSuiteHooks();
641
+ mergeHooks(fileHooks, getHooks(defaultTasks));
631
642
  for (const c of [...defaultTasks.tasks, ...collectorContext.tasks]) {
632
- if (c.type === "test") {
633
- file.tasks.push(c);
634
- } else if (c.type === "custom") {
635
- file.tasks.push(c);
636
- } else if (c.type === "suite") {
643
+ if (c.type === "test" || c.type === "custom" || c.type === "suite") {
637
644
  file.tasks.push(c);
638
645
  } else if (c.type === "collector") {
639
646
  const suite = await c.collect(file);
640
- if (suite.name || suite.tasks.length)
647
+ if (suite.name || suite.tasks.length) {
648
+ mergeHooks(fileHooks, getHooks(suite));
641
649
  file.tasks.push(suite);
650
+ }
651
+ } else {
652
+ c;
642
653
  }
643
654
  }
655
+ setHooks(file, fileHooks);
644
656
  file.collectDuration = now$1() - collectStart;
645
657
  } catch (e) {
646
658
  const error = processError(e);
@@ -652,10 +664,22 @@ async function collectTests(paths, runner) {
652
664
  calculateSuiteHash(file);
653
665
  const hasOnlyTasks = someTasksAreOnly(file);
654
666
  interpretTaskModes(file, config.testNamePattern, hasOnlyTasks, false, config.allowOnly);
667
+ file.tasks.forEach((task) => {
668
+ var _a;
669
+ if (((_a = task.suite) == null ? void 0 : _a.id) === "")
670
+ delete task.suite;
671
+ });
655
672
  files.push(file);
656
673
  }
657
674
  return files;
658
675
  }
676
+ function mergeHooks(baseHooks, hooks) {
677
+ for (const _key in hooks) {
678
+ const key = _key;
679
+ baseHooks[key].push(...hooks[key]);
680
+ }
681
+ return baseHooks;
682
+ }
659
683
 
660
684
  const now = Date.now;
661
685
  function updateSuiteHookState(suite, name, state, runner) {
@@ -689,9 +713,10 @@ async function callTaskHooks(task, hooks, sequence) {
689
713
  async function callSuiteHook(suite, currentTask, name, runner, args) {
690
714
  const sequence = runner.config.sequence.hooks;
691
715
  const callbacks = [];
692
- if (name === "beforeEach" && suite.suite) {
716
+ const parentSuite = "filepath" in suite ? null : suite.suite || suite.file;
717
+ if (name === "beforeEach" && parentSuite) {
693
718
  callbacks.push(
694
- ...await callSuiteHook(suite.suite, currentTask, name, runner, args)
719
+ ...await callSuiteHook(parentSuite, currentTask, name, runner, args)
695
720
  );
696
721
  }
697
722
  updateSuiteHookState(currentTask, name, "run", runner);
@@ -703,9 +728,9 @@ async function callSuiteHook(suite, currentTask, name, runner, args) {
703
728
  callbacks.push(await hook(...args));
704
729
  }
705
730
  updateSuiteHookState(currentTask, name, "pass", runner);
706
- if (name === "afterEach" && suite.suite) {
731
+ if (name === "afterEach" && parentSuite) {
707
732
  callbacks.push(
708
- ...await callSuiteHook(suite.suite, currentTask, name, runner, args)
733
+ ...await callSuiteHook(parentSuite, currentTask, name, runner, args)
709
734
  );
710
735
  }
711
736
  return callbacks;
@@ -763,6 +788,7 @@ async function runTest(test, runner) {
763
788
  };
764
789
  updateTask(test, runner);
765
790
  setCurrentTest(test);
791
+ const suite = test.suite || test.file;
766
792
  const repeats = test.repeats ?? 0;
767
793
  for (let repeatCount = 0; repeatCount <= repeats; repeatCount++) {
768
794
  const retry = test.retry ?? 0;
@@ -771,7 +797,7 @@ async function runTest(test, runner) {
771
797
  try {
772
798
  await ((_c = runner.onBeforeTryTask) == null ? void 0 : _c.call(runner, test, { retry: retryCount, repeats: repeatCount }));
773
799
  test.result.repeatCount = repeatCount;
774
- beforeEachCleanups = await callSuiteHook(test.suite, test, "beforeEach", runner, [test.context, test.suite]);
800
+ beforeEachCleanups = await callSuiteHook(suite, test, "beforeEach", runner, [test.context, suite]);
775
801
  if (runner.runTask) {
776
802
  await runner.runTask(test);
777
803
  } else {
@@ -804,7 +830,7 @@ async function runTest(test, runner) {
804
830
  return;
805
831
  }
806
832
  try {
807
- await callSuiteHook(test.suite, test, "afterEach", runner, [test.context, test.suite]);
833
+ await callSuiteHook(suite, test, "afterEach", runner, [test.context, suite]);
808
834
  await callCleanupHooks(beforeEachCleanups);
809
835
  await callFixtureCleanup(test.context);
810
836
  } catch (e) {
@@ -31,7 +31,6 @@ interface TaskBase {
31
31
  concurrent?: boolean;
32
32
  shuffle?: boolean;
33
33
  suite?: Suite;
34
- file?: File;
35
34
  result?: TaskResult;
36
35
  retry?: number;
37
36
  repeats?: number;
@@ -41,7 +40,7 @@ interface TaskBase {
41
40
  };
42
41
  }
43
42
  interface TaskPopulated extends TaskBase {
44
- suite: Suite;
43
+ file: File;
45
44
  pending?: boolean;
46
45
  result?: TaskResult;
47
46
  fails?: boolean;
@@ -67,13 +66,13 @@ interface TaskResult {
67
66
  }
68
67
  type TaskResultPack = [id: string, result: TaskResult | undefined, meta: TaskMeta];
69
68
  interface Suite extends TaskBase {
69
+ file: File;
70
70
  type: 'suite';
71
71
  tasks: Task[];
72
- filepath?: string;
73
- projectName: string;
74
72
  }
75
73
  interface File extends Suite {
76
74
  filepath: string;
75
+ projectName: string;
77
76
  collectDuration?: number;
78
77
  setupDuration?: number;
79
78
  }
@@ -242,7 +241,7 @@ interface SuiteCollector<ExtraContext = {}> {
242
241
  test: TestAPI<ExtraContext>;
243
242
  tasks: (Suite | Custom<ExtraContext> | Test<ExtraContext> | SuiteCollector<ExtraContext>)[];
244
243
  task: (name: string, options?: TaskCustomOptions) => Custom<ExtraContext>;
245
- collect: (file?: File) => Promise<Suite>;
244
+ collect: (file: File) => Promise<Suite>;
246
245
  clear: () => void;
247
246
  on: <T extends keyof SuiteHooks<ExtraContext>>(name: T, ...fn: SuiteHooks<ExtraContext>[T]) => void;
248
247
  }
package/dist/types.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { B as SequenceHooks, G as SequenceSetupFiles, F as File, T as Task, S as Suite, o as TaskResultPack, a as Test, C as Custom, A as TaskContext, E as ExtendedContext } from './tasks-K5XERDtv.js';
2
- export { g as CustomAPI, D as DoneCallback, t as Fixture, s as FixtureFn, r as FixtureOptions, u as Fixtures, v as HookCleanupCallback, H as HookListener, I as InferFixturesTypes, O as OnTestFailedHandler, i as OnTestFinishedHandler, R as RunMode, y as RuntimeContext, d as SuiteAPI, f as SuiteCollector, x as SuiteFactory, h as SuiteHooks, k as TaskBase, w as TaskCustomOptions, m as TaskMeta, l as TaskPopulated, n as TaskResult, j as TaskState, e as TestAPI, z as TestContext, p as TestFunction, q as TestOptions, U as Use } from './tasks-K5XERDtv.js';
1
+ import { B as SequenceHooks, G as SequenceSetupFiles, F as File, T as Task, S as Suite, o as TaskResultPack, a as Test, C as Custom, A as TaskContext, E as ExtendedContext } from './tasks-Ck0GpLiZ.js';
2
+ export { g as CustomAPI, D as DoneCallback, t as Fixture, s as FixtureFn, r as FixtureOptions, u as Fixtures, v as HookCleanupCallback, H as HookListener, I as InferFixturesTypes, O as OnTestFailedHandler, i as OnTestFinishedHandler, R as RunMode, y as RuntimeContext, d as SuiteAPI, f as SuiteCollector, x as SuiteFactory, h as SuiteHooks, k as TaskBase, w as TaskCustomOptions, m as TaskMeta, l as TaskPopulated, n as TaskResult, j as TaskState, e as TestAPI, z as TestContext, p as TestFunction, q as TestOptions, U as Use } from './tasks-Ck0GpLiZ.js';
3
3
  import { DiffOptions } from '@vitest/utils/diff';
4
4
  import '@vitest/utils';
5
5
 
package/dist/utils.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { S as Suite, T as Task, a as Test, C as Custom } from './tasks-K5XERDtv.js';
2
- export { b as ChainableFunction, c as createChainable } from './tasks-K5XERDtv.js';
1
+ import { S as Suite, T as Task, a as Test, C as Custom } from './tasks-Ck0GpLiZ.js';
2
+ export { b as ChainableFunction, c as createChainable } from './tasks-Ck0GpLiZ.js';
3
3
  import { Arrayable } from '@vitest/utils';
4
4
 
5
5
  /**
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vitest/runner",
3
3
  "type": "module",
4
- "version": "1.6.0",
4
+ "version": "2.0.0-beta.2",
5
5
  "description": "Vitest test runner",
6
6
  "license": "MIT",
7
7
  "funding": "https://opencollective.com/vitest",
@@ -39,8 +39,8 @@
39
39
  ],
40
40
  "dependencies": {
41
41
  "p-limit": "^5.0.0",
42
- "pathe": "^1.1.1",
43
- "@vitest/utils": "1.6.0"
42
+ "pathe": "^1.1.2",
43
+ "@vitest/utils": "2.0.0-beta.2"
44
44
  },
45
45
  "scripts": {
46
46
  "build": "rimraf dist && rollup -c",