@vitest/runner 2.0.0-beta.2 → 2.0.0-beta.3

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.
@@ -1,4 +1,5 @@
1
1
  import { processError } from '@vitest/utils/error';
2
+ import { relative } from 'pathe';
2
3
  import { toArray } from '@vitest/utils';
3
4
 
4
5
  function partitionSuiteChildren(suite) {
@@ -91,6 +92,22 @@ function calculateSuiteHash(parent) {
91
92
  calculateSuiteHash(t);
92
93
  });
93
94
  }
95
+ function createFileTask(filepath, root, projectName) {
96
+ const path = relative(root, filepath);
97
+ const file = {
98
+ id: generateHash(`${path}${projectName || ""}`),
99
+ name: path,
100
+ type: "suite",
101
+ mode: "run",
102
+ filepath,
103
+ tasks: [],
104
+ meta: /* @__PURE__ */ Object.create(null),
105
+ projectName,
106
+ file: void 0
107
+ };
108
+ file.file = file;
109
+ return file;
110
+ }
94
111
 
95
112
  function createChainable(keys, fn) {
96
113
  function create(context) {
@@ -170,4 +187,4 @@ function getNames(task) {
170
187
  return names;
171
188
  }
172
189
 
173
- export { getTests as a, getTasks as b, calculateSuiteHash as c, getSuites as d, hasFailed as e, getNames as f, generateHash as g, hasTests as h, interpretTaskModes as i, createChainable as j, partitionSuiteChildren as p, someTasksAreOnly as s };
190
+ export { createFileTask as a, getTests as b, calculateSuiteHash as c, getTasks as d, getSuites as e, hasFailed as f, generateHash as g, hasTests as h, interpretTaskModes as i, getNames as j, createChainable as k, partitionSuiteChildren as p, someTasksAreOnly as s };
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-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';
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-DqMVjp0M.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-DqMVjp0M.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
@@ -2,9 +2,9 @@ import limit from 'p-limit';
2
2
  import { getSafeTimers, isObject, createDefer, format, objDisplay, objectAttr, toArray, shuffle } from '@vitest/utils';
3
3
  import { processError } from '@vitest/utils/error';
4
4
  export { processError } from '@vitest/utils/error';
5
- import { j as createChainable, g as generateHash, c as calculateSuiteHash, s as someTasksAreOnly, i as interpretTaskModes, p as partitionSuiteChildren, h as hasTests, e as hasFailed } from './chunk-tasks.js';
6
- import { relative } from 'pathe';
5
+ import { k as createChainable, a as createFileTask, c as calculateSuiteHash, s as someTasksAreOnly, i as interpretTaskModes, p as partitionSuiteChildren, h as hasTests, f as hasFailed } from './chunk-tasks.js';
7
6
  import { parseSingleStack } from '@vitest/utils/source-map';
7
+ import 'pathe';
8
8
 
9
9
  const fnMap = /* @__PURE__ */ new WeakMap();
10
10
  const fixtureMap = /* @__PURE__ */ new WeakMap();
@@ -212,7 +212,7 @@ function getUsedProps(fn) {
212
212
  throw new Error(`The first argument inside a fixture must use object destructuring pattern, e.g. ({ test } => {}). Instead, received "${first}".`);
213
213
  const _first = first.slice(1, -1).replace(/\s/g, "");
214
214
  const props = splitByComma(_first).map((prop) => {
215
- return prop.replace(/\:.*|\=.*/g, "");
215
+ return prop.replace(/:.*|=.*/g, "");
216
216
  });
217
217
  const last = props.at(-1);
218
218
  if (last && last.startsWith("..."))
@@ -414,7 +414,8 @@ function createSuiteCollector(name, factory = () => {
414
414
  file: void 0,
415
415
  shuffle,
416
416
  tasks: [],
417
- meta: /* @__PURE__ */ Object.create(null)
417
+ meta: /* @__PURE__ */ Object.create(null),
418
+ concurrent: suiteOptions == null ? void 0 : suiteOptions.concurrent
418
419
  };
419
420
  if (runner && includeLocation && runner.config.includeTaskLocation) {
420
421
  const limit = Error.stackTraceLimit;
@@ -557,7 +558,7 @@ function formatTitle(template, items, idx) {
557
558
  let formatted = format(template, ...items.slice(0, count));
558
559
  if (isObject(items[0])) {
559
560
  formatted = formatted.replace(
560
- /\$([$\w_.]+)/g,
561
+ /\$([$\w.]+)/g,
561
562
  // https://github.com/chaijs/chai/pull/1490
562
563
  (_, key) => {
563
564
  var _a, _b;
@@ -613,22 +614,12 @@ async function runSetupFiles(config, runner) {
613
614
 
614
615
  const now$1 = Date.now;
615
616
  async function collectTests(paths, runner) {
617
+ var _a;
616
618
  const files = [];
617
619
  const config = runner.config;
618
620
  for (const filepath of paths) {
619
- const path = relative(config.root, filepath);
620
- const file = {
621
- id: generateHash(`${path}${config.name || ""}`),
622
- name: path,
623
- type: "suite",
624
- mode: "run",
625
- filepath,
626
- tasks: [],
627
- meta: /* @__PURE__ */ Object.create(null),
628
- projectName: config.name,
629
- file: void 0
630
- };
631
- file.file = file;
621
+ const file = createFileTask(filepath, config.root, config.name);
622
+ (_a = runner.onCollectStart) == null ? void 0 : _a.call(runner, file);
632
623
  clearCollectorContext(filepath, runner);
633
624
  try {
634
625
  const setupStart = now$1();
@@ -665,8 +656,8 @@ async function collectTests(paths, runner) {
665
656
  const hasOnlyTasks = someTasksAreOnly(file);
666
657
  interpretTaskModes(file, config.testNamePattern, hasOnlyTasks, false, config.allowOnly);
667
658
  file.tasks.forEach((task) => {
668
- var _a;
669
- if (((_a = task.suite) == null ? void 0 : _a.id) === "")
659
+ var _a2;
660
+ if (((_a2 = task.suite) == null ? void 0 : _a2.id) === "")
670
661
  delete task.suite;
671
662
  });
672
663
  files.push(file);
@@ -921,8 +912,7 @@ async function runSuite(suite, runner) {
921
912
  } else {
922
913
  for (let tasksGroup of partitionSuiteChildren(suite)) {
923
914
  if (tasksGroup[0].concurrent === true) {
924
- const mutex = limit(runner.config.maxConcurrency);
925
- await Promise.all(tasksGroup.map((c) => mutex(() => runSuiteChild(c, runner))));
915
+ await Promise.all(tasksGroup.map((c) => runSuiteChild(c, runner)));
926
916
  } else {
927
917
  const { sequence } = runner.config;
928
918
  if (sequence.shuffle || suite.shuffle) {
@@ -963,14 +953,16 @@ async function runSuite(suite, runner) {
963
953
  await ((_d = runner.onAfterRunSuite) == null ? void 0 : _d.call(runner, suite));
964
954
  }
965
955
  }
956
+ let limitMaxConcurrency;
966
957
  async function runSuiteChild(c, runner) {
967
958
  if (c.type === "test" || c.type === "custom")
968
- return runTest(c, runner);
959
+ return limitMaxConcurrency(() => runTest(c, runner));
969
960
  else if (c.type === "suite")
970
961
  return runSuite(c, runner);
971
962
  }
972
963
  async function runFiles(files, runner) {
973
964
  var _a, _b;
965
+ limitMaxConcurrency ?? (limitMaxConcurrency = limit(runner.config.maxConcurrency));
974
966
  for (const file of files) {
975
967
  if (!file.tasks.length && !runner.config.passWithNoTests) {
976
968
  if (!((_b = (_a = file.result) == null ? void 0 : _a.errors) == null ? void 0 : _b.length)) {
@@ -145,7 +145,7 @@ interface TestOptions {
145
145
  */
146
146
  repeats?: number;
147
147
  /**
148
- * Whether tests run concurrently.
148
+ * Whether suites and tests run concurrently.
149
149
  * Tests inherit `concurrent` from `describe()` and nested `describe()` will inherit from parent's `concurrent`.
150
150
  */
151
151
  concurrent?: boolean;
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-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';
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-DqMVjp0M.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-DqMVjp0M.js';
3
3
  import { DiffOptions } from '@vitest/utils/diff';
4
4
  import '@vitest/utils';
5
5
 
@@ -37,6 +37,10 @@ interface VitestRunner {
37
37
  * First thing that's getting called before actually collecting and running tests.
38
38
  */
39
39
  onBeforeCollect?: (paths: string[]) => unknown;
40
+ /**
41
+ * Called after the file task was created but not collected yet.
42
+ */
43
+ onCollectStart?: (file: File) => unknown;
40
44
  /**
41
45
  * Called after collecting tests and before "onBeforeRun".
42
46
  */
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-Ck0GpLiZ.js';
2
- export { b as ChainableFunction, c as createChainable } from './tasks-Ck0GpLiZ.js';
1
+ import { S as Suite, F as File, T as Task, a as Test, C as Custom } from './tasks-DqMVjp0M.js';
2
+ export { b as ChainableFunction, c as createChainable } from './tasks-DqMVjp0M.js';
3
3
  import { Arrayable } from '@vitest/utils';
4
4
 
5
5
  /**
@@ -9,6 +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): File;
12
13
 
13
14
  /**
14
15
  * Partition in tasks groups by consecutive concurrent
@@ -22,4 +23,4 @@ declare function hasTests(suite: Arrayable<Suite>): boolean;
22
23
  declare function hasFailed(suite: Arrayable<Task>): boolean;
23
24
  declare function getNames(task: Task): string[];
24
25
 
25
- export { calculateSuiteHash, generateHash, getNames, getSuites, getTasks, getTests, hasFailed, hasTests, interpretTaskModes, partitionSuiteChildren, someTasksAreOnly };
26
+ export { calculateSuiteHash, createFileTask, generateHash, getNames, getSuites, getTasks, getTests, hasFailed, hasTests, interpretTaskModes, partitionSuiteChildren, someTasksAreOnly };
package/dist/utils.js CHANGED
@@ -1,3 +1,4 @@
1
- export { c as calculateSuiteHash, j as createChainable, g as generateHash, f as getNames, d as getSuites, b as getTasks, a as getTests, e as hasFailed, h as hasTests, i as interpretTaskModes, p as partitionSuiteChildren, s as someTasksAreOnly } from './chunk-tasks.js';
1
+ export { c as calculateSuiteHash, k as createChainable, a as createFileTask, g as generateHash, j as getNames, e as getSuites, d as getTasks, b as getTests, f as hasFailed, h as hasTests, i as interpretTaskModes, p as partitionSuiteChildren, s as someTasksAreOnly } from './chunk-tasks.js';
2
2
  import '@vitest/utils/error';
3
+ import 'pathe';
3
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.0.0-beta.2",
4
+ "version": "2.0.0-beta.3",
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": "^5.0.0",
42
42
  "pathe": "^1.1.2",
43
- "@vitest/utils": "2.0.0-beta.2"
43
+ "@vitest/utils": "2.0.0-beta.3"
44
44
  },
45
45
  "scripts": {
46
46
  "build": "rimraf dist && rollup -c",