@vitest/runner 1.2.2 → 1.3.0

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.
@@ -0,0 +1,168 @@
1
+ import { processError } from '@vitest/utils/error';
2
+ import { toArray } from '@vitest/utils';
3
+
4
+ function partitionSuiteChildren(suite) {
5
+ let tasksGroup = [];
6
+ const tasksGroups = [];
7
+ for (const c of suite.tasks) {
8
+ if (tasksGroup.length === 0 || c.concurrent === tasksGroup[0].concurrent) {
9
+ tasksGroup.push(c);
10
+ } else {
11
+ tasksGroups.push(tasksGroup);
12
+ tasksGroup = [c];
13
+ }
14
+ }
15
+ if (tasksGroup.length > 0)
16
+ tasksGroups.push(tasksGroup);
17
+ return tasksGroups;
18
+ }
19
+
20
+ function interpretTaskModes(suite, namePattern, onlyMode, parentIsOnly, allowOnly) {
21
+ const suiteIsOnly = parentIsOnly || suite.mode === "only";
22
+ suite.tasks.forEach((t) => {
23
+ const includeTask = suiteIsOnly || t.mode === "only";
24
+ if (onlyMode) {
25
+ if (t.type === "suite" && (includeTask || someTasksAreOnly(t))) {
26
+ if (t.mode === "only") {
27
+ checkAllowOnly(t, allowOnly);
28
+ t.mode = "run";
29
+ }
30
+ } else if (t.mode === "run" && !includeTask) {
31
+ t.mode = "skip";
32
+ } else if (t.mode === "only") {
33
+ checkAllowOnly(t, allowOnly);
34
+ t.mode = "run";
35
+ }
36
+ }
37
+ if (t.type === "test") {
38
+ if (namePattern && !getTaskFullName(t).match(namePattern))
39
+ t.mode = "skip";
40
+ } else if (t.type === "suite") {
41
+ if (t.mode === "skip")
42
+ skipAllTasks(t);
43
+ else
44
+ interpretTaskModes(t, namePattern, onlyMode, includeTask, allowOnly);
45
+ }
46
+ });
47
+ if (suite.mode === "run") {
48
+ if (suite.tasks.length && suite.tasks.every((i) => i.mode !== "run"))
49
+ suite.mode = "skip";
50
+ }
51
+ }
52
+ function getTaskFullName(task) {
53
+ return `${task.suite ? `${getTaskFullName(task.suite)} ` : ""}${task.name}`;
54
+ }
55
+ function someTasksAreOnly(suite) {
56
+ return suite.tasks.some((t) => t.mode === "only" || t.type === "suite" && someTasksAreOnly(t));
57
+ }
58
+ function skipAllTasks(suite) {
59
+ suite.tasks.forEach((t) => {
60
+ if (t.mode === "run") {
61
+ t.mode = "skip";
62
+ if (t.type === "suite")
63
+ skipAllTasks(t);
64
+ }
65
+ });
66
+ }
67
+ function checkAllowOnly(task, allowOnly) {
68
+ if (allowOnly)
69
+ return;
70
+ const error = processError(new Error("[Vitest] Unexpected .only modifier. Remove it or pass --allowOnly argument to bypass this error"));
71
+ task.result = {
72
+ state: "fail",
73
+ errors: [error]
74
+ };
75
+ }
76
+ function generateHash(str) {
77
+ let hash = 0;
78
+ if (str.length === 0)
79
+ return `${hash}`;
80
+ for (let i = 0; i < str.length; i++) {
81
+ const char = str.charCodeAt(i);
82
+ hash = (hash << 5) - hash + char;
83
+ hash = hash & hash;
84
+ }
85
+ return `${hash}`;
86
+ }
87
+ function calculateSuiteHash(parent) {
88
+ parent.tasks.forEach((t, idx) => {
89
+ t.id = `${parent.id}_${idx}`;
90
+ if (t.type === "suite")
91
+ calculateSuiteHash(t);
92
+ });
93
+ }
94
+
95
+ function createChainable(keys, fn) {
96
+ function create(context) {
97
+ const chain2 = function(...args) {
98
+ return fn.apply(context, args);
99
+ };
100
+ Object.assign(chain2, fn);
101
+ chain2.withContext = () => chain2.bind(context);
102
+ chain2.setContext = (key, value) => {
103
+ context[key] = value;
104
+ };
105
+ chain2.mergeContext = (ctx) => {
106
+ Object.assign(context, ctx);
107
+ };
108
+ for (const key of keys) {
109
+ Object.defineProperty(chain2, key, {
110
+ get() {
111
+ return create({ ...context, [key]: true });
112
+ }
113
+ });
114
+ }
115
+ return chain2;
116
+ }
117
+ const chain = create({});
118
+ chain.fn = fn;
119
+ return chain;
120
+ }
121
+
122
+ function isAtomTest(s) {
123
+ return s.type === "test" || s.type === "custom";
124
+ }
125
+ function getTests(suite) {
126
+ const tests = [];
127
+ const arraySuites = toArray(suite);
128
+ for (const s of arraySuites) {
129
+ if (isAtomTest(s)) {
130
+ tests.push(s);
131
+ } else {
132
+ for (const task of s.tasks) {
133
+ if (isAtomTest(task))
134
+ tests.push(task);
135
+ else
136
+ tests.push(...getTests(task));
137
+ }
138
+ }
139
+ }
140
+ return tests;
141
+ }
142
+ function getTasks(tasks = []) {
143
+ return toArray(tasks).flatMap((s) => isAtomTest(s) ? [s] : [s, ...getTasks(s.tasks)]);
144
+ }
145
+ function getSuites(suite) {
146
+ return toArray(suite).flatMap((s) => s.type === "suite" ? [s, ...getSuites(s.tasks)] : []);
147
+ }
148
+ function hasTests(suite) {
149
+ return toArray(suite).some((s) => s.tasks.some((c) => isAtomTest(c) || hasTests(c)));
150
+ }
151
+ function hasFailed(suite) {
152
+ return toArray(suite).some((s) => {
153
+ var _a;
154
+ return ((_a = s.result) == null ? void 0 : _a.state) === "fail" || s.type === "suite" && hasFailed(s.tasks);
155
+ });
156
+ }
157
+ function getNames(task) {
158
+ const names = [task.name];
159
+ let current = task;
160
+ while ((current == null ? void 0 : current.suite) || (current == null ? void 0 : current.file)) {
161
+ current = current.suite || current.file;
162
+ if (current == null ? void 0 : current.name)
163
+ names.unshift(current.name);
164
+ }
165
+ return names;
166
+ }
167
+
168
+ 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 };
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, a as Test, C as Custom, S as Suite } from './tasks-rsXe_qLO.js';
4
- export { D as DoneCallback, E as ExtendedContext, r as Fixture, q as FixtureFn, s as Fixtures, t as HookCleanupCallback, H as HookListener, I as InferFixturesTypes, R as RunMode, w as RuntimeContext, z as SequenceHooks, A as SequenceSetupFiles, v as SuiteFactory, j as TaskBase, y as TaskContext, u as TaskCustomOptions, l as TaskMeta, k as TaskPopulated, m as TaskResult, n as TaskResultPack, i as TaskState, x as TestContext, o as TestFunction, p as TestOptions, U as Use } from './tasks-rsXe_qLO.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-_kyNRBhz.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-_kyNRBhz.js';
5
5
  import { Awaitable } from '@vitest/utils';
6
6
  export { processError } from '@vitest/utils/error';
7
7
  import '@vitest/utils/diff';
@@ -21,6 +21,7 @@ declare function afterAll(fn: SuiteHooks['afterAll'][0], timeout?: number): void
21
21
  declare function beforeEach<ExtraContext = {}>(fn: SuiteHooks<ExtraContext>['beforeEach'][0], timeout?: number): void;
22
22
  declare function afterEach<ExtraContext = {}>(fn: SuiteHooks<ExtraContext>['afterEach'][0], timeout?: number): void;
23
23
  declare const onTestFailed: (fn: OnTestFailedHandler) => void;
24
+ declare const onTestFinished: (fn: OnTestFinishedHandler) => void;
24
25
 
25
26
  declare function setFn(key: Test | Custom, fn: (() => Awaitable<void>)): void;
26
27
  declare function getFn<Task = Test | Custom>(key: Task): (() => Awaitable<void>);
@@ -29,4 +30,4 @@ declare function getHooks(key: Suite): SuiteHooks;
29
30
 
30
31
  declare function getCurrentTest<T extends Test | Custom | undefined>(): T;
31
32
 
32
- export { Custom, CustomAPI, File, OnTestFailedHandler, Suite, SuiteAPI, SuiteCollector, SuiteHooks, Task, Test, TestAPI, VitestRunner, afterAll, afterEach, beforeAll, beforeEach, createTaskCollector, describe, getCurrentSuite, getCurrentTest, getFn, getHooks, it, onTestFailed, setFn, setHooks, startTests, suite, test, updateTask };
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 };
package/dist/index.js CHANGED
@@ -1,8 +1,8 @@
1
1
  import limit from 'p-limit';
2
- import { getSafeTimers, createDefer, format, isObject, objDisplay, objectAttr, noop, toArray, shuffle } from '@vitest/utils';
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 { createChainable, generateHash, calculateSuiteHash, someTasksAreOnly, interpretTaskModes, partitionSuiteChildren, hasTests, hasFailed } from './utils.js';
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
6
  import { relative } from 'pathe';
7
7
 
8
8
  const fnMap = /* @__PURE__ */ new WeakMap();
@@ -80,6 +80,10 @@ function createTestContext(test, runner) {
80
80
  test.onFailed || (test.onFailed = []);
81
81
  test.onFailed.push(fn);
82
82
  };
83
+ context.onTestFinished = (fn) => {
84
+ test.onFinished || (test.onFinished = []);
85
+ test.onFinished.push(fn);
86
+ };
83
87
  return ((_a = runner.extendTaskContext) == null ? void 0 : _a.call(runner, context)) || context;
84
88
  }
85
89
  function makeTimeoutMsg(isHook, timeout) {
@@ -88,14 +92,16 @@ If this is a long-running ${isHook ? "hook" : "test"}, pass a timeout value as t
88
92
  }
89
93
 
90
94
  function mergeContextFixtures(fixtures, context = {}) {
91
- const fixtureArray = Object.entries(fixtures).map(([prop, value], index) => {
92
- const isFn = typeof value === "function";
93
- return {
94
- prop,
95
- value,
96
- index,
97
- isFn
98
- };
95
+ const fixtureOptionKeys = ["auto"];
96
+ const fixtureArray = Object.entries(fixtures).map(([prop, value]) => {
97
+ const fixtureItem = { value };
98
+ if (Array.isArray(value) && value.length >= 2 && isObject(value[1]) && Object.keys(value[1]).some((key) => fixtureOptionKeys.includes(key))) {
99
+ Object.assign(fixtureItem, value[1]);
100
+ fixtureItem.value = value[0];
101
+ }
102
+ fixtureItem.prop = prop;
103
+ fixtureItem.isFn = typeof fixtureItem.value === "function";
104
+ return fixtureItem;
99
105
  });
100
106
  if (Array.isArray(context.fixtures))
101
107
  context.fixtures = context.fixtures.concat(fixtureArray);
@@ -127,7 +133,8 @@ function withFixtures(fn, testContext) {
127
133
  if (!(fixtures == null ? void 0 : fixtures.length))
128
134
  return fn(context);
129
135
  const usedProps = getUsedProps(fn);
130
- if (!usedProps.length)
136
+ const hasAutoFixture = fixtures.some(({ auto }) => auto);
137
+ if (!usedProps.length && !hasAutoFixture)
131
138
  return fn(context);
132
139
  if (!fixtureValueMaps.get(context))
133
140
  fixtureValueMaps.set(context, /* @__PURE__ */ new Map());
@@ -135,7 +142,7 @@ function withFixtures(fn, testContext) {
135
142
  if (!cleanupFnArrayMap.has(context))
136
143
  cleanupFnArrayMap.set(context, []);
137
144
  const cleanupFnArray = cleanupFnArrayMap.get(context);
138
- const usedFixtures = fixtures.filter(({ prop }) => usedProps.includes(prop));
145
+ const usedFixtures = fixtures.filter(({ prop, auto }) => auto || usedProps.includes(prop));
139
146
  const pendingFixtures = resolveDeps(usedFixtures);
140
147
  if (!pendingFixtures.length)
141
148
  return fn(context);
@@ -243,10 +250,10 @@ function getCurrentTest() {
243
250
 
244
251
  const suite = createSuite();
245
252
  const test = createTest(
246
- function(name, fn, options) {
253
+ function(name, optionsOrFn, optionsOrTest) {
247
254
  if (getCurrentTest())
248
255
  throw new Error('Calling the test function inside another test function is not allowed. Please put it inside "describe" or "suite" so it can be properly collected.');
249
- getCurrentSuite().test.fn.call(this, formatName(name), fn, options);
256
+ getCurrentSuite().test.fn.call(this, formatName(name), optionsOrFn, optionsOrTest);
250
257
  }
251
258
  );
252
259
  const describe = suite;
@@ -278,8 +285,33 @@ function createSuiteHooks() {
278
285
  afterEach: []
279
286
  };
280
287
  }
288
+ function parseArguments(optionsOrFn, optionsOrTest) {
289
+ let options = {};
290
+ let fn = () => {
291
+ };
292
+ if (typeof optionsOrTest === "object") {
293
+ if (typeof optionsOrFn === "object")
294
+ throw new TypeError("Cannot use two objects as arguments. Please provide options and a function callback in that order.");
295
+ options = optionsOrTest;
296
+ } else if (typeof optionsOrTest === "number") {
297
+ options = { timeout: optionsOrTest };
298
+ } else if (typeof optionsOrFn === "object") {
299
+ options = optionsOrFn;
300
+ }
301
+ if (typeof optionsOrFn === "function") {
302
+ if (typeof optionsOrTest === "function")
303
+ throw new TypeError("Cannot use two functions as arguments. Please use the second argument for options.");
304
+ fn = optionsOrFn;
305
+ } else if (typeof optionsOrTest === "function") {
306
+ fn = optionsOrTest;
307
+ }
308
+ return {
309
+ options,
310
+ handler: fn
311
+ };
312
+ }
281
313
  function createSuiteCollector(name, factory = () => {
282
- }, mode, concurrent, sequential, shuffle, each, suiteOptions) {
314
+ }, mode, shuffle, each, suiteOptions) {
283
315
  const tasks = [];
284
316
  const factoryQueue = [];
285
317
  let suite2;
@@ -318,16 +350,18 @@ function createSuiteCollector(name, factory = () => {
318
350
  tasks.push(task2);
319
351
  return task2;
320
352
  };
321
- const test2 = createTest(function(name2, fn = noop, options = {}) {
322
- if (typeof options === "number")
323
- options = { timeout: options };
353
+ const test2 = createTest(function(name2, optionsOrFn, optionsOrTest) {
354
+ let { options, handler } = parseArguments(
355
+ optionsOrFn,
356
+ optionsOrTest
357
+ );
324
358
  if (typeof suiteOptions === "object")
325
359
  options = Object.assign({}, suiteOptions, options);
326
360
  options.concurrent = this.concurrent || !this.sequential && (options == null ? void 0 : options.concurrent);
327
361
  options.sequential = this.sequential || !this.concurrent && (options == null ? void 0 : options.sequential);
328
362
  const test3 = task(
329
363
  formatName(name2),
330
- { ...this, ...options, handler: fn }
364
+ { ...this, ...options, handler }
331
365
  );
332
366
  test3.type = "test";
333
367
  });
@@ -387,28 +421,34 @@ function createSuiteCollector(name, factory = () => {
387
421
  return collector;
388
422
  }
389
423
  function createSuite() {
390
- function suiteFn(name, factory, options = {}) {
424
+ function suiteFn(name, factoryOrOptions, optionsOrFactory = {}) {
391
425
  const mode = this.only ? "only" : this.skip ? "skip" : this.todo ? "todo" : "run";
392
426
  const currentSuite = getCurrentSuite();
393
- if (typeof options === "number")
394
- options = { timeout: options };
427
+ let { options, handler: factory } = parseArguments(
428
+ factoryOrOptions,
429
+ optionsOrFactory
430
+ );
395
431
  if (currentSuite == null ? void 0 : currentSuite.options)
396
432
  options = { ...currentSuite.options, ...options };
397
433
  options.concurrent = this.concurrent || !this.sequential && (options == null ? void 0 : options.concurrent);
398
434
  options.sequential = this.sequential || !this.concurrent && (options == null ? void 0 : options.sequential);
399
- return createSuiteCollector(formatName(name), factory, mode, this.concurrent, this.sequential, this.shuffle, this.each, options);
435
+ return createSuiteCollector(formatName(name), factory, mode, this.shuffle, this.each, options);
400
436
  }
401
437
  suiteFn.each = function(cases, ...args) {
402
438
  const suite2 = this.withContext();
403
439
  this.setContext("each", true);
404
440
  if (Array.isArray(cases) && args.length)
405
441
  cases = formatTemplateString(cases, args);
406
- return (name, fn, options) => {
442
+ return (name, optionsOrFn, fnOrOptions) => {
407
443
  const _name = formatName(name);
408
444
  const arrayOnlyCases = cases.every(Array.isArray);
445
+ const { options, handler } = parseArguments(
446
+ optionsOrFn,
447
+ fnOrOptions
448
+ );
409
449
  cases.forEach((i, idx) => {
410
450
  const items = Array.isArray(i) ? i : [i];
411
- arrayOnlyCases ? suite2(formatTitle(_name, items, idx), () => fn(...items), options) : suite2(formatTitle(_name, items, idx), () => fn(i), options);
451
+ arrayOnlyCases ? suite2(formatTitle(_name, items, idx), options, () => handler(...items)) : suite2(formatTitle(_name, items, idx), options, () => handler(i));
412
452
  });
413
453
  this.setContext("each", void 0);
414
454
  };
@@ -427,12 +467,16 @@ function createTaskCollector(fn, context) {
427
467
  this.setContext("each", true);
428
468
  if (Array.isArray(cases) && args.length)
429
469
  cases = formatTemplateString(cases, args);
430
- return (name, fn2, options) => {
470
+ return (name, optionsOrFn, fnOrOptions) => {
431
471
  const _name = formatName(name);
432
472
  const arrayOnlyCases = cases.every(Array.isArray);
473
+ const { options, handler } = parseArguments(
474
+ optionsOrFn,
475
+ fnOrOptions
476
+ );
433
477
  cases.forEach((i, idx) => {
434
478
  const items = Array.isArray(i) ? i : [i];
435
- arrayOnlyCases ? test2(formatTitle(_name, items, idx), () => fn2(...items), options) : test2(formatTitle(_name, items, idx), () => fn2(i), options);
479
+ arrayOnlyCases ? test2(formatTitle(_name, items, idx), options, () => handler(...items)) : test2(formatTitle(_name, items, idx), options, () => handler(i));
436
480
  });
437
481
  this.setContext("each", void 0);
438
482
  };
@@ -445,8 +489,8 @@ function createTaskCollector(fn, context) {
445
489
  };
446
490
  taskFn.extend = function(fixtures) {
447
491
  const _context = mergeContextFixtures(fixtures, context);
448
- return createTest(function fn2(name, fn2, options) {
449
- getCurrentSuite().test.fn.call(this, formatName(name), fn2, options);
492
+ return createTest(function fn2(name, optionsOrFn, optionsOrTest) {
493
+ getCurrentSuite().test.fn.call(this, formatName(name), optionsOrFn, optionsOrTest);
450
494
  }, _context);
451
495
  };
452
496
  const _test = createChainable(
@@ -641,7 +685,7 @@ async function callCleanupHooks(cleanups) {
641
685
  }));
642
686
  }
643
687
  async function runTest(test, runner) {
644
- var _a, _b, _c, _d, _e, _f, _g;
688
+ var _a, _b, _c, _d, _e, _f, _g, _h;
645
689
  await ((_a = runner.onBeforeRunTask) == null ? void 0 : _a.call(runner, test));
646
690
  if (test.mode !== "run")
647
691
  return;
@@ -713,8 +757,18 @@ async function runTest(test, runner) {
713
757
  updateTask(test, runner);
714
758
  }
715
759
  }
716
- if (test.result.state === "fail")
717
- await Promise.all(((_f = test.onFailed) == null ? void 0 : _f.map((fn) => fn(test.result))) || []);
760
+ try {
761
+ await Promise.all(((_f = test.onFinished) == null ? void 0 : _f.map((fn) => fn(test.result))) || []);
762
+ } catch (e) {
763
+ failTask(test.result, e, runner.config.diffOptions);
764
+ }
765
+ if (test.result.state === "fail") {
766
+ try {
767
+ await Promise.all(((_g = test.onFailed) == null ? void 0 : _g.map((fn) => fn(test.result))) || []);
768
+ } catch (e) {
769
+ failTask(test.result, e, runner.config.diffOptions);
770
+ }
771
+ }
718
772
  if (test.fails) {
719
773
  if (test.result.state === "pass") {
720
774
  const error = processError(new Error("Expect test to fail"));
@@ -727,7 +781,7 @@ async function runTest(test, runner) {
727
781
  }
728
782
  setCurrentTest(void 0);
729
783
  test.result.duration = now() - start;
730
- await ((_g = runner.onAfterRunTask) == null ? void 0 : _g.call(runner, test));
784
+ await ((_h = runner.onAfterRunTask) == null ? void 0 : _h.call(runner, test));
731
785
  updateTask(test, runner);
732
786
  }
733
787
  function failTask(result, err, diffOptions) {
@@ -873,13 +927,17 @@ const onTestFailed = createTestHook("onTestFailed", (test, handler) => {
873
927
  test.onFailed || (test.onFailed = []);
874
928
  test.onFailed.push(handler);
875
929
  });
930
+ const onTestFinished = createTestHook("onTestFinished", (test, handler) => {
931
+ test.onFinished || (test.onFinished = []);
932
+ test.onFinished.push(handler);
933
+ });
876
934
  function createTestHook(name, handler) {
877
935
  return (fn) => {
878
936
  const current = getCurrentTest();
879
937
  if (!current)
880
938
  throw new Error(`Hook ${name}() can only be called inside a test`);
881
- handler(current, fn);
939
+ return handler(current, fn);
882
940
  };
883
941
  }
884
942
 
885
- export { afterAll, afterEach, beforeAll, beforeEach, createTaskCollector, describe, getCurrentSuite, getCurrentTest, getFn, getHooks, it, onTestFailed, setFn, setHooks, startTests, suite, test, updateTask };
943
+ export { afterAll, afterEach, beforeAll, beforeEach, createTaskCollector, describe, getCurrentSuite, getCurrentTest, getFn, getHooks, it, onTestFailed, onTestFinished, setFn, setHooks, startTests, suite, test, updateTask };
@@ -1,18 +1,15 @@
1
1
  import { ErrorWithDiff, Awaitable } from '@vitest/utils';
2
2
 
3
- type ChainableFunction<T extends string, Args extends any[], R = any, E = {}> = {
4
- (...args: Args): R;
3
+ type ChainableFunction<T extends string, F extends (...args: any) => any, C = {}> = F & {
4
+ [x in T]: ChainableFunction<T, F, C>;
5
5
  } & {
6
- [x in T]: ChainableFunction<T, Args, R, E>;
7
- } & {
8
- fn: (this: Record<T, any>, ...args: Args) => R;
9
- } & E;
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>;
6
+ fn: (this: Record<T, any>, ...args: Parameters<F>) => ReturnType<F>;
7
+ } & C;
8
+ declare function createChainable<T extends string, Args extends any[], R = any>(keys: T[], fn: (this: Record<T, any>, ...args: Args) => R): ChainableFunction<T, (...args: Args) => R>;
11
9
 
12
- interface FixtureItem {
10
+ interface FixtureItem extends FixtureOptions {
13
11
  prop: string;
14
12
  value: any;
15
- index: number;
16
13
  /**
17
14
  * Indicates whether the fixture is a function
18
15
  */
@@ -45,6 +42,7 @@ interface TaskPopulated extends TaskBase {
45
42
  result?: TaskResult;
46
43
  fails?: boolean;
47
44
  onFailed?: OnTestFailedHandler[];
45
+ onFinished?: OnTestFinishedHandler[];
48
46
  /**
49
47
  * Store promises (from async expects) to wait for them before finishing the test
50
48
  */
@@ -99,24 +97,30 @@ type ExtractEachCallbackArgs<T extends ReadonlyArray<any>> = {
99
97
  10: [T[0], T[1], T[2], T[3], T[4], T[5], T[6], T[7], T[8], T[9]];
100
98
  fallback: Array<T extends ReadonlyArray<infer U> ? U : any>;
101
99
  }[T extends Readonly<[any]> ? 1 : T extends Readonly<[any, any]> ? 2 : T extends Readonly<[any, any, any]> ? 3 : T extends Readonly<[any, any, any, any]> ? 4 : T extends Readonly<[any, any, any, any, any]> ? 5 : T extends Readonly<[any, any, any, any, any, any]> ? 6 : T extends Readonly<[any, any, any, any, any, any, any]> ? 7 : T extends Readonly<[any, any, any, any, any, any, any, any]> ? 8 : T extends Readonly<[any, any, any, any, any, any, any, any, any]> ? 9 : T extends Readonly<[any, any, any, any, any, any, any, any, any, any]> ? 10 : 'fallback'];
102
- interface SuiteEachFunction {
103
- <T extends any[] | [any]>(cases: ReadonlyArray<T>): (name: string | Function, fn: (...args: T) => Awaitable<void>) => void;
104
- <T extends ReadonlyArray<any>>(cases: ReadonlyArray<T>): (name: string | Function, fn: (...args: ExtractEachCallbackArgs<T>) => Awaitable<void>) => void;
105
- <T>(cases: ReadonlyArray<T>): (name: string | Function, fn: (...args: T[]) => Awaitable<void>) => void;
100
+ interface EachFunctionReturn<T extends any[]> {
101
+ /**
102
+ * @deprecated Use options as the second argument instead
103
+ */
104
+ (name: string | Function, fn: (...args: T) => Awaitable<void>, options: TestOptions): void;
105
+ (name: string | Function, fn: (...args: T) => Awaitable<void>, options?: number | TestOptions): void;
106
+ (name: string | Function, options: TestOptions, fn: (...args: T) => Awaitable<void>): void;
106
107
  }
107
108
  interface TestEachFunction {
108
- <T extends any[] | [any]>(cases: ReadonlyArray<T>): (name: string | Function, fn: (...args: T) => Awaitable<void>, options?: number | TestOptions) => void;
109
- <T extends ReadonlyArray<any>>(cases: ReadonlyArray<T>): (name: string | Function, fn: (...args: ExtractEachCallbackArgs<T>) => Awaitable<void>, options?: number | TestOptions) => void;
110
- <T>(cases: ReadonlyArray<T>): (name: string | Function, fn: (...args: T[]) => Awaitable<void>, options?: number | TestOptions) => void;
111
- (...args: [TemplateStringsArray, ...any]): (name: string | Function, fn: (...args: any[]) => Awaitable<void>, options?: number | TestOptions) => void;
112
- }
113
- type ChainableTestAPI<ExtraContext = {}> = ChainableFunction<'concurrent' | 'sequential' | 'only' | 'skip' | 'todo' | 'fails', [
114
- name: string | Function,
115
- fn?: TestFunction<ExtraContext>,
116
- options?: number | TestOptions
117
- ], void, {
109
+ <T extends any[] | [any]>(cases: ReadonlyArray<T>): EachFunctionReturn<T>;
110
+ <T extends ReadonlyArray<any>>(cases: ReadonlyArray<T>): EachFunctionReturn<ExtractEachCallbackArgs<T>>;
111
+ <T>(cases: ReadonlyArray<T>): EachFunctionReturn<T[]>;
112
+ (...args: [TemplateStringsArray, ...any]): EachFunctionReturn<any[]>;
113
+ }
114
+ interface TestCollectorCallable<C = {}> {
115
+ /**
116
+ * @deprecated Use options as the second argument instead
117
+ */
118
+ <ExtraContext extends C>(name: string | Function, fn: TestFunction<ExtraContext>, options: TestOptions): void;
119
+ <ExtraContext extends C>(name: string | Function, fn?: TestFunction<ExtraContext>, options?: number | TestOptions): void;
120
+ <ExtraContext extends C>(name: string | Function, options?: TestOptions, fn?: TestFunction<ExtraContext>): void;
121
+ }
122
+ type ChainableTestAPI<ExtraContext = {}> = ChainableFunction<'concurrent' | 'sequential' | 'only' | 'skip' | 'todo' | 'fails', TestCollectorCallable<ExtraContext>, {
118
123
  each: TestEachFunction;
119
- <T extends ExtraContext>(name: string | Function, fn?: TestFunction<T>, options?: number | TestOptions): void;
120
124
  }>;
121
125
  interface TestOptions {
122
126
  /**
@@ -147,41 +151,64 @@ interface TestOptions {
147
151
  * Tests inherit `sequential` from `describe()` and nested `describe()` will inherit from parent's `sequential`.
148
152
  */
149
153
  sequential?: boolean;
154
+ /**
155
+ * Whether the test should be skipped.
156
+ */
157
+ skip?: boolean;
158
+ /**
159
+ * Should this test be the only one running in a suite.
160
+ */
161
+ only?: boolean;
162
+ /**
163
+ * Whether the test should be skipped and marked as a todo.
164
+ */
165
+ todo?: boolean;
166
+ /**
167
+ * Whether the test is expected to fail. If it does, the test will pass, otherwise it will fail.
168
+ */
169
+ fails?: boolean;
150
170
  }
151
171
  interface ExtendedAPI<ExtraContext> {
152
- each: TestEachFunction;
153
- skipIf(condition: any): ChainableTestAPI<ExtraContext>;
154
- runIf(condition: any): ChainableTestAPI<ExtraContext>;
172
+ skipIf: (condition: any) => ChainableTestAPI<ExtraContext>;
173
+ runIf: (condition: any) => ChainableTestAPI<ExtraContext>;
155
174
  }
156
175
  type CustomAPI<ExtraContext = {}> = ChainableTestAPI<ExtraContext> & ExtendedAPI<ExtraContext> & {
157
- extend<T extends Record<string, any> = {}>(fixtures: Fixtures<T, ExtraContext>): CustomAPI<{
176
+ extend: <T extends Record<string, any> = {}>(fixtures: Fixtures<T, ExtraContext>) => CustomAPI<{
158
177
  [K in keyof T | keyof ExtraContext]: K extends keyof T ? T[K] : K extends keyof ExtraContext ? ExtraContext[K] : never;
159
178
  }>;
160
179
  };
161
180
  type TestAPI<ExtraContext = {}> = ChainableTestAPI<ExtraContext> & ExtendedAPI<ExtraContext> & {
162
- extend<T extends Record<string, any> = {}>(fixtures: Fixtures<T, ExtraContext>): TestAPI<{
181
+ extend: <T extends Record<string, any> = {}>(fixtures: Fixtures<T, ExtraContext>) => TestAPI<{
163
182
  [K in keyof T | keyof ExtraContext]: K extends keyof T ? T[K] : K extends keyof ExtraContext ? ExtraContext[K] : never;
164
183
  }>;
165
184
  };
185
+ interface FixtureOptions {
186
+ /**
187
+ * Whether to automatically set up current fixture, even though it's not being used in tests.
188
+ */
189
+ auto?: boolean;
190
+ }
166
191
  type Use<T> = (value: T) => Promise<void>;
167
192
  type FixtureFn<T, K extends keyof T, ExtraContext> = (context: Omit<T, K> & ExtraContext, use: Use<T[K]>) => Promise<void>;
168
193
  type Fixture<T, K extends keyof T, ExtraContext = {}> = ((...args: any) => any) extends T[K] ? (T[K] extends any ? FixtureFn<T, K, Omit<ExtraContext, Exclude<keyof T, K>>> : never) : T[K] | (T[K] extends any ? FixtureFn<T, K, Omit<ExtraContext, Exclude<keyof T, K>>> : never);
169
194
  type Fixtures<T extends Record<string, any>, ExtraContext = {}> = {
170
- [K in keyof T]: Fixture<T, K, ExtraContext & ExtendedContext<Test>>;
195
+ [K in keyof T]: Fixture<T, K, ExtraContext & ExtendedContext<Test>> | [Fixture<T, K, ExtraContext & ExtendedContext<Test>>, FixtureOptions?];
171
196
  };
172
197
  type InferFixturesTypes<T> = T extends TestAPI<infer C> ? C : T;
173
- type ChainableSuiteAPI<ExtraContext = {}> = ChainableFunction<'concurrent' | 'sequential' | 'only' | 'skip' | 'todo' | 'shuffle', [
174
- name: string | Function,
175
- factory?: SuiteFactory<ExtraContext>,
176
- options?: number | TestOptions
177
- ], SuiteCollector<ExtraContext>, {
198
+ interface SuiteCollectorCallable<ExtraContext = {}> {
199
+ /**
200
+ * @deprecated Use options as the second argument instead
201
+ */
202
+ (name: string | Function, fn: SuiteFactory<ExtraContext>, options: TestOptions): SuiteCollector<ExtraContext>;
203
+ (name: string | Function, fn?: SuiteFactory<ExtraContext>, options?: number | TestOptions): SuiteCollector<ExtraContext>;
204
+ (name: string | Function, options: TestOptions, fn?: SuiteFactory<ExtraContext>): SuiteCollector<ExtraContext>;
205
+ }
206
+ type ChainableSuiteAPI<ExtraContext = {}> = ChainableFunction<'concurrent' | 'sequential' | 'only' | 'skip' | 'todo' | 'shuffle', SuiteCollectorCallable<ExtraContext>, {
178
207
  each: TestEachFunction;
179
- <T extends ExtraContext>(name: string | Function, factory?: SuiteFactory<T>): SuiteCollector<T>;
180
208
  }>;
181
209
  type SuiteAPI<ExtraContext = {}> = ChainableSuiteAPI<ExtraContext> & {
182
- each: SuiteEachFunction;
183
- skipIf(condition: any): ChainableSuiteAPI<ExtraContext>;
184
- runIf(condition: any): ChainableSuiteAPI<ExtraContext>;
210
+ skipIf: (condition: any) => ChainableSuiteAPI<ExtraContext>;
211
+ runIf: (condition: any) => ChainableSuiteAPI<ExtraContext>;
185
212
  };
186
213
  type HookListener<T extends any[], Return = void> = (...args: T) => Awaitable<Return>;
187
214
  type HookCleanupCallback = (() => Awaitable<unknown>) | void;
@@ -231,6 +258,10 @@ interface TaskContext<Task extends Custom | Test = Custom | Test> {
231
258
  * Extract hooks on test failed
232
259
  */
233
260
  onTestFailed: (fn: OnTestFailedHandler) => void;
261
+ /**
262
+ * Extract hooks on test failed
263
+ */
264
+ onTestFinished: (fn: OnTestFinishedHandler) => void;
234
265
  /**
235
266
  * Mark tests as skipped. All execution after this call will be skipped.
236
267
  */
@@ -238,7 +269,8 @@ interface TaskContext<Task extends Custom | Test = Custom | Test> {
238
269
  }
239
270
  type ExtendedContext<T extends Custom | Test> = TaskContext<T> & TestContext;
240
271
  type OnTestFailedHandler = (result: TaskResult) => Awaitable<void>;
272
+ type OnTestFinishedHandler = (result: TaskResult) => Awaitable<void>;
241
273
  type SequenceHooks = 'stack' | 'list' | 'parallel';
242
274
  type SequenceSetupFiles = 'list' | 'parallel';
243
275
 
244
- export { type SequenceSetupFiles as A, type Custom as C, type DoneCallback as D, type ExtendedContext as E, type File as F, type HookListener as H, type InferFixturesTypes as I, type OnTestFailedHandler as O, type RunMode as R, type Suite as S, type Task as T, type Use as U, type Test as a, type ChainableFunction as b, createChainable as c, type SuiteAPI as d, type TestAPI as e, type SuiteCollector as f, type CustomAPI as g, type SuiteHooks as h, type TaskState as i, type TaskBase as j, type TaskPopulated as k, type TaskMeta as l, type TaskResult as m, type TaskResultPack as n, type TestFunction as o, type TestOptions as p, type FixtureFn as q, type Fixture as r, type Fixtures as s, type HookCleanupCallback as t, type TaskCustomOptions as u, type SuiteFactory as v, type RuntimeContext as w, type TestContext as x, type TaskContext as y, type SequenceHooks as z };
276
+ export { type TaskContext as A, type SequenceHooks as B, type Custom as C, type DoneCallback as D, type ExtendedContext as E, type File as F, type SequenceSetupFiles as G, type HookListener as H, type InferFixturesTypes as I, type OnTestFailedHandler as O, type RunMode as R, type Suite as S, type Task as T, type Use as U, type Test as a, type ChainableFunction as b, createChainable as c, type SuiteAPI as d, type TestAPI as e, type SuiteCollector as f, type CustomAPI as g, type SuiteHooks as h, type OnTestFinishedHandler as i, type TaskState as j, type TaskBase as k, type TaskPopulated as l, type TaskMeta as m, type TaskResult as n, type TaskResultPack as o, type TestFunction as p, type TestOptions as q, type FixtureOptions as r, type FixtureFn as s, type Fixture as t, type Fixtures as u, type HookCleanupCallback as v, type TaskCustomOptions as w, type SuiteFactory as x, type RuntimeContext as y, type TestContext as z };
package/dist/types.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { z as SequenceHooks, A as SequenceSetupFiles, F as File, k as TaskPopulated, S as Suite, n as TaskResultPack, a as Test, C as Custom, y as TaskContext, E as ExtendedContext } from './tasks-rsXe_qLO.js';
2
- export { g as CustomAPI, D as DoneCallback, r as Fixture, q as FixtureFn, s as Fixtures, t as HookCleanupCallback, H as HookListener, I as InferFixturesTypes, O as OnTestFailedHandler, R as RunMode, w as RuntimeContext, d as SuiteAPI, f as SuiteCollector, v as SuiteFactory, h as SuiteHooks, T as Task, j as TaskBase, u as TaskCustomOptions, l as TaskMeta, m as TaskResult, i as TaskState, e as TestAPI, x as TestContext, o as TestFunction, p as TestOptions, U as Use } from './tasks-rsXe_qLO.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-_kyNRBhz.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-_kyNRBhz.js';
3
3
  import { DiffOptions } from '@vitest/utils/diff';
4
4
  import '@vitest/utils';
5
5
 
@@ -35,69 +35,69 @@ interface VitestRunner {
35
35
  /**
36
36
  * First thing that's getting called before actually collecting and running tests.
37
37
  */
38
- onBeforeCollect?(paths: string[]): unknown;
38
+ onBeforeCollect?: (paths: string[]) => unknown;
39
39
  /**
40
40
  * Called after collecting tests and before "onBeforeRun".
41
41
  */
42
- onCollected?(files: File[]): unknown;
42
+ onCollected?: (files: File[]) => unknown;
43
43
  /**
44
44
  * Called when test runner should cancel next test runs.
45
45
  * Runner should listen for this method and mark tests and suites as skipped in
46
46
  * "onBeforeRunSuite" and "onBeforeRunTask" when called.
47
47
  */
48
- onCancel?(reason: CancelReason): unknown;
48
+ onCancel?: (reason: CancelReason) => unknown;
49
49
  /**
50
50
  * Called before running a single test. Doesn't have "result" yet.
51
51
  */
52
- onBeforeRunTask?(test: TaskPopulated): unknown;
52
+ onBeforeRunTask?: (test: Task) => unknown;
53
53
  /**
54
54
  * Called before actually running the test function. Already has "result" with "state" and "startTime".
55
55
  */
56
- onBeforeTryTask?(test: TaskPopulated, options: {
56
+ onBeforeTryTask?: (test: Task, options: {
57
57
  retry: number;
58
58
  repeats: number;
59
- }): unknown;
59
+ }) => unknown;
60
60
  /**
61
61
  * Called after result and state are set.
62
62
  */
63
- onAfterRunTask?(test: TaskPopulated): unknown;
63
+ onAfterRunTask?: (test: Task) => unknown;
64
64
  /**
65
65
  * Called right after running the test function. Doesn't have new state yet. Will not be called, if the test function throws.
66
66
  */
67
- onAfterTryTask?(test: TaskPopulated, options: {
67
+ onAfterTryTask?: (test: Task, options: {
68
68
  retry: number;
69
69
  repeats: number;
70
- }): unknown;
70
+ }) => unknown;
71
71
  /**
72
72
  * Called before running a single suite. Doesn't have "result" yet.
73
73
  */
74
- onBeforeRunSuite?(suite: Suite): unknown;
74
+ onBeforeRunSuite?: (suite: Suite) => unknown;
75
75
  /**
76
76
  * Called after running a single suite. Has state and result.
77
77
  */
78
- onAfterRunSuite?(suite: Suite): unknown;
78
+ onAfterRunSuite?: (suite: Suite) => unknown;
79
79
  /**
80
80
  * If defined, will be called instead of usual Vitest suite partition and handling.
81
81
  * "before" and "after" hooks will not be ignored.
82
82
  */
83
- runSuite?(suite: Suite): Promise<void>;
83
+ runSuite?: (suite: Suite) => Promise<void>;
84
84
  /**
85
85
  * If defined, will be called instead of usual Vitest handling. Useful, if you have your custom test function.
86
86
  * "before" and "after" hooks will not be ignored.
87
87
  */
88
- runTask?(test: TaskPopulated): Promise<void>;
88
+ runTask?: (test: Task) => Promise<void>;
89
89
  /**
90
90
  * Called, when a task is updated. The same as "onTaskUpdate" in a reporter, but this is running in the same thread as tests.
91
91
  */
92
- onTaskUpdate?(task: TaskResultPack[]): Promise<void>;
92
+ onTaskUpdate?: (task: TaskResultPack[]) => Promise<void>;
93
93
  /**
94
94
  * Called before running all tests in collected paths.
95
95
  */
96
- onBeforeRunFiles?(files: File[]): unknown;
96
+ onBeforeRunFiles?: (files: File[]) => unknown;
97
97
  /**
98
98
  * Called right after running all tests in collected paths.
99
99
  */
100
- onAfterRunFiles?(files: File[]): unknown;
100
+ onAfterRunFiles?: (files: File[]) => unknown;
101
101
  /**
102
102
  * Called when new context for a test is defined. Useful, if you want to add custom properties to the context.
103
103
  * If you only want to define custom context, consider using "beforeAll" in "setupFiles" instead.
@@ -106,15 +106,15 @@ interface VitestRunner {
106
106
  *
107
107
  * @see https://vitest.dev/advanced/runner.html#your-task-function
108
108
  */
109
- extendTaskContext?<T extends Test | Custom>(context: TaskContext<T>): ExtendedContext<T>;
109
+ extendTaskContext?: <T extends Test | Custom>(context: TaskContext<T>) => ExtendedContext<T>;
110
110
  /**
111
111
  * Called, when files are imported. Can be called in two situations: when collecting tests and when importing setup files.
112
112
  */
113
- importFile(filepath: string, source: VitestRunnerImportSource): unknown;
113
+ importFile: (filepath: string, source: VitestRunnerImportSource) => unknown;
114
114
  /**
115
115
  * Publicly available configuration.
116
116
  */
117
117
  config: VitestRunnerConfig;
118
118
  }
119
119
 
120
- export { type CancelReason, Custom, ExtendedContext, File, SequenceHooks, SequenceSetupFiles, Suite, TaskContext, TaskPopulated, TaskResultPack, Test, type VitestRunner, type VitestRunnerConfig, type VitestRunnerConstructor, type VitestRunnerImportSource };
120
+ 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, T as Task, a as Test, C as Custom } from './tasks-rsXe_qLO.js';
2
- export { b as ChainableFunction, c as createChainable } from './tasks-rsXe_qLO.js';
1
+ import { S as Suite, T as Task, a as Test, C as Custom } from './tasks-_kyNRBhz.js';
2
+ export { b as ChainableFunction, c as createChainable } from './tasks-_kyNRBhz.js';
3
3
  import { Arrayable } from '@vitest/utils';
4
4
 
5
5
  /**
package/dist/utils.js CHANGED
@@ -1,168 +1,3 @@
1
- import { processError } from '@vitest/utils/error';
2
- import { toArray } from '@vitest/utils';
3
-
4
- function partitionSuiteChildren(suite) {
5
- let tasksGroup = [];
6
- const tasksGroups = [];
7
- for (const c of suite.tasks) {
8
- if (tasksGroup.length === 0 || c.concurrent === tasksGroup[0].concurrent) {
9
- tasksGroup.push(c);
10
- } else {
11
- tasksGroups.push(tasksGroup);
12
- tasksGroup = [c];
13
- }
14
- }
15
- if (tasksGroup.length > 0)
16
- tasksGroups.push(tasksGroup);
17
- return tasksGroups;
18
- }
19
-
20
- function interpretTaskModes(suite, namePattern, onlyMode, parentIsOnly, allowOnly) {
21
- const suiteIsOnly = parentIsOnly || suite.mode === "only";
22
- suite.tasks.forEach((t) => {
23
- const includeTask = suiteIsOnly || t.mode === "only";
24
- if (onlyMode) {
25
- if (t.type === "suite" && (includeTask || someTasksAreOnly(t))) {
26
- if (t.mode === "only") {
27
- checkAllowOnly(t, allowOnly);
28
- t.mode = "run";
29
- }
30
- } else if (t.mode === "run" && !includeTask) {
31
- t.mode = "skip";
32
- } else if (t.mode === "only") {
33
- checkAllowOnly(t, allowOnly);
34
- t.mode = "run";
35
- }
36
- }
37
- if (t.type === "test") {
38
- if (namePattern && !getTaskFullName(t).match(namePattern))
39
- t.mode = "skip";
40
- } else if (t.type === "suite") {
41
- if (t.mode === "skip")
42
- skipAllTasks(t);
43
- else
44
- interpretTaskModes(t, namePattern, onlyMode, includeTask, allowOnly);
45
- }
46
- });
47
- if (suite.mode === "run") {
48
- if (suite.tasks.length && suite.tasks.every((i) => i.mode !== "run"))
49
- suite.mode = "skip";
50
- }
51
- }
52
- function getTaskFullName(task) {
53
- return `${task.suite ? `${getTaskFullName(task.suite)} ` : ""}${task.name}`;
54
- }
55
- function someTasksAreOnly(suite) {
56
- return suite.tasks.some((t) => t.mode === "only" || t.type === "suite" && someTasksAreOnly(t));
57
- }
58
- function skipAllTasks(suite) {
59
- suite.tasks.forEach((t) => {
60
- if (t.mode === "run") {
61
- t.mode = "skip";
62
- if (t.type === "suite")
63
- skipAllTasks(t);
64
- }
65
- });
66
- }
67
- function checkAllowOnly(task, allowOnly) {
68
- if (allowOnly)
69
- return;
70
- const error = processError(new Error("[Vitest] Unexpected .only modifier. Remove it or pass --allowOnly argument to bypass this error"));
71
- task.result = {
72
- state: "fail",
73
- errors: [error]
74
- };
75
- }
76
- function generateHash(str) {
77
- let hash = 0;
78
- if (str.length === 0)
79
- return `${hash}`;
80
- for (let i = 0; i < str.length; i++) {
81
- const char = str.charCodeAt(i);
82
- hash = (hash << 5) - hash + char;
83
- hash = hash & hash;
84
- }
85
- return `${hash}`;
86
- }
87
- function calculateSuiteHash(parent) {
88
- parent.tasks.forEach((t, idx) => {
89
- t.id = `${parent.id}_${idx}`;
90
- if (t.type === "suite")
91
- calculateSuiteHash(t);
92
- });
93
- }
94
-
95
- function createChainable(keys, fn) {
96
- function create(context) {
97
- const chain2 = function(...args) {
98
- return fn.apply(context, args);
99
- };
100
- Object.assign(chain2, fn);
101
- chain2.withContext = () => chain2.bind(context);
102
- chain2.setContext = (key, value) => {
103
- context[key] = value;
104
- };
105
- chain2.mergeContext = (ctx) => {
106
- Object.assign(context, ctx);
107
- };
108
- for (const key of keys) {
109
- Object.defineProperty(chain2, key, {
110
- get() {
111
- return create({ ...context, [key]: true });
112
- }
113
- });
114
- }
115
- return chain2;
116
- }
117
- const chain = create({});
118
- chain.fn = fn;
119
- return chain;
120
- }
121
-
122
- function isAtomTest(s) {
123
- return s.type === "test" || s.type === "custom";
124
- }
125
- function getTests(suite) {
126
- const tests = [];
127
- const arraySuites = toArray(suite);
128
- for (const s of arraySuites) {
129
- if (isAtomTest(s)) {
130
- tests.push(s);
131
- } else {
132
- for (const task of s.tasks) {
133
- if (isAtomTest(task))
134
- tests.push(task);
135
- else
136
- tests.push(...getTests(task));
137
- }
138
- }
139
- }
140
- return tests;
141
- }
142
- function getTasks(tasks = []) {
143
- return toArray(tasks).flatMap((s) => isAtomTest(s) ? [s] : [s, ...getTasks(s.tasks)]);
144
- }
145
- function getSuites(suite) {
146
- return toArray(suite).flatMap((s) => s.type === "suite" ? [s, ...getSuites(s.tasks)] : []);
147
- }
148
- function hasTests(suite) {
149
- return toArray(suite).some((s) => s.tasks.some((c) => isAtomTest(c) || hasTests(c)));
150
- }
151
- function hasFailed(suite) {
152
- return toArray(suite).some((s) => {
153
- var _a;
154
- return ((_a = s.result) == null ? void 0 : _a.state) === "fail" || s.type === "suite" && hasFailed(s.tasks);
155
- });
156
- }
157
- function getNames(task) {
158
- const names = [task.name];
159
- let current = task;
160
- while ((current == null ? void 0 : current.suite) || (current == null ? void 0 : current.file)) {
161
- current = current.suite || current.file;
162
- if (current == null ? void 0 : current.name)
163
- names.unshift(current.name);
164
- }
165
- return names;
166
- }
167
-
168
- export { calculateSuiteHash, createChainable, generateHash, getNames, getSuites, getTasks, getTests, hasFailed, hasTests, interpretTaskModes, partitionSuiteChildren, someTasksAreOnly };
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';
2
+ import '@vitest/utils/error';
3
+ import '@vitest/utils';
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vitest/runner",
3
3
  "type": "module",
4
- "version": "1.2.2",
4
+ "version": "1.3.0",
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.1",
43
- "@vitest/utils": "1.2.2"
43
+ "@vitest/utils": "1.3.0"
44
44
  },
45
45
  "scripts": {
46
46
  "build": "rimraf dist && rollup -c",