@vitest/runner 0.34.0 → 0.34.2
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/index.d.ts +2 -2
- package/dist/index.js +27 -3
- package/dist/{tasks-abce80cc.d.ts → tasks-e594cd24.d.ts} +5 -0
- package/dist/types.d.ts +2 -2
- package/dist/utils.d.ts +2 -2
- package/dist/utils.js +15 -1
- package/package.json +2 -2
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 SuiteHooks, O as OnTestFailedHandler, a as Test } from './tasks-
|
4
|
-
export { D as DoneCallback, o as Fixtures, p as HookCleanupCallback, H as HookListener, R as RunMode, r as RuntimeContext, t as SequenceHooks, u as SequenceSetupFiles, S as Suite, q as SuiteFactory, i as TaskBase, b as TaskCustom, j as TaskMeta, k as TaskResult, l as TaskResultPack, h as TaskState, s as TestContext, m as TestFunction, n as TestOptions } from './tasks-
|
3
|
+
import { T as Task, F as File, d as SuiteAPI, e as TestAPI, f as SuiteCollector, g as SuiteHooks, O as OnTestFailedHandler, a as Test } from './tasks-e594cd24.js';
|
4
|
+
export { D as DoneCallback, o as Fixtures, p as HookCleanupCallback, H as HookListener, R as RunMode, r as RuntimeContext, t as SequenceHooks, u as SequenceSetupFiles, S as Suite, q as SuiteFactory, i as TaskBase, b as TaskCustom, j as TaskMeta, k as TaskResult, l as TaskResultPack, h as TaskState, s as TestContext, m as TestFunction, n as TestOptions } from './tasks-e594cd24.js';
|
5
5
|
import { Awaitable } from '@vitest/utils';
|
6
6
|
|
7
7
|
declare function updateTask(task: Task, runner: VitestRunner): void;
|
package/dist/index.js
CHANGED
@@ -19,6 +19,16 @@ function getHooks(key) {
|
|
19
19
|
return hooksMap.get(key);
|
20
20
|
}
|
21
21
|
|
22
|
+
class PendingError extends Error {
|
23
|
+
constructor(message, task) {
|
24
|
+
super(message);
|
25
|
+
this.message = message;
|
26
|
+
this.taskId = task.id;
|
27
|
+
}
|
28
|
+
code = "VITEST_PENDING";
|
29
|
+
taskId;
|
30
|
+
}
|
31
|
+
|
22
32
|
const collectorContext = {
|
23
33
|
tasks: [],
|
24
34
|
currentSuite: null
|
@@ -55,6 +65,10 @@ function createTestContext(test, runner) {
|
|
55
65
|
};
|
56
66
|
context.meta = test;
|
57
67
|
context.task = test;
|
68
|
+
context.skip = () => {
|
69
|
+
test.pending = true;
|
70
|
+
throw new PendingError("test is skipped; abort execution", test);
|
71
|
+
};
|
58
72
|
context.onTestFailed = (fn) => {
|
59
73
|
test.onFailed || (test.onFailed = []);
|
60
74
|
test.onFailed.push(fn);
|
@@ -565,7 +579,7 @@ async function callCleanupHooks(cleanups) {
|
|
565
579
|
}));
|
566
580
|
}
|
567
581
|
async function runTest(test, runner) {
|
568
|
-
var _a, _b, _c, _d, _e, _f;
|
582
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
569
583
|
await ((_a = runner.onBeforeRunTest) == null ? void 0 : _a.call(runner, test));
|
570
584
|
if (test.mode !== "run")
|
571
585
|
return;
|
@@ -614,6 +628,12 @@ async function runTest(test, runner) {
|
|
614
628
|
} catch (e) {
|
615
629
|
failTask(test.result, e);
|
616
630
|
}
|
631
|
+
if (test.pending || ((_e = test.result) == null ? void 0 : _e.state) === "skip") {
|
632
|
+
test.mode = "skip";
|
633
|
+
test.result = { state: "skip" };
|
634
|
+
updateTask(test, runner);
|
635
|
+
return;
|
636
|
+
}
|
617
637
|
try {
|
618
638
|
await callSuiteHook(test.suite, test, "afterEach", runner, [test.context, test.suite]);
|
619
639
|
await callCleanupHooks(beforeEachCleanups);
|
@@ -630,7 +650,7 @@ async function runTest(test, runner) {
|
|
630
650
|
}
|
631
651
|
}
|
632
652
|
if (test.result.state === "fail")
|
633
|
-
await Promise.all(((
|
653
|
+
await Promise.all(((_f = test.onFailed) == null ? void 0 : _f.map((fn) => fn(test.result))) || []);
|
634
654
|
if (test.fails) {
|
635
655
|
if (test.result.state === "pass") {
|
636
656
|
const error = processError(new Error("Expect test to fail"));
|
@@ -645,10 +665,14 @@ async function runTest(test, runner) {
|
|
645
665
|
}
|
646
666
|
setCurrentTest(void 0);
|
647
667
|
test.result.duration = now() - start;
|
648
|
-
await ((
|
668
|
+
await ((_g = runner.onAfterRunTest) == null ? void 0 : _g.call(runner, test));
|
649
669
|
updateTask(test, runner);
|
650
670
|
}
|
651
671
|
function failTask(result, err) {
|
672
|
+
if (err instanceof PendingError) {
|
673
|
+
result.state = "skip";
|
674
|
+
return;
|
675
|
+
}
|
652
676
|
result.state = "fail";
|
653
677
|
const errors = Array.isArray(err) ? err : [err];
|
654
678
|
for (const e of errors) {
|
@@ -60,6 +60,7 @@ interface File extends Suite {
|
|
60
60
|
interface Test<ExtraContext = {}> extends TaskBase {
|
61
61
|
type: 'test';
|
62
62
|
suite: Suite;
|
63
|
+
pending?: boolean;
|
63
64
|
result?: TaskResult;
|
64
65
|
fails?: boolean;
|
65
66
|
context: TestContext & ExtraContext;
|
@@ -190,6 +191,10 @@ interface TestContext {
|
|
190
191
|
* Extract hooks on test failed
|
191
192
|
*/
|
192
193
|
onTestFailed: (fn: OnTestFailedHandler) => void;
|
194
|
+
/**
|
195
|
+
* Mark tests as skipped. All execution after this call will be skipped.
|
196
|
+
*/
|
197
|
+
skip: () => void;
|
193
198
|
}
|
194
199
|
type OnTestFailedHandler = (result: TaskResult) => Awaitable<void>;
|
195
200
|
type SequenceHooks = 'stack' | 'list' | 'parallel';
|
package/dist/types.d.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
import { t as SequenceHooks, u as SequenceSetupFiles, F as File, a as Test, S as Suite, l as TaskResultPack, s as TestContext } from './tasks-
|
2
|
-
export { D as DoneCallback, o as Fixtures, p as HookCleanupCallback, H as HookListener, O as OnTestFailedHandler, R as RunMode, r as RuntimeContext, d as SuiteAPI, f as SuiteCollector, q as SuiteFactory, g as SuiteHooks, T as Task, i as TaskBase, b as TaskCustom, j as TaskMeta, k as TaskResult, h as TaskState, e as TestAPI, m as TestFunction, n as TestOptions } from './tasks-
|
1
|
+
import { t as SequenceHooks, u as SequenceSetupFiles, F as File, a as Test, S as Suite, l as TaskResultPack, s as TestContext } from './tasks-e594cd24.js';
|
2
|
+
export { D as DoneCallback, o as Fixtures, p as HookCleanupCallback, H as HookListener, O as OnTestFailedHandler, R as RunMode, r as RuntimeContext, d as SuiteAPI, f as SuiteCollector, q as SuiteFactory, g as SuiteHooks, T as Task, i as TaskBase, b as TaskCustom, j as TaskMeta, k as TaskResult, h as TaskState, e as TestAPI, m as TestFunction, n as TestOptions } from './tasks-e594cd24.js';
|
3
3
|
import '@vitest/utils';
|
4
4
|
|
5
5
|
interface VitestRunnerConfig {
|
package/dist/utils.d.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
import { S as Suite, T as Task, a as Test, b as TaskCustom } from './tasks-
|
2
|
-
export { C as ChainableFunction, c as createChainable } from './tasks-
|
1
|
+
import { S as Suite, T as Task, a as Test, b as TaskCustom } from './tasks-e594cd24.js';
|
2
|
+
export { C as ChainableFunction, c as createChainable } from './tasks-e594cd24.js';
|
3
3
|
import { Arrayable } from '@vitest/utils';
|
4
4
|
|
5
5
|
/**
|
package/dist/utils.js
CHANGED
@@ -124,7 +124,21 @@ function isAtomTest(s) {
|
|
124
124
|
return s.type === "test" || s.type === "custom";
|
125
125
|
}
|
126
126
|
function getTests(suite) {
|
127
|
-
|
127
|
+
const tests = [];
|
128
|
+
const suite_arr = toArray(suite);
|
129
|
+
for (const s of suite_arr) {
|
130
|
+
if (isAtomTest(s)) {
|
131
|
+
tests.push(s);
|
132
|
+
} else {
|
133
|
+
for (const task of s.tasks) {
|
134
|
+
if (isAtomTest(task))
|
135
|
+
tests.push(task);
|
136
|
+
else
|
137
|
+
tests.push(...getTests(task));
|
138
|
+
}
|
139
|
+
}
|
140
|
+
}
|
141
|
+
return tests;
|
128
142
|
}
|
129
143
|
function getTasks(tasks = []) {
|
130
144
|
return toArray(tasks).flatMap((s) => isAtomTest(s) ? [s] : [s, ...getTasks(s.tasks)]);
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@vitest/runner",
|
3
3
|
"type": "module",
|
4
|
-
"version": "0.34.
|
4
|
+
"version": "0.34.2",
|
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": "^4.0.0",
|
42
42
|
"pathe": "^1.1.1",
|
43
|
-
"@vitest/utils": "0.34.
|
43
|
+
"@vitest/utils": "0.34.2"
|
44
44
|
},
|
45
45
|
"scripts": {
|
46
46
|
"build": "rimraf dist && rollup -c",
|