@vitest/runner 0.29.8 → 0.30.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.
- package/dist/chunk-tasks.js +8 -6
- package/dist/index.d.ts +15 -13
- package/dist/index.js +34 -13
- package/dist/{runner-b9659804.d.ts → runner-751eaed8.d.ts} +1 -1
- package/dist/{tasks-3fbb29e4.d.ts → tasks-c965d7f6.d.ts} +6 -31
- package/dist/types.d.ts +2 -2
- package/dist/utils.d.ts +12 -3
- package/dist/utils.js +1 -0
- package/package.json +3 -2
package/dist/chunk-tasks.js
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
import { format, deepClone, stringify, getOwnProperties, getType, toArray } from '@vitest/utils';
|
2
|
+
import { unifiedDiff } from '@vitest/utils/diff';
|
2
3
|
|
3
4
|
function partitionSuiteChildren(suite) {
|
4
5
|
let tasksGroup = [];
|
@@ -18,7 +19,9 @@ function partitionSuiteChildren(suite) {
|
|
18
19
|
|
19
20
|
const IS_RECORD_SYMBOL = "@@__IMMUTABLE_RECORD__@@";
|
20
21
|
const IS_COLLECTION_SYMBOL = "@@__IMMUTABLE_ITERABLE__@@";
|
21
|
-
|
22
|
+
function isImmutable(v) {
|
23
|
+
return v && (v[IS_COLLECTION_SYMBOL] || v[IS_RECORD_SYMBOL]);
|
24
|
+
}
|
22
25
|
const OBJECT_PROTO = Object.getPrototypeOf({});
|
23
26
|
function getUnserializableMessage(err) {
|
24
27
|
if (err instanceof Error)
|
@@ -90,13 +93,12 @@ function processError(err, options = {}) {
|
|
90
93
|
const clonedActual = deepClone(err.actual);
|
91
94
|
const clonedExpected = deepClone(err.expected);
|
92
95
|
const { replacedActual, replacedExpected } = replaceAsymmetricMatcher(clonedActual, clonedExpected);
|
93
|
-
err.actual
|
94
|
-
|
95
|
-
const maxDiffSize = options.outputDiffMaxSize ?? 1e4;
|
96
|
+
if (err.showDiff || err.showDiff === void 0 && err.expected !== void 0 && err.actual !== void 0)
|
97
|
+
err.diff = unifiedDiff(replacedActual, replacedExpected, options);
|
96
98
|
if (typeof err.expected !== "string")
|
97
|
-
err.expected = stringify(err.expected, 10
|
99
|
+
err.expected = stringify(err.expected, 10);
|
98
100
|
if (typeof err.actual !== "string")
|
99
|
-
err.actual = stringify(err.actual, 10
|
101
|
+
err.actual = stringify(err.actual, 10);
|
100
102
|
try {
|
101
103
|
if (typeof err.message === "string")
|
102
104
|
err.message = normalizeErrorMessage(err.message);
|
package/dist/index.d.ts
CHANGED
@@ -1,25 +1,27 @@
|
|
1
|
-
import { V as VitestRunner } from './runner-
|
2
|
-
export {
|
3
|
-
import { T as Task, F as File, S as SuiteAPI, a as TestAPI, b as SuiteCollector, c as SuiteHooks,
|
4
|
-
export { D as DoneCallback,
|
1
|
+
import { V as VitestRunner } from './runner-751eaed8.js';
|
2
|
+
export { a as VitestRunnerConfig, c as VitestRunnerConstructor, b as VitestRunnerImportSource } from './runner-751eaed8.js';
|
3
|
+
import { T as Task, F as File, S as SuiteAPI, a as TestAPI, b as SuiteCollector, c as SuiteHooks, O as OnTestFailedHandler, d as Test } from './tasks-c965d7f6.js';
|
4
|
+
export { D as DoneCallback, m as HookCleanupCallback, H as HookListener, R as RunMode, o as RuntimeContext, q as SequenceHooks, r as SequenceSetupFiles, j as Suite, n as SuiteFactory, f as TaskBase, g as TaskCustom, h as TaskResult, i as TaskResultPack, e as TaskState, p as TestContext, k as TestFunction, l as TestOptions } from './tasks-c965d7f6.js';
|
5
5
|
import { Awaitable } from '@vitest/utils';
|
6
6
|
|
7
7
|
declare function updateTask(task: Task, runner: VitestRunner): void;
|
8
8
|
declare function startTests(paths: string[], runner: VitestRunner): Promise<File[]>;
|
9
9
|
|
10
|
-
declare const suite: SuiteAPI
|
11
|
-
declare const test: TestAPI
|
12
|
-
declare const describe: SuiteAPI
|
13
|
-
declare const it: TestAPI
|
10
|
+
declare const suite: SuiteAPI;
|
11
|
+
declare const test: TestAPI;
|
12
|
+
declare const describe: SuiteAPI;
|
13
|
+
declare const it: TestAPI;
|
14
14
|
declare function getCurrentSuite<ExtraContext = {}>(): SuiteCollector<ExtraContext>;
|
15
15
|
|
16
|
-
declare
|
17
|
-
declare
|
18
|
-
declare
|
19
|
-
declare
|
16
|
+
declare function beforeAll(fn: SuiteHooks['beforeAll'][0], timeout?: number): void;
|
17
|
+
declare function afterAll(fn: SuiteHooks['afterAll'][0], timeout?: number): void;
|
18
|
+
declare function beforeEach<ExtraContext = {}>(fn: SuiteHooks<ExtraContext>['beforeEach'][0], timeout?: number): void;
|
19
|
+
declare function afterEach<ExtraContext = {}>(fn: SuiteHooks<ExtraContext>['afterEach'][0], timeout?: number): void;
|
20
20
|
declare const onTestFailed: (fn: OnTestFailedHandler) => void;
|
21
21
|
|
22
22
|
declare function setFn(key: Test, fn: (() => Awaitable<void>)): void;
|
23
23
|
declare function getFn<Task = Test>(key: Task): (() => Awaitable<void>);
|
24
24
|
|
25
|
-
|
25
|
+
declare function getCurrentTest(): Test<{}> | undefined;
|
26
|
+
|
27
|
+
export { File, OnTestFailedHandler, SuiteAPI, SuiteCollector, SuiteHooks, Task, Test, TestAPI, VitestRunner, afterAll, afterEach, beforeAll, beforeEach, describe, getCurrentSuite, getCurrentTest, getFn, it, onTestFailed, setFn, startTests, suite, test, updateTask };
|
package/dist/index.js
CHANGED
@@ -2,6 +2,7 @@ import limit from 'p-limit';
|
|
2
2
|
import { getSafeTimers, format, isObject, objDisplay, objectAttr, noop, toArray, shuffle } from '@vitest/utils';
|
3
3
|
import { c as createChainable, g as generateHash, p as processError, a as calculateSuiteHash, s as someTasksAreOnly, i as interpretTaskModes, b as partitionSuiteChildren, h as hasTests, d as hasFailed } from './chunk-tasks.js';
|
4
4
|
import { relative } from 'pathe';
|
5
|
+
import '@vitest/utils/diff';
|
5
6
|
|
6
7
|
const fnMap = /* @__PURE__ */ new WeakMap();
|
7
8
|
const hooksMap = /* @__PURE__ */ new WeakMap();
|
@@ -248,6 +249,7 @@ function formatTitle(template, items, idx) {
|
|
248
249
|
formatted = formatted.replace(
|
249
250
|
/\$([$\w_.]+)/g,
|
250
251
|
(_, key) => objDisplay(objectAttr(items[0], key))
|
252
|
+
// https://github.com/chaijs/chai/pull/1490
|
251
253
|
);
|
252
254
|
}
|
253
255
|
return formatted;
|
@@ -285,7 +287,7 @@ async function collectTests(paths, runner) {
|
|
285
287
|
for (const filepath of paths) {
|
286
288
|
const path = relative(config.root, filepath);
|
287
289
|
const file = {
|
288
|
-
id: generateHash(path),
|
290
|
+
id: generateHash(`${path}${config.name || ""}`),
|
289
291
|
name: path,
|
290
292
|
type: "suite",
|
291
293
|
mode: "run",
|
@@ -405,13 +407,13 @@ async function sendTasksUpdate(runner) {
|
|
405
407
|
return p;
|
406
408
|
}
|
407
409
|
}
|
408
|
-
|
410
|
+
async function callCleanupHooks(cleanups) {
|
409
411
|
await Promise.all(cleanups.map(async (fn) => {
|
410
412
|
if (typeof fn !== "function")
|
411
413
|
return;
|
412
414
|
await fn();
|
413
415
|
}));
|
414
|
-
}
|
416
|
+
}
|
415
417
|
async function runTest(test, runner) {
|
416
418
|
var _a, _b, _c, _d, _e, _f;
|
417
419
|
await ((_a = runner.onBeforeRunTest) == null ? void 0 : _a.call(runner, test));
|
@@ -443,6 +445,12 @@ async function runTest(test, runner) {
|
|
443
445
|
throw new Error("Test function is not found. Did you add it using `setFn`?");
|
444
446
|
await fn();
|
445
447
|
}
|
448
|
+
if (test.promises) {
|
449
|
+
const result = await Promise.allSettled(test.promises);
|
450
|
+
const errors = result.map((r) => r.status === "rejected" ? r.reason : void 0).filter(Boolean);
|
451
|
+
if (errors.length)
|
452
|
+
throw errors;
|
453
|
+
}
|
446
454
|
await ((_d = runner.onAfterTryTest) == null ? void 0 : _d.call(runner, test, retryCount));
|
447
455
|
test.result.state = "pass";
|
448
456
|
} catch (e) {
|
@@ -479,10 +487,13 @@ async function runTest(test, runner) {
|
|
479
487
|
}
|
480
488
|
function failTask(result, err) {
|
481
489
|
result.state = "fail";
|
482
|
-
const
|
483
|
-
|
484
|
-
|
485
|
-
|
490
|
+
const errors = Array.isArray(err) ? err : [err];
|
491
|
+
for (const e of errors) {
|
492
|
+
const error = processError(e);
|
493
|
+
result.error ?? (result.error = error);
|
494
|
+
result.errors ?? (result.errors = []);
|
495
|
+
result.errors.push(error);
|
496
|
+
}
|
486
497
|
}
|
487
498
|
function markTasksAsSkipped(suite, runner) {
|
488
499
|
suite.tasks.forEach((t) => {
|
@@ -597,11 +608,21 @@ async function startTests(paths, runner) {
|
|
597
608
|
return files;
|
598
609
|
}
|
599
610
|
|
600
|
-
|
601
|
-
|
602
|
-
|
603
|
-
|
604
|
-
|
611
|
+
function getDefaultHookTimeout() {
|
612
|
+
return getRunner().config.hookTimeout;
|
613
|
+
}
|
614
|
+
function beforeAll(fn, timeout) {
|
615
|
+
return getCurrentSuite().on("beforeAll", withTimeout(fn, timeout ?? getDefaultHookTimeout(), true));
|
616
|
+
}
|
617
|
+
function afterAll(fn, timeout) {
|
618
|
+
return getCurrentSuite().on("afterAll", withTimeout(fn, timeout ?? getDefaultHookTimeout(), true));
|
619
|
+
}
|
620
|
+
function beforeEach(fn, timeout) {
|
621
|
+
return getCurrentSuite().on("beforeEach", withTimeout(fn, timeout ?? getDefaultHookTimeout(), true));
|
622
|
+
}
|
623
|
+
function afterEach(fn, timeout) {
|
624
|
+
return getCurrentSuite().on("afterEach", withTimeout(fn, timeout ?? getDefaultHookTimeout(), true));
|
625
|
+
}
|
605
626
|
const onTestFailed = createTestHook("onTestFailed", (test, handler) => {
|
606
627
|
test.onFailed || (test.onFailed = []);
|
607
628
|
test.onFailed.push(handler);
|
@@ -615,4 +636,4 @@ function createTestHook(name, handler) {
|
|
615
636
|
};
|
616
637
|
}
|
617
638
|
|
618
|
-
export { afterAll, afterEach, beforeAll, beforeEach, describe, getCurrentSuite, getFn, it, onTestFailed, setFn, startTests, suite, test, updateTask };
|
639
|
+
export { afterAll, afterEach, beforeAll, beforeEach, describe, getCurrentSuite, getCurrentTest, getFn, it, onTestFailed, setFn, startTests, suite, test, updateTask };
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { q as SequenceHooks, r as SequenceSetupFiles, F as File,
|
1
|
+
import { q as SequenceHooks, r as SequenceSetupFiles, F as File, d as Test, j as Suite, h as TaskResult, p as TestContext } from './tasks-c965d7f6.js';
|
2
2
|
|
3
3
|
interface VitestRunnerConfig {
|
4
4
|
root: string;
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { Awaitable } from '@vitest/utils';
|
1
|
+
import { ErrorWithDiff, Awaitable } from '@vitest/utils';
|
2
2
|
|
3
3
|
type ChainableFunction<T extends string, Args extends any[], R = any, E = {}> = {
|
4
4
|
(...args: Args): R;
|
@@ -9,35 +9,6 @@ type ChainableFunction<T extends string, Args extends any[], R = any, E = {}> =
|
|
9
9
|
} & E;
|
10
10
|
declare function createChainable<T extends string, Args extends any[], R = any, E = {}>(keys: T[], fn: (this: Record<T, boolean | undefined>, ...args: Args) => R): ChainableFunction<T, Args, R, E>;
|
11
11
|
|
12
|
-
interface ParsedStack {
|
13
|
-
method: string;
|
14
|
-
file: string;
|
15
|
-
line: number;
|
16
|
-
column: number;
|
17
|
-
}
|
18
|
-
interface ErrorWithDiff extends Error {
|
19
|
-
name: string;
|
20
|
-
nameStr?: string;
|
21
|
-
stack?: string;
|
22
|
-
stackStr?: string;
|
23
|
-
stacks?: ParsedStack[];
|
24
|
-
showDiff?: boolean;
|
25
|
-
actual?: any;
|
26
|
-
expected?: any;
|
27
|
-
operator?: string;
|
28
|
-
type?: string;
|
29
|
-
frame?: string;
|
30
|
-
}
|
31
|
-
declare function serializeError(val: any, seen?: WeakMap<object, any>): any;
|
32
|
-
interface ProcessErrorOptions {
|
33
|
-
outputDiffMaxSize?: number;
|
34
|
-
}
|
35
|
-
declare function processError(err: any, options?: ProcessErrorOptions): any;
|
36
|
-
declare function replaceAsymmetricMatcher(actual: any, expected: any, actualReplaced?: WeakSet<object>, expectedReplaced?: WeakSet<object>): {
|
37
|
-
replacedActual: any;
|
38
|
-
replacedExpected: any;
|
39
|
-
};
|
40
|
-
|
41
12
|
type RunMode = 'run' | 'skip' | 'only' | 'todo';
|
42
13
|
type TaskState = RunMode | 'pass' | 'fail';
|
43
14
|
interface TaskBase {
|
@@ -88,6 +59,10 @@ interface Test<ExtraContext = {}> extends TaskBase {
|
|
88
59
|
fails?: boolean;
|
89
60
|
context: TestContext & ExtraContext;
|
90
61
|
onFailed?: OnTestFailedHandler[];
|
62
|
+
/**
|
63
|
+
* Store promises (from async expects) to wait for them before finishing the test
|
64
|
+
*/
|
65
|
+
promises?: Promise<any>[];
|
91
66
|
}
|
92
67
|
type Task = Test | Suite | TaskCustom | File;
|
93
68
|
type DoneCallback = (error?: any) => void;
|
@@ -193,4 +168,4 @@ type OnTestFailedHandler = (result: TaskResult) => Awaitable<void>;
|
|
193
168
|
type SequenceHooks = 'stack' | 'list' | 'parallel';
|
194
169
|
type SequenceSetupFiles = 'list' | 'parallel';
|
195
170
|
|
196
|
-
export { ChainableFunction as C, DoneCallback as D,
|
171
|
+
export { ChainableFunction as C, DoneCallback as D, File as F, HookListener as H, OnTestFailedHandler as O, RunMode as R, SuiteAPI as S, Task as T, TestAPI as a, SuiteCollector as b, SuiteHooks as c, Test as d, TaskState as e, TaskBase as f, TaskCustom as g, TaskResult as h, TaskResultPack as i, Suite as j, TestFunction as k, TestOptions as l, HookCleanupCallback as m, SuiteFactory as n, RuntimeContext as o, TestContext as p, SequenceHooks as q, SequenceSetupFiles as r, createChainable as s };
|
package/dist/types.d.ts
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
export { D as DoneCallback, F as File,
|
2
|
-
export { V as VitestRunner, a as VitestRunnerConfig, c as VitestRunnerConstructor, b as VitestRunnerImportSource } from './runner-
|
1
|
+
export { D as DoneCallback, F as File, m as HookCleanupCallback, H as HookListener, O as OnTestFailedHandler, R as RunMode, o as RuntimeContext, q as SequenceHooks, r as SequenceSetupFiles, j as Suite, S as SuiteAPI, b as SuiteCollector, n as SuiteFactory, c as SuiteHooks, T as Task, f as TaskBase, g as TaskCustom, h as TaskResult, i as TaskResultPack, e as TaskState, d as Test, a as TestAPI, p as TestContext, k as TestFunction, l as TestOptions } from './tasks-c965d7f6.js';
|
2
|
+
export { V as VitestRunner, a as VitestRunnerConfig, c as VitestRunnerConstructor, b as VitestRunnerImportSource } from './runner-751eaed8.js';
|
3
3
|
import '@vitest/utils';
|
package/dist/utils.d.ts
CHANGED
@@ -1,6 +1,15 @@
|
|
1
|
-
import {
|
2
|
-
export { C as ChainableFunction,
|
1
|
+
import { j as Suite, T as Task, d as Test, g as TaskCustom } from './tasks-c965d7f6.js';
|
2
|
+
export { C as ChainableFunction, s as createChainable } from './tasks-c965d7f6.js';
|
3
3
|
import { Arrayable } from '@vitest/utils';
|
4
|
+
export { ErrorWithDiff, ParsedStack } from '@vitest/utils';
|
5
|
+
import { DiffOptions } from '@vitest/utils/diff';
|
6
|
+
|
7
|
+
declare function serializeError(val: any, seen?: WeakMap<object, any>): any;
|
8
|
+
declare function processError(err: any, options?: DiffOptions): any;
|
9
|
+
declare function replaceAsymmetricMatcher(actual: any, expected: any, actualReplaced?: WeakSet<object>, expectedReplaced?: WeakSet<object>): {
|
10
|
+
replacedActual: any;
|
11
|
+
replacedExpected: any;
|
12
|
+
};
|
4
13
|
|
5
14
|
/**
|
6
15
|
* If any tasks been marked as `only`, mark all other tasks as `skip`.
|
@@ -22,4 +31,4 @@ declare function hasTests(suite: Arrayable<Suite>): boolean;
|
|
22
31
|
declare function hasFailed(suite: Arrayable<Task>): boolean;
|
23
32
|
declare function getNames(task: Task): string[];
|
24
33
|
|
25
|
-
export { calculateSuiteHash, generateHash, getNames, getSuites, getTasks, getTests, hasFailed, hasTests, interpretTaskModes, partitionSuiteChildren, someTasksAreOnly };
|
34
|
+
export { calculateSuiteHash, generateHash, getNames, getSuites, getTasks, getTests, hasFailed, hasTests, interpretTaskModes, partitionSuiteChildren, processError, replaceAsymmetricMatcher, serializeError, someTasksAreOnly };
|
package/dist/utils.js
CHANGED
@@ -1,2 +1,3 @@
|
|
1
1
|
export { a as calculateSuiteHash, c as createChainable, g as generateHash, k as getNames, j as getSuites, f as getTasks, e as getTests, d as hasFailed, h as hasTests, i as interpretTaskModes, b as partitionSuiteChildren, p as processError, r as replaceAsymmetricMatcher, l as serializeError, s as someTasksAreOnly } from './chunk-tasks.js';
|
2
2
|
import '@vitest/utils';
|
3
|
+
import '@vitest/utils/diff';
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@vitest/runner",
|
3
3
|
"type": "module",
|
4
|
-
"version": "0.
|
4
|
+
"version": "0.30.0",
|
5
5
|
"description": "Vitest test runner",
|
6
6
|
"license": "MIT",
|
7
7
|
"repository": {
|
@@ -33,9 +33,10 @@
|
|
33
33
|
"*.d.ts"
|
34
34
|
],
|
35
35
|
"dependencies": {
|
36
|
+
"concordance": "^5.0.4",
|
36
37
|
"p-limit": "^4.0.0",
|
37
38
|
"pathe": "^1.1.0",
|
38
|
-
"@vitest/utils": "0.
|
39
|
+
"@vitest/utils": "0.30.0"
|
39
40
|
},
|
40
41
|
"scripts": {
|
41
42
|
"build": "rimraf dist && rollup -c",
|