@vitest/runner 2.0.0-beta.9 → 2.0.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.
@@ -13,11 +13,39 @@ function partitionSuiteChildren(suite) {
13
13
  tasksGroup = [c];
14
14
  }
15
15
  }
16
- if (tasksGroup.length > 0)
16
+ if (tasksGroup.length > 0) {
17
17
  tasksGroups.push(tasksGroup);
18
+ }
18
19
  return tasksGroups;
19
20
  }
20
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
+
21
49
  function interpretTaskModes(suite, namePattern, onlyMode, parentIsOnly, allowOnly) {
22
50
  const suiteIsOnly = parentIsOnly || suite.mode === "only";
23
51
  suite.tasks.forEach((t) => {
@@ -36,39 +64,50 @@ function interpretTaskModes(suite, namePattern, onlyMode, parentIsOnly, allowOnl
36
64
  }
37
65
  }
38
66
  if (t.type === "test") {
39
- if (namePattern && !getTaskFullName(t).match(namePattern))
67
+ if (namePattern && !getTaskFullName(t).match(namePattern)) {
40
68
  t.mode = "skip";
69
+ }
41
70
  } else if (t.type === "suite") {
42
- if (t.mode === "skip")
71
+ if (t.mode === "skip") {
43
72
  skipAllTasks(t);
44
- else
73
+ } else {
45
74
  interpretTaskModes(t, namePattern, onlyMode, includeTask, allowOnly);
75
+ }
46
76
  }
47
77
  });
48
78
  if (suite.mode === "run") {
49
- if (suite.tasks.length && suite.tasks.every((i) => i.mode !== "run"))
79
+ if (suite.tasks.length && suite.tasks.every((i) => i.mode !== "run")) {
50
80
  suite.mode = "skip";
81
+ }
51
82
  }
52
83
  }
53
84
  function getTaskFullName(task) {
54
85
  return `${task.suite ? `${getTaskFullName(task.suite)} ` : ""}${task.name}`;
55
86
  }
56
87
  function someTasksAreOnly(suite) {
57
- return suite.tasks.some((t) => t.mode === "only" || t.type === "suite" && someTasksAreOnly(t));
88
+ return suite.tasks.some(
89
+ (t) => t.mode === "only" || t.type === "suite" && someTasksAreOnly(t)
90
+ );
58
91
  }
59
92
  function skipAllTasks(suite) {
60
93
  suite.tasks.forEach((t) => {
61
94
  if (t.mode === "run") {
62
95
  t.mode = "skip";
63
- if (t.type === "suite")
96
+ if (t.type === "suite") {
64
97
  skipAllTasks(t);
98
+ }
65
99
  }
66
100
  });
67
101
  }
68
102
  function checkAllowOnly(task, allowOnly) {
69
- if (allowOnly)
103
+ if (allowOnly) {
70
104
  return;
71
- const error = processError(new Error("[Vitest] Unexpected .only modifier. Remove it or pass --allowOnly argument to bypass this error"));
105
+ }
106
+ const error = processError(
107
+ new Error(
108
+ "[Vitest] Unexpected .only modifier. Remove it or pass --allowOnly argument to bypass this error"
109
+ )
110
+ );
72
111
  task.result = {
73
112
  state: "fail",
74
113
  errors: [error]
@@ -76,8 +115,9 @@ function checkAllowOnly(task, allowOnly) {
76
115
  }
77
116
  function generateHash(str) {
78
117
  let hash = 0;
79
- if (str.length === 0)
118
+ if (str.length === 0) {
80
119
  return `${hash}`;
120
+ }
81
121
  for (let i = 0; i < str.length; i++) {
82
122
  const char = str.charCodeAt(i);
83
123
  hash = (hash << 5) - hash + char;
@@ -88,11 +128,12 @@ function generateHash(str) {
88
128
  function calculateSuiteHash(parent) {
89
129
  parent.tasks.forEach((t, idx) => {
90
130
  t.id = `${parent.id}_${idx}`;
91
- if (t.type === "suite")
131
+ if (t.type === "suite") {
92
132
  calculateSuiteHash(t);
133
+ }
93
134
  });
94
135
  }
95
- function createFileTask(filepath, root, projectName) {
136
+ function createFileTask(filepath, root, projectName, pool) {
96
137
  const path = relative(root, filepath);
97
138
  const file = {
98
139
  id: generateHash(`${path}${projectName || ""}`),
@@ -103,7 +144,8 @@ function createFileTask(filepath, root, projectName) {
103
144
  tasks: [],
104
145
  meta: /* @__PURE__ */ Object.create(null),
105
146
  projectName,
106
- file: void 0
147
+ file: void 0,
148
+ pool
107
149
  };
108
150
  file.file = file;
109
151
  return file;
@@ -151,8 +193,9 @@ function getTests(suite) {
151
193
  tests.push(task);
152
194
  } else {
153
195
  const taskTests = getTests(task);
154
- for (const test of taskTests)
196
+ for (const test of taskTests) {
155
197
  tests.push(test);
198
+ }
156
199
  }
157
200
  }
158
201
  }
@@ -160,31 +203,41 @@ function getTests(suite) {
160
203
  return tests;
161
204
  }
162
205
  function getTasks(tasks = []) {
163
- return toArray(tasks).flatMap((s) => isAtomTest(s) ? [s] : [s, ...getTasks(s.tasks)]);
206
+ return toArray(tasks).flatMap(
207
+ (s) => isAtomTest(s) ? [s] : [s, ...getTasks(s.tasks)]
208
+ );
164
209
  }
165
210
  function getSuites(suite) {
166
- return toArray(suite).flatMap((s) => s.type === "suite" ? [s, ...getSuites(s.tasks)] : []);
211
+ return toArray(suite).flatMap(
212
+ (s) => s.type === "suite" ? [s, ...getSuites(s.tasks)] : []
213
+ );
167
214
  }
168
215
  function hasTests(suite) {
169
- return toArray(suite).some((s) => s.tasks.some((c) => isAtomTest(c) || hasTests(c)));
216
+ return toArray(suite).some(
217
+ (s) => s.tasks.some((c) => isAtomTest(c) || hasTests(c))
218
+ );
170
219
  }
171
220
  function hasFailed(suite) {
172
- return toArray(suite).some((s) => {
173
- var _a;
174
- return ((_a = s.result) == null ? void 0 : _a.state) === "fail" || s.type === "suite" && hasFailed(s.tasks);
175
- });
221
+ return toArray(suite).some(
222
+ (s) => {
223
+ var _a;
224
+ return ((_a = s.result) == null ? void 0 : _a.state) === "fail" || s.type === "suite" && hasFailed(s.tasks);
225
+ }
226
+ );
176
227
  }
177
228
  function getNames(task) {
178
229
  const names = [task.name];
179
230
  let current = task;
180
231
  while (current == null ? void 0 : current.suite) {
181
232
  current = current.suite;
182
- if (current == null ? void 0 : current.name)
233
+ if (current == null ? void 0 : current.name) {
183
234
  names.unshift(current.name);
235
+ }
184
236
  }
185
- if (current !== task.file)
237
+ if (current !== task.file) {
186
238
  names.unshift(task.file.name);
239
+ }
187
240
  return names;
188
241
  }
189
242
 
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 };
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-Cjrz1dUg.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-Cjrz1dUg.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-WAKtRuk9.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-WAKtRuk9.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;
@@ -23,11 +24,11 @@ declare function afterEach<ExtraContext = {}>(fn: SuiteHooks<ExtraContext>['afte
23
24
  declare const onTestFailed: (fn: OnTestFailedHandler) => void;
24
25
  declare const onTestFinished: (fn: OnTestFinishedHandler) => void;
25
26
 
26
- declare function setFn(key: Test | Custom, fn: (() => Awaitable<void>)): void;
27
- declare function getFn<Task = Test | Custom>(key: Task): (() => Awaitable<void>);
27
+ declare function setFn(key: Test | Custom, fn: () => Awaitable<void>): void;
28
+ declare function getFn<Task = Test | Custom>(key: Task): () => Awaitable<void>;
28
29
  declare function setHooks(key: Suite, hooks: SuiteHooks): void;
29
30
  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 };