@vitest/runner 2.0.0-beta.12 → 2.0.0-beta.13

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.
@@ -19,6 +19,33 @@ function partitionSuiteChildren(suite) {
19
19
  return tasksGroups;
20
20
  }
21
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
+ };
47
+ }
48
+
22
49
  function interpretTaskModes(suite, namePattern, onlyMode, parentIsOnly, allowOnly) {
23
50
  const suiteIsOnly = parentIsOnly || suite.mode === "only";
24
51
  suite.tasks.forEach((t) => {
@@ -106,7 +133,7 @@ function calculateSuiteHash(parent) {
106
133
  }
107
134
  });
108
135
  }
109
- function createFileTask(filepath, root, projectName) {
136
+ function createFileTask(filepath, root, projectName, pool) {
110
137
  const path = relative(root, filepath);
111
138
  const file = {
112
139
  id: generateHash(`${path}${projectName || ""}`),
@@ -117,7 +144,8 @@ function createFileTask(filepath, root, projectName) {
117
144
  tasks: [],
118
145
  meta: /* @__PURE__ */ Object.create(null),
119
146
  projectName,
120
- file: void 0
147
+ file: void 0,
148
+ pool
121
149
  };
122
150
  file.file = file;
123
151
  return file;
@@ -212,4 +240,4 @@ function getNames(task) {
212
240
  return names;
213
241
  }
214
242
 
215
- export { createFileTask as a, isAtomTest as b, calculateSuiteHash as c, getTests as d, getTasks as e, getSuites as f, generateHash as g, hasTests as h, interpretTaskModes as i, hasFailed as j, getNames as k, createChainable as l, partitionSuiteChildren as p, someTasksAreOnly as s };
243
+ export { createFileTask as a, isAtomTest as b, calculateSuiteHash as c, getTests as d, getTasks as e, getSuites as f, generateHash as g, hasTests as h, interpretTaskModes as i, hasFailed as j, getNames as k, createChainable as l, limitConcurrency as m, partitionSuiteChildren as p, someTasksAreOnly as s };
package/dist/index.d.ts CHANGED
@@ -1,13 +1,14 @@
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-BP89OzIP.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-BP89OzIP.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-UPEJyRVL.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-UPEJyRVL.js';
5
5
  import { Awaitable } from '@vitest/utils';
6
6
  export { processError } from '@vitest/utils/error';
7
7
  import '@vitest/utils/diff';
8
8
 
9
9
  declare function updateTask(task: Task, runner: VitestRunner): void;
10
10
  declare function startTests(paths: string[], runner: VitestRunner): Promise<File[]>;
11
+ declare function publicCollect(paths: string[], runner: VitestRunner): Promise<File[]>;
11
12
 
12
13
  declare const suite: SuiteAPI;
13
14
  declare const test: TestAPI;
@@ -30,4 +31,4 @@ declare function getHooks(key: Suite): SuiteHooks;
30
31
 
31
32
  declare function getCurrentTest<T extends Test | Custom | undefined>(): T;
32
33
 
33
- export { Custom, CustomAPI, File, OnTestFailedHandler, OnTestFinishedHandler, Suite, SuiteAPI, SuiteCollector, SuiteHooks, Task, Test, TestAPI, VitestRunner, afterAll, afterEach, beforeAll, beforeEach, createTaskCollector, describe, getCurrentSuite, getCurrentTest, getFn, getHooks, it, onTestFailed, onTestFinished, setFn, setHooks, startTests, suite, test, updateTask };
34
+ export { Custom, CustomAPI, File, OnTestFailedHandler, OnTestFinishedHandler, Suite, SuiteAPI, SuiteCollector, SuiteHooks, Task, 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,8 +1,7 @@
1
- import limit from 'p-limit';
2
1
  import { getSafeTimers, isObject, createDefer, isNegativeNaN, format, objDisplay, objectAttr, toArray, shuffle } from '@vitest/utils';
3
2
  import { processError } from '@vitest/utils/error';
4
3
  export { processError } from '@vitest/utils/error';
5
- import { l as createChainable, a as createFileTask, c as calculateSuiteHash, s as someTasksAreOnly, i as interpretTaskModes, p as partitionSuiteChildren, h as hasTests, j as hasFailed } from './chunk-tasks.js';
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';
6
5
  import { parseSingleStack } from '@vitest/utils/source-map';
7
6
  import 'pathe';
8
7
 
@@ -733,7 +732,7 @@ async function collectTests(paths, runner) {
733
732
  const files = [];
734
733
  const config = runner.config;
735
734
  for (const filepath of paths) {
736
- const file = createFileTask(filepath, config.root, config.name);
735
+ const file = createFileTask(filepath, config.root, config.name, runner.pool);
737
736
  (_a = runner.onCollectStart) == null ? void 0 : _a.call(runner, file);
738
737
  clearCollectorContext(filepath, runner);
739
738
  try {
@@ -1137,7 +1136,7 @@ async function runSuiteChild(c, runner) {
1137
1136
  }
1138
1137
  async function runFiles(files, runner) {
1139
1138
  var _a, _b;
1140
- limitMaxConcurrency ?? (limitMaxConcurrency = limit(runner.config.maxConcurrency));
1139
+ limitMaxConcurrency ?? (limitMaxConcurrency = limitConcurrency(runner.config.maxConcurrency));
1141
1140
  for (const file of files) {
1142
1141
  if (!file.tasks.length && !runner.config.passWithNoTests) {
1143
1142
  if (!((_b = (_a = file.result) == null ? void 0 : _a.errors) == null ? void 0 : _b.length)) {
@@ -1164,6 +1163,13 @@ async function startTests(paths, runner) {
1164
1163
  await sendTasksUpdate(runner);
1165
1164
  return files;
1166
1165
  }
1166
+ async function publicCollect(paths, runner) {
1167
+ var _a, _b;
1168
+ await ((_a = runner.onBeforeCollect) == null ? void 0 : _a.call(runner, paths));
1169
+ const files = await collectTests(paths, runner);
1170
+ await ((_b = runner.onCollected) == null ? void 0 : _b.call(runner, files));
1171
+ return files;
1172
+ }
1167
1173
 
1168
1174
  function getDefaultHookTimeout() {
1169
1175
  return getRunner().config.hookTimeout;
@@ -1216,4 +1222,4 @@ function createTestHook(name, handler) {
1216
1222
  };
1217
1223
  }
1218
1224
 
1219
- export { afterAll, afterEach, beforeAll, beforeEach, createTaskCollector, describe, getCurrentSuite, getCurrentTest, getFn, getHooks, it, onTestFailed, onTestFinished, setFn, setHooks, startTests, suite, test, updateTask };
1225
+ export { afterAll, afterEach, beforeAll, beforeEach, publicCollect as collectTests, createTaskCollector, describe, getCurrentSuite, getCurrentTest, getFn, getHooks, it, onTestFailed, onTestFinished, setFn, setHooks, startTests, suite, test, updateTask };
@@ -75,6 +75,7 @@ interface Suite extends TaskBase {
75
75
  tasks: Task[];
76
76
  }
77
77
  interface File extends Suite {
78
+ pool?: string;
78
79
  filepath: string;
79
80
  projectName: string | undefined;
80
81
  collectDuration?: number;
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-BP89OzIP.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-BP89OzIP.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-UPEJyRVL.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-UPEJyRVL.js';
3
3
  import { DiffOptions } from '@vitest/utils/diff';
4
4
  import '@vitest/utils';
5
5
 
@@ -124,6 +124,10 @@ interface VitestRunner {
124
124
  * Publicly available configuration.
125
125
  */
126
126
  config: VitestRunnerConfig;
127
+ /**
128
+ * The name of the current pool. Can affect how stack trace is inferred on the server side.
129
+ */
130
+ pool?: string;
127
131
  }
128
132
 
129
133
  export { type CancelReason, Custom, ExtendedContext, File, SequenceHooks, SequenceSetupFiles, Suite, Task, TaskContext, TaskResultPack, Test, type VitestRunner, type VitestRunnerConfig, type VitestRunnerConstructor, type VitestRunnerImportSource };
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-BP89OzIP.js';
2
- export { b as ChainableFunction, c as createChainable } from './tasks-BP89OzIP.js';
1
+ import { S as Suite, F as File, T as Task, a as Test, C as Custom } from './tasks-UPEJyRVL.js';
2
+ export { b as ChainableFunction, c as createChainable } from './tasks-UPEJyRVL.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): File;
12
+ declare function createFileTask(filepath: string, root: string, projectName: string, pool?: string): File;
13
13
 
14
14
  /**
15
15
  * Partition in tasks groups by consecutive concurrent
@@ -24,4 +24,9 @@ declare function hasTests(suite: Arrayable<Suite>): boolean;
24
24
  declare function hasFailed(suite: Arrayable<Task>): boolean;
25
25
  declare function getNames(task: Task): string[];
26
26
 
27
- export { calculateSuiteHash, createFileTask, generateHash, getNames, getSuites, getTasks, getTests, hasFailed, hasTests, interpretTaskModes, isAtomTest, partitionSuiteChildren, someTasksAreOnly };
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 };
package/dist/utils.js CHANGED
@@ -1,4 +1,4 @@
1
- export { c as calculateSuiteHash, l as createChainable, a as createFileTask, g as generateHash, k as getNames, f as getSuites, e as getTasks, d as getTests, j as hasFailed, h as hasTests, i as interpretTaskModes, b as isAtomTest, p as partitionSuiteChildren, s as someTasksAreOnly } from './chunk-tasks.js';
1
+ export { c as calculateSuiteHash, l as createChainable, a as createFileTask, g as generateHash, k as getNames, f as getSuites, e as getTasks, d as getTests, j as hasFailed, h as hasTests, i as interpretTaskModes, b as isAtomTest, m 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.0.0-beta.12",
4
+ "version": "2.0.0-beta.13",
5
5
  "description": "Vitest test runner",
6
6
  "license": "MIT",
7
7
  "funding": "https://opencollective.com/vitest",
@@ -38,9 +38,8 @@
38
38
  "dist"
39
39
  ],
40
40
  "dependencies": {
41
- "p-limit": "^5.0.0",
42
41
  "pathe": "^1.1.2",
43
- "@vitest/utils": "2.0.0-beta.12"
42
+ "@vitest/utils": "2.0.0-beta.13"
44
43
  },
45
44
  "scripts": {
46
45
  "build": "rimraf dist && rollup -c",