@vitest/runner 1.0.0-beta.1 → 1.0.0-beta.3
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 +3 -2
- package/dist/index.js +18 -29
- package/dist/{tasks-b31a73cb.d.ts → tasks-3ea70b32.d.ts} +1 -5
- package/dist/types.d.ts +3 -3
- package/dist/utils.d.ts +2 -2
- package/dist/utils.js +2 -3
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
@@ -1,8 +1,9 @@
|
|
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 } from './tasks-
|
4
|
-
export { D as DoneCallback, E as ExtendedContext, q as Fixture, r as Fixtures, s as HookCleanupCallback, H as HookListener, I as InferFixturesTypes, R as RunMode, v as RuntimeContext, y as SequenceHooks, z as SequenceSetupFiles, S as Suite, u as SuiteFactory, j as TaskBase, x as TaskContext, t as TaskCustomOptions, l as TaskMeta, k as TaskPopulated, m as TaskResult, n as TaskResultPack, i as TaskState, w as TestContext, o as TestFunction, p as TestOptions } 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, a as Test, C as Custom } from './tasks-3ea70b32.js';
|
4
|
+
export { D as DoneCallback, E as ExtendedContext, q as Fixture, r as Fixtures, s as HookCleanupCallback, H as HookListener, I as InferFixturesTypes, R as RunMode, v as RuntimeContext, y as SequenceHooks, z as SequenceSetupFiles, S as Suite, u as SuiteFactory, j as TaskBase, x as TaskContext, t as TaskCustomOptions, l as TaskMeta, k as TaskPopulated, m as TaskResult, n as TaskResultPack, i as TaskState, w as TestContext, o as TestFunction, p as TestOptions } from './tasks-3ea70b32.js';
|
5
5
|
import { Awaitable } from '@vitest/utils';
|
6
|
+
export { processError } from '@vitest/utils/error';
|
6
7
|
|
7
8
|
declare function updateTask(task: Task, runner: VitestRunner): void;
|
8
9
|
declare function startTests(paths: string[], runner: VitestRunner): Promise<File[]>;
|
package/dist/index.js
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
import limit from 'p-limit';
|
2
2
|
import { getSafeTimers, format, isObject, objDisplay, objectAttr, noop, toArray, shuffle } from '@vitest/utils';
|
3
3
|
import { processError } from '@vitest/utils/error';
|
4
|
+
export { processError } from '@vitest/utils/error';
|
4
5
|
import { createChainable, generateHash, calculateSuiteHash, someTasksAreOnly, interpretTaskModes, partitionSuiteChildren, hasTests, hasFailed } from './utils.js';
|
5
6
|
import { relative } from 'pathe';
|
6
7
|
|
@@ -110,25 +111,17 @@ function mergeContextFixtures(fixtures, context = {}) {
|
|
110
111
|
return context;
|
111
112
|
}
|
112
113
|
const fixtureValueMap = /* @__PURE__ */ new Map();
|
113
|
-
|
114
|
-
async function callFixtureCleanup(
|
115
|
-
const cleanupFnArray = fixtureCleanupFnMap.get(id);
|
116
|
-
if (!cleanupFnArray)
|
117
|
-
return;
|
114
|
+
let cleanupFnArray = new Array();
|
115
|
+
async function callFixtureCleanup() {
|
118
116
|
for (const cleanup of cleanupFnArray.reverse())
|
119
117
|
await cleanup();
|
120
|
-
|
118
|
+
cleanupFnArray = [];
|
121
119
|
}
|
122
120
|
function withFixtures(fn, testContext) {
|
123
121
|
return (hookContext) => {
|
124
122
|
const context = hookContext || testContext;
|
125
123
|
if (!context)
|
126
124
|
return fn({});
|
127
|
-
let cleanupFnArray = fixtureCleanupFnMap.get(context.task.suite.id);
|
128
|
-
if (!cleanupFnArray) {
|
129
|
-
cleanupFnArray = [];
|
130
|
-
fixtureCleanupFnMap.set(context.task.suite.id, cleanupFnArray);
|
131
|
-
}
|
132
125
|
const fixtures = getFixture(context);
|
133
126
|
if (!(fixtures == null ? void 0 : fixtures.length))
|
134
127
|
return fn(context);
|
@@ -232,9 +225,19 @@ function splitByComma(s) {
|
|
232
225
|
return result;
|
233
226
|
}
|
234
227
|
|
228
|
+
let _test;
|
229
|
+
function setCurrentTest(test) {
|
230
|
+
_test = test;
|
231
|
+
}
|
232
|
+
function getCurrentTest() {
|
233
|
+
return _test;
|
234
|
+
}
|
235
|
+
|
235
236
|
const suite = createSuite();
|
236
237
|
const test = createTest(
|
237
238
|
function(name, fn, options) {
|
239
|
+
if (getCurrentTest())
|
240
|
+
throw new Error("Nested tests are not allowed");
|
238
241
|
getCurrentSuite().test.fn.call(this, formatName(name), fn, options);
|
239
242
|
}
|
240
243
|
);
|
@@ -530,7 +533,6 @@ async function collectTests(paths, runner) {
|
|
530
533
|
const error = processError(e);
|
531
534
|
file.result = {
|
532
535
|
state: "fail",
|
533
|
-
error,
|
534
536
|
errors: [error]
|
535
537
|
};
|
536
538
|
}
|
@@ -542,14 +544,6 @@ async function collectTests(paths, runner) {
|
|
542
544
|
return files;
|
543
545
|
}
|
544
546
|
|
545
|
-
let _test;
|
546
|
-
function setCurrentTest(test) {
|
547
|
-
_test = test;
|
548
|
-
}
|
549
|
-
function getCurrentTest() {
|
550
|
-
return _test;
|
551
|
-
}
|
552
|
-
|
553
547
|
const now = Date.now;
|
554
548
|
function updateSuiteHookState(suite, name, state, runner) {
|
555
549
|
var _a;
|
@@ -688,6 +682,7 @@ async function runTest(test, runner) {
|
|
688
682
|
try {
|
689
683
|
await callSuiteHook(test.suite, test, "afterEach", runner, [test.context, test.suite]);
|
690
684
|
await callCleanupHooks(beforeEachCleanups);
|
685
|
+
await callFixtureCleanup();
|
691
686
|
} catch (e) {
|
692
687
|
failTask(test.result, e, runner.config.diffOptions);
|
693
688
|
}
|
@@ -706,11 +701,9 @@ async function runTest(test, runner) {
|
|
706
701
|
if (test.result.state === "pass") {
|
707
702
|
const error = processError(new Error("Expect test to fail"));
|
708
703
|
test.result.state = "fail";
|
709
|
-
test.result.error = error;
|
710
704
|
test.result.errors = [error];
|
711
705
|
} else {
|
712
706
|
test.result.state = "pass";
|
713
|
-
test.result.error = void 0;
|
714
707
|
test.result.errors = void 0;
|
715
708
|
}
|
716
709
|
}
|
@@ -728,7 +721,6 @@ function failTask(result, err, diffOptions) {
|
|
728
721
|
const errors = Array.isArray(err) ? err : [err];
|
729
722
|
for (const e of errors) {
|
730
723
|
const error = processError(e, diffOptions);
|
731
|
-
result.error ?? (result.error = error);
|
732
724
|
result.errors ?? (result.errors = []);
|
733
725
|
result.errors.push(error);
|
734
726
|
}
|
@@ -743,7 +735,7 @@ function markTasksAsSkipped(suite, runner) {
|
|
743
735
|
});
|
744
736
|
}
|
745
737
|
async function runSuite(suite, runner) {
|
746
|
-
var _a, _b, _c;
|
738
|
+
var _a, _b, _c, _d;
|
747
739
|
await ((_a = runner.onBeforeRunSuite) == null ? void 0 : _a.call(runner, suite));
|
748
740
|
if (((_b = suite.result) == null ? void 0 : _b.state) === "fail") {
|
749
741
|
markTasksAsSkipped(suite, runner);
|
@@ -788,7 +780,6 @@ async function runSuite(suite, runner) {
|
|
788
780
|
failTask(suite.result, e, runner.config.diffOptions);
|
789
781
|
}
|
790
782
|
try {
|
791
|
-
await callFixtureCleanup(suite.id);
|
792
783
|
await callSuiteHook(suite, suite, "afterAll", runner, [suite]);
|
793
784
|
await callCleanupHooks(beforeAllCleanups);
|
794
785
|
} catch (e) {
|
@@ -797,9 +788,8 @@ async function runSuite(suite, runner) {
|
|
797
788
|
if (suite.mode === "run") {
|
798
789
|
if (!hasTests(suite)) {
|
799
790
|
suite.result.state = "fail";
|
800
|
-
if (!suite.result.
|
791
|
+
if (!((_c = suite.result.errors) == null ? void 0 : _c.length)) {
|
801
792
|
const error = processError(new Error(`No test found in suite ${suite.name}`));
|
802
|
-
suite.result.error = error;
|
803
793
|
suite.result.errors = [error];
|
804
794
|
}
|
805
795
|
} else if (hasFailed(suite)) {
|
@@ -810,7 +800,7 @@ async function runSuite(suite, runner) {
|
|
810
800
|
}
|
811
801
|
updateTask(suite, runner);
|
812
802
|
suite.result.duration = now() - start;
|
813
|
-
await ((
|
803
|
+
await ((_d = runner.onAfterRunSuite) == null ? void 0 : _d.call(runner, suite));
|
814
804
|
}
|
815
805
|
}
|
816
806
|
async function runSuiteChild(c, runner) {
|
@@ -827,7 +817,6 @@ async function runFiles(files, runner) {
|
|
827
817
|
const error = processError(new Error(`No test suite found in file ${file.filepath}`));
|
828
818
|
file.result = {
|
829
819
|
state: "fail",
|
830
|
-
error,
|
831
820
|
errors: [error]
|
832
821
|
};
|
833
822
|
}
|
@@ -57,10 +57,6 @@ interface TaskResult {
|
|
57
57
|
duration?: number;
|
58
58
|
startTime?: number;
|
59
59
|
heap?: number;
|
60
|
-
/**
|
61
|
-
* @deprecated Use "errors" instead
|
62
|
-
*/
|
63
|
-
error?: ErrorWithDiff;
|
64
60
|
errors?: ErrorWithDiff[];
|
65
61
|
htmlError?: string;
|
66
62
|
hooks?: Partial<Record<keyof SuiteHooks, TaskState>>;
|
@@ -238,4 +234,4 @@ type OnTestFailedHandler = (result: TaskResult) => Awaitable<void>;
|
|
238
234
|
type SequenceHooks = 'stack' | 'list' | 'parallel';
|
239
235
|
type SequenceSetupFiles = 'list' | 'parallel';
|
240
236
|
|
241
|
-
export { Custom as C, DoneCallback as D, ExtendedContext as E, File as F, HookListener as H, InferFixturesTypes as I, OnTestFailedHandler as O, RunMode as R, Suite as S, Task as T, Test as a, ChainableFunction as b, createChainable as c, SuiteAPI as d, TestAPI as e, SuiteCollector as f, CustomAPI as g, SuiteHooks as h, TaskState as i, TaskBase as j, TaskPopulated as k, TaskMeta as l, TaskResult as m, TaskResultPack as n, TestFunction as o, TestOptions as p, Fixture as q, Fixtures as r, HookCleanupCallback as s, TaskCustomOptions as t, SuiteFactory as u, RuntimeContext as v, TestContext as w, TaskContext as x, SequenceHooks as y, SequenceSetupFiles as z };
|
237
|
+
export { 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 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 Fixture as q, type Fixtures as r, type HookCleanupCallback as s, type TaskCustomOptions as t, type SuiteFactory as u, type RuntimeContext as v, type TestContext as w, type TaskContext as x, type SequenceHooks as y, type SequenceSetupFiles as z };
|
package/dist/types.d.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
import { y as SequenceHooks, z as SequenceSetupFiles, F as File, k as TaskPopulated, S as Suite, n as TaskResultPack, a as Test, C as Custom, x as TaskContext, E as ExtendedContext } from './tasks-
|
2
|
-
export { g as CustomAPI, D as DoneCallback, q as Fixture, r as Fixtures, s as HookCleanupCallback, H as HookListener, I as InferFixturesTypes, O as OnTestFailedHandler, R as RunMode, v as RuntimeContext, d as SuiteAPI, f as SuiteCollector, u as SuiteFactory, h as SuiteHooks, T as Task, j as TaskBase, t as TaskCustomOptions, l as TaskMeta, m as TaskResult, i as TaskState, e as TestAPI, w as TestContext, o as TestFunction, p as TestOptions } from './tasks-
|
1
|
+
import { y as SequenceHooks, z as SequenceSetupFiles, F as File, k as TaskPopulated, S as Suite, n as TaskResultPack, a as Test, C as Custom, x as TaskContext, E as ExtendedContext } from './tasks-3ea70b32.js';
|
2
|
+
export { g as CustomAPI, D as DoneCallback, q as Fixture, r as Fixtures, s as HookCleanupCallback, H as HookListener, I as InferFixturesTypes, O as OnTestFailedHandler, R as RunMode, v as RuntimeContext, d as SuiteAPI, f as SuiteCollector, u as SuiteFactory, h as SuiteHooks, T as Task, j as TaskBase, t as TaskCustomOptions, l as TaskMeta, m as TaskResult, i as TaskState, e as TestAPI, w as TestContext, o as TestFunction, p as TestOptions } from './tasks-3ea70b32.js';
|
3
3
|
import '@vitest/utils';
|
4
4
|
|
5
5
|
/**
|
@@ -158,4 +158,4 @@ interface VitestRunner {
|
|
158
158
|
config: VitestRunnerConfig;
|
159
159
|
}
|
160
160
|
|
161
|
-
export { CancelReason, Custom, ExtendedContext, File, SequenceHooks, SequenceSetupFiles, Suite, TaskContext, TaskPopulated, TaskResultPack, Test, VitestRunner, VitestRunnerConfig, VitestRunnerConstructor, VitestRunnerImportSource };
|
161
|
+
export { type CancelReason, Custom, ExtendedContext, File, SequenceHooks, SequenceSetupFiles, Suite, TaskContext, TaskPopulated, 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-
|
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-3ea70b32.js';
|
2
|
+
export { b as ChainableFunction, c as createChainable } from './tasks-3ea70b32.js';
|
3
3
|
import { Arrayable } from '@vitest/utils';
|
4
4
|
|
5
5
|
/**
|
package/dist/utils.js
CHANGED
@@ -70,7 +70,6 @@ function checkAllowOnly(task, allowOnly) {
|
|
70
70
|
const error = processError(new Error("[Vitest] Unexpected .only modifier. Remove it or pass --allowOnly argument to bypass this error"));
|
71
71
|
task.result = {
|
72
72
|
state: "fail",
|
73
|
-
error,
|
74
73
|
errors: [error]
|
75
74
|
};
|
76
75
|
}
|
@@ -125,8 +124,8 @@ function isAtomTest(s) {
|
|
125
124
|
}
|
126
125
|
function getTests(suite) {
|
127
126
|
const tests = [];
|
128
|
-
const
|
129
|
-
for (const s of
|
127
|
+
const arraySuites = toArray(suite);
|
128
|
+
for (const s of arraySuites) {
|
130
129
|
if (isAtomTest(s)) {
|
131
130
|
tests.push(s);
|
132
131
|
} else {
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@vitest/runner",
|
3
3
|
"type": "module",
|
4
|
-
"version": "1.0.0-beta.
|
4
|
+
"version": "1.0.0-beta.3",
|
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": "1.0.0-beta.
|
43
|
+
"@vitest/utils": "1.0.0-beta.3"
|
44
44
|
},
|
45
45
|
"scripts": {
|
46
46
|
"build": "rimraf dist && rollup -c",
|