@vitest/runner 1.5.3 → 2.0.0-beta.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.
- package/dist/chunk-tasks.js +4 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +57 -21
- package/dist/{tasks-K5XERDtv.d.ts → tasks-Ck0GpLiZ.d.ts} +4 -5
- package/dist/types.d.ts +2 -2
- package/dist/utils.d.ts +2 -2
- package/package.json +3 -3
package/dist/chunk-tasks.js
CHANGED
@@ -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 (
|
164
|
-
current = current.suite
|
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-
|
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-
|
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 =
|
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
|
-
|
440
|
-
task2.file = file;
|
448
|
+
task2.file = file;
|
441
449
|
});
|
442
450
|
return suite2;
|
443
451
|
}
|
@@ -470,9 +478,14 @@ function createSuite() {
|
|
470
478
|
optionsOrFn,
|
471
479
|
fnOrOptions
|
472
480
|
);
|
481
|
+
const fnFirst = typeof optionsOrFn === "function";
|
473
482
|
cases.forEach((i, idx) => {
|
474
483
|
const items = Array.isArray(i) ? i : [i];
|
475
|
-
|
484
|
+
if (fnFirst) {
|
485
|
+
arrayOnlyCases ? suite2(formatTitle(_name, items, idx), () => handler(...items), options) : suite2(formatTitle(_name, items, idx), () => handler(i), options);
|
486
|
+
} else {
|
487
|
+
arrayOnlyCases ? suite2(formatTitle(_name, items, idx), options, () => handler(...items)) : suite2(formatTitle(_name, items, idx), options, () => handler(i));
|
488
|
+
}
|
476
489
|
});
|
477
490
|
this.setContext("each", void 0);
|
478
491
|
};
|
@@ -498,9 +511,14 @@ function createTaskCollector(fn, context) {
|
|
498
511
|
optionsOrFn,
|
499
512
|
fnOrOptions
|
500
513
|
);
|
514
|
+
const fnFirst = typeof optionsOrFn === "function";
|
501
515
|
cases.forEach((i, idx) => {
|
502
516
|
const items = Array.isArray(i) ? i : [i];
|
503
|
-
|
517
|
+
if (fnFirst) {
|
518
|
+
arrayOnlyCases ? test2(formatTitle(_name, items, idx), () => handler(...items), options) : test2(formatTitle(_name, items, idx), () => handler(i), options);
|
519
|
+
} else {
|
520
|
+
arrayOnlyCases ? test2(formatTitle(_name, items, idx), options, () => handler(...items)) : test2(formatTitle(_name, items, idx), options, () => handler(i));
|
521
|
+
}
|
504
522
|
});
|
505
523
|
this.setContext("each", void 0);
|
506
524
|
};
|
@@ -607,8 +625,10 @@ async function collectTests(paths, runner) {
|
|
607
625
|
filepath,
|
608
626
|
tasks: [],
|
609
627
|
meta: /* @__PURE__ */ Object.create(null),
|
610
|
-
projectName: config.name
|
628
|
+
projectName: config.name,
|
629
|
+
file: void 0
|
611
630
|
};
|
631
|
+
file.file = file;
|
612
632
|
clearCollectorContext(filepath, runner);
|
613
633
|
try {
|
614
634
|
const setupStart = now$1();
|
@@ -617,20 +637,22 @@ async function collectTests(paths, runner) {
|
|
617
637
|
file.setupDuration = collectStart - setupStart;
|
618
638
|
await runner.importFile(filepath, "collect");
|
619
639
|
const defaultTasks = await getDefaultSuite().collect(file);
|
620
|
-
|
640
|
+
const fileHooks = createSuiteHooks();
|
641
|
+
mergeHooks(fileHooks, getHooks(defaultTasks));
|
621
642
|
for (const c of [...defaultTasks.tasks, ...collectorContext.tasks]) {
|
622
|
-
if (c.type === "test") {
|
623
|
-
file.tasks.push(c);
|
624
|
-
} else if (c.type === "custom") {
|
625
|
-
file.tasks.push(c);
|
626
|
-
} else if (c.type === "suite") {
|
643
|
+
if (c.type === "test" || c.type === "custom" || c.type === "suite") {
|
627
644
|
file.tasks.push(c);
|
628
645
|
} else if (c.type === "collector") {
|
629
646
|
const suite = await c.collect(file);
|
630
|
-
if (suite.name || suite.tasks.length)
|
647
|
+
if (suite.name || suite.tasks.length) {
|
648
|
+
mergeHooks(fileHooks, getHooks(suite));
|
631
649
|
file.tasks.push(suite);
|
650
|
+
}
|
651
|
+
} else {
|
652
|
+
c;
|
632
653
|
}
|
633
654
|
}
|
655
|
+
setHooks(file, fileHooks);
|
634
656
|
file.collectDuration = now$1() - collectStart;
|
635
657
|
} catch (e) {
|
636
658
|
const error = processError(e);
|
@@ -642,10 +664,22 @@ async function collectTests(paths, runner) {
|
|
642
664
|
calculateSuiteHash(file);
|
643
665
|
const hasOnlyTasks = someTasksAreOnly(file);
|
644
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
|
+
});
|
645
672
|
files.push(file);
|
646
673
|
}
|
647
674
|
return files;
|
648
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
|
+
}
|
649
683
|
|
650
684
|
const now = Date.now;
|
651
685
|
function updateSuiteHookState(suite, name, state, runner) {
|
@@ -679,9 +713,10 @@ async function callTaskHooks(task, hooks, sequence) {
|
|
679
713
|
async function callSuiteHook(suite, currentTask, name, runner, args) {
|
680
714
|
const sequence = runner.config.sequence.hooks;
|
681
715
|
const callbacks = [];
|
682
|
-
|
716
|
+
const parentSuite = "filepath" in suite ? null : suite.suite || suite.file;
|
717
|
+
if (name === "beforeEach" && parentSuite) {
|
683
718
|
callbacks.push(
|
684
|
-
...await callSuiteHook(
|
719
|
+
...await callSuiteHook(parentSuite, currentTask, name, runner, args)
|
685
720
|
);
|
686
721
|
}
|
687
722
|
updateSuiteHookState(currentTask, name, "run", runner);
|
@@ -693,9 +728,9 @@ async function callSuiteHook(suite, currentTask, name, runner, args) {
|
|
693
728
|
callbacks.push(await hook(...args));
|
694
729
|
}
|
695
730
|
updateSuiteHookState(currentTask, name, "pass", runner);
|
696
|
-
if (name === "afterEach" &&
|
731
|
+
if (name === "afterEach" && parentSuite) {
|
697
732
|
callbacks.push(
|
698
|
-
...await callSuiteHook(
|
733
|
+
...await callSuiteHook(parentSuite, currentTask, name, runner, args)
|
699
734
|
);
|
700
735
|
}
|
701
736
|
return callbacks;
|
@@ -753,6 +788,7 @@ async function runTest(test, runner) {
|
|
753
788
|
};
|
754
789
|
updateTask(test, runner);
|
755
790
|
setCurrentTest(test);
|
791
|
+
const suite = test.suite || test.file;
|
756
792
|
const repeats = test.repeats ?? 0;
|
757
793
|
for (let repeatCount = 0; repeatCount <= repeats; repeatCount++) {
|
758
794
|
const retry = test.retry ?? 0;
|
@@ -761,7 +797,7 @@ async function runTest(test, runner) {
|
|
761
797
|
try {
|
762
798
|
await ((_c = runner.onBeforeTryTask) == null ? void 0 : _c.call(runner, test, { retry: retryCount, repeats: repeatCount }));
|
763
799
|
test.result.repeatCount = repeatCount;
|
764
|
-
beforeEachCleanups = await callSuiteHook(
|
800
|
+
beforeEachCleanups = await callSuiteHook(suite, test, "beforeEach", runner, [test.context, suite]);
|
765
801
|
if (runner.runTask) {
|
766
802
|
await runner.runTask(test);
|
767
803
|
} else {
|
@@ -794,7 +830,7 @@ async function runTest(test, runner) {
|
|
794
830
|
return;
|
795
831
|
}
|
796
832
|
try {
|
797
|
-
await callSuiteHook(
|
833
|
+
await callSuiteHook(suite, test, "afterEach", runner, [test.context, suite]);
|
798
834
|
await callCleanupHooks(beforeEachCleanups);
|
799
835
|
await callFixtureCleanup(test.context);
|
800
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
|
-
|
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
|
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-
|
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-
|
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-
|
2
|
-
export { b as ChainableFunction, c as createChainable } from './tasks-
|
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": "
|
4
|
+
"version": "2.0.0-beta.1",
|
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.
|
43
|
-
"@vitest/utils": "
|
42
|
+
"pathe": "^1.1.2",
|
43
|
+
"@vitest/utils": "2.0.0-beta.1"
|
44
44
|
},
|
45
45
|
"scripts": {
|
46
46
|
"build": "rimraf dist && rollup -c",
|