vitest 4.1.12 → 5.1.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/LICENSE.md +192 -10
- package/browser/context.d.ts +7 -1
- package/browser/context.js +5 -5
- package/config.d.ts +0 -2
- package/dist/browser.d.ts +52 -21
- package/dist/browser.js +12 -13
- package/dist/chunks/{acorn.B2iPLyUM.js → acorn.C1kjbUFw.js} +30 -30
- package/dist/chunks/{base.B6Opl8PE.js → base.Cof-UHJf.js} +81 -52
- package/dist/chunks/{browser.d.BcoexmFG.d.ts → browser.d.C7tWgUvw.d.ts} +17 -14
- package/dist/chunks/{cac.DzDtg8hz.js → cac.BYbt0aJp.js} +143 -87
- package/dist/chunks/{cli-api.B0Pz1_R7.js → cli-api.COfZo8lK.js} +7160 -7189
- package/dist/chunks/config.d.B3YV4t0O.d.ts +3873 -0
- package/dist/chunks/{console.3WNpx0tS.js → console.CQZ877Hi.js} +69 -63
- package/dist/chunks/{constants.CPYnjOGj.js → constants.DLYM6cZY.js} +2 -2
- package/dist/chunks/coverage.9iqXE2gN.js +26 -0
- package/dist/chunks/{coverage.CTzCuANN.js → coverage.jGCktcGP.js} +7 -2
- package/dist/chunks/{creator.DgVhQm5q.js → creator.DHWmytIK.js} +65 -28
- package/dist/chunks/{defaults.9aQKnqFk.js → defaults.B1FCaFfh.js} +16 -9
- package/dist/chunks/display.BlTmubjj.js +194 -0
- package/dist/chunks/doctor.B-oPbwps.js +465 -0
- package/dist/chunks/{env.D4Lgay0q.js → env.BKKtU2WC.js} +2 -1
- package/dist/chunks/{environment.d.CrsxCzP1.d.ts → environment.d.BFQtFKdZ.d.ts} +9 -1
- package/dist/chunks/globals.ZKtKSkEf.js +29 -0
- package/dist/chunks/index.Bi0NXYPf.js +1708 -0
- package/dist/chunks/{index.CMESou6r.js → index.BoyTG_B7.js} +82 -81
- package/dist/chunks/index.CZzC1gGg.js +8501 -0
- package/dist/chunks/index.D0heQG4v.js +1318 -0
- package/dist/chunks/index.Di8au7q4.js +15665 -0
- package/dist/chunks/{index.Chj8NDwU.js → index.DmDMHCg8.js} +6 -12
- package/dist/chunks/{index.DXx9Dtk7.js → index.w_oBZ9N8.js} +25 -12
- package/dist/chunks/{init-forks.H5ZuobOQ.js → init-forks.BaDXQSD8.js} +7 -10
- package/dist/chunks/{init-threads.6kl1khcL.js → init-threads.ZX_Vov0z.js} +1 -1
- package/dist/chunks/{init.k9zZ9sLh.js → init.CO4AB7HZ.js} +113 -38
- package/dist/chunks/module-dependencies._2Eei3FO.js +71 -0
- package/dist/chunks/{native.DPzPHdi5.js → native.upB-V0CK.js} +50 -37
- package/dist/chunks/{nativeModuleMocker.BkNfQMkH.js → nativeModuleMocker.Dh5azSB4.js} +48 -19
- package/dist/chunks/{index.BCY_7LL2.js → nativeModuleRunner.9xPIMzi7.js} +110 -42
- package/dist/chunks/node.B9mkVmLH.js +47 -0
- package/dist/chunks/offset.Dy-5Fdfn.js +24 -0
- package/dist/chunks/pathe.M-eThtNZ.zq3TM4NT.js +492 -0
- package/dist/chunks/{reporters.d.DtoKVV2s.d.ts → plugin.d.LRFSN46m.d.ts} +2573 -1453
- package/dist/chunks/plugins.DPQHVT0p.js +37 -0
- package/dist/chunks/rawSnapshot.DqSiqIEx.js +356 -0
- package/dist/chunks/resolver.BzpmeQeT.js +48 -0
- package/dist/chunks/rpc.Uhkwr2NM.js +93 -0
- package/dist/chunks/rpc.d.3FOhdFx8.d.ts +75 -0
- package/dist/chunks/run.CjdgFZiW.js +4231 -0
- package/dist/chunks/setup-common.CqAQCXzx.js +36 -0
- package/dist/chunks/source-map.DakdQc29.js +1788 -0
- package/dist/chunks/source-map.d.BkG8YK_3.d.ts +89 -0
- package/dist/chunks/spy.DDMXghXv.js +509 -0
- package/dist/chunks/task-utils.d.D-gFPNFi.d.ts +144 -0
- package/dist/chunks/tinyrainbow.Do8I1XRG.js +88 -0
- package/dist/chunks/{utils.BS4fH3nR.js → utils.BBk_icFG.js} +50 -52
- package/dist/chunks/{utils.BX5Fg8C4.js → utils.DYj33du9.js} +1 -17
- package/dist/chunks/vm.b4MbCAJQ.js +1329 -0
- package/dist/chunks/{worker.d.ZpHpO4yb.d.ts → worker.d.CyJRpyfZ.d.ts} +34 -19
- package/dist/cli.js +5 -6
- package/dist/config.cjs +9 -6
- package/dist/config.d.ts +27 -25
- package/dist/config.js +3 -3
- package/dist/index.d.ts +471 -38
- package/dist/index.js +18 -19
- package/dist/module-evaluator.d.ts +64 -5
- package/dist/module-evaluator.js +122 -62
- package/dist/node.d.ts +355 -87
- package/dist/node.js +49 -73
- package/dist/runtime.d.ts +43 -6
- package/dist/runtime.js +7 -9
- package/dist/spy.js +1 -1
- package/dist/task-utils.js +290 -0
- package/dist/{chunks/traces.DT5aQ62U.js → traces.js} +3 -2
- package/dist/worker.d.ts +8 -10
- package/dist/worker.js +33 -43
- package/dist/workers/forks.js +30 -40
- package/dist/workers/runVmTests.js +66 -43
- package/dist/workers/threads.js +30 -40
- package/dist/workers/vmForks.js +19 -20
- package/dist/workers/vmThreads.js +19 -20
- package/globals.d.ts +19 -19
- package/index.cjs +3 -3
- package/optional-runtime-types.d.ts +1 -1
- package/optional-types.d.ts +1 -1
- package/package.json +59 -74
- package/suppress-warnings.cjs +1 -1
- package/dist/chunks/_commonjsHelpers.D26ty3Ew.js +0 -6
- package/dist/chunks/benchmark.CX_oY03V.js +0 -40
- package/dist/chunks/benchmark.d.DAaHLpsq.d.ts +0 -24
- package/dist/chunks/config.d.A1h_Y6Jt.d.ts +0 -232
- package/dist/chunks/coverage.DM_a_rWm.js +0 -1087
- package/dist/chunks/coverage.d.BZtK59WP.d.ts +0 -37
- package/dist/chunks/evaluatedModules.Dg1zASAC.js +0 -17
- package/dist/chunks/global.d.DVsSRdQ5.d.ts +0 -100
- package/dist/chunks/globals.Dj1TGiMC.js +0 -31
- package/dist/chunks/index.DC7d2Pf8.js +0 -729
- package/dist/chunks/index.DdgEv5B1.js +0 -42
- package/dist/chunks/index.UpGiHP7g.js +0 -4255
- package/dist/chunks/index.og1WyBLx.js +0 -6358
- package/dist/chunks/nativeModuleRunner.BIakptoF.js +0 -36
- package/dist/chunks/node.COQbm6gK.js +0 -14
- package/dist/chunks/plugin.d.DwFIiJ7i.d.ts +0 -38
- package/dist/chunks/rpc.MzXet3jl.js +0 -144
- package/dist/chunks/rpc.d.B_8sPU0w.d.ts +0 -30
- package/dist/chunks/setup-common.DYx3LtFI.js +0 -60
- package/dist/chunks/startVitestModuleRunner.DB-7oCpn.js +0 -740
- package/dist/chunks/suite.d.udJtyAgw.d.ts +0 -10
- package/dist/chunks/test.DNmyFkvJ.js +0 -4430
- package/dist/chunks/traces.d.D2T_R8rx.d.ts +0 -60
- package/dist/chunks/vm.CXMd5FHa.js +0 -785
- package/dist/coverage.d.ts +0 -123
- package/dist/coverage.js +0 -27
- package/dist/environments.d.ts +0 -22
- package/dist/environments.js +0 -5
- package/dist/reporters.d.ts +0 -27
- package/dist/reporters.js +0 -26
- package/dist/runners.d.ts +0 -70
- package/dist/runners.js +0 -19
- package/dist/snapshot.d.ts +0 -9
- package/dist/snapshot.js +0 -6
- package/dist/suite.d.ts +0 -5
- package/dist/suite.js +0 -8
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
/// <reference types="chai" />
|
|
2
|
+
import { bq as SnapshotState, n as Test, br as PromisifyAssertion, bs as Tester, bt as Plugin, ae as BenchResult, a as File } from './config.d.B3YV4t0O.js';
|
|
3
|
+
|
|
4
|
+
interface SnapshotMatcher<
|
|
5
|
+
R extends void | Promise<void>,
|
|
6
|
+
T = unknown
|
|
7
|
+
> {
|
|
8
|
+
<U extends { [P in keyof T]: any }>(snapshot: Partial<U>, hint?: string): R;
|
|
9
|
+
(hint?: string): R;
|
|
10
|
+
}
|
|
11
|
+
interface InlineSnapshotMatcher<
|
|
12
|
+
R extends void | Promise<void>,
|
|
13
|
+
T = unknown
|
|
14
|
+
> {
|
|
15
|
+
<U extends { [P in keyof T]: any }>(properties: Partial<U>, snapshot?: string, hint?: string): R;
|
|
16
|
+
(hint?: string): R;
|
|
17
|
+
}
|
|
18
|
+
declare module "vitest" {
|
|
19
|
+
interface MatcherState {
|
|
20
|
+
environment: string;
|
|
21
|
+
snapshotState: SnapshotState;
|
|
22
|
+
task?: Readonly<Test>;
|
|
23
|
+
}
|
|
24
|
+
interface ExpectPollOptions {
|
|
25
|
+
interval?: number;
|
|
26
|
+
timeout?: number;
|
|
27
|
+
message?: string;
|
|
28
|
+
}
|
|
29
|
+
interface ExpectStatic {
|
|
30
|
+
assert: Chai.AssertStatic;
|
|
31
|
+
unreachable: (message?: string) => never;
|
|
32
|
+
soft: <T>(actual: T, message?: string) => Assertion<void, T>;
|
|
33
|
+
poll: <T>(actual: (options: {
|
|
34
|
+
signal: AbortSignal;
|
|
35
|
+
}) => T, options?: ExpectPollOptions) => PromisifyAssertion<Awaited<T>>;
|
|
36
|
+
addEqualityTesters: (testers: Array<Tester>) => void;
|
|
37
|
+
assertions: (expected: number) => void;
|
|
38
|
+
hasAssertions: () => void;
|
|
39
|
+
addSnapshotSerializer: (plugin: Plugin) => void;
|
|
40
|
+
}
|
|
41
|
+
interface Assertion<
|
|
42
|
+
R,
|
|
43
|
+
T
|
|
44
|
+
> {
|
|
45
|
+
matchSnapshot: SnapshotMatcher<R, T>;
|
|
46
|
+
toMatchSnapshot: SnapshotMatcher<R, T>;
|
|
47
|
+
toMatchInlineSnapshot: InlineSnapshotMatcher<R, T>;
|
|
48
|
+
/**
|
|
49
|
+
* Checks that an error thrown by a function matches a previously recorded snapshot.
|
|
50
|
+
*
|
|
51
|
+
* @param hint - Optional custom error message.
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* expect(functionWithError).toThrowErrorMatchingSnapshot();
|
|
55
|
+
*/
|
|
56
|
+
toThrowErrorMatchingSnapshot: (hint?: string) => R;
|
|
57
|
+
/**
|
|
58
|
+
* Checks that an error thrown by a function matches an inline snapshot within the test file.
|
|
59
|
+
* Useful for keeping snapshots close to the test code.
|
|
60
|
+
*
|
|
61
|
+
* @param snapshot - Optional inline snapshot string to match.
|
|
62
|
+
* @param hint - Optional custom error message.
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* const throwError = () => { throw new Error('Error occurred') };
|
|
66
|
+
* expect(throwError).toThrowErrorMatchingInlineSnapshot(`"Error occurred"`);
|
|
67
|
+
*/
|
|
68
|
+
toThrowErrorMatchingInlineSnapshot: (snapshot?: string, hint?: string) => R;
|
|
69
|
+
/**
|
|
70
|
+
* Compares the received value to a snapshot saved in a specified file.
|
|
71
|
+
* Useful for cases where snapshot content is large or needs to be shared across tests.
|
|
72
|
+
*
|
|
73
|
+
* @param filepath - Path to the snapshot file.
|
|
74
|
+
* @param hint - Optional custom error message.
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* await expect(largeData).toMatchFileSnapshot('path/to/snapshot.json');
|
|
78
|
+
*/
|
|
79
|
+
toMatchFileSnapshot: (filepath: string, hint?: string) => Promise<void>;
|
|
80
|
+
/**
|
|
81
|
+
* Asserts that a benchmark result is faster than another benchmark result.
|
|
82
|
+
* Compares mean latency — lower is faster.
|
|
83
|
+
*
|
|
84
|
+
* @example
|
|
85
|
+
* const result = await bench.compare(
|
|
86
|
+
* bench('lib1', () => { lib1() }),
|
|
87
|
+
* bench('lib2', () => { lib2() }),
|
|
88
|
+
* )
|
|
89
|
+
* expect(result.get('lib1')).toBeFasterThan(result.get('lib2'))
|
|
90
|
+
* expect(result.get('lib1')).toBeFasterThan(result.get('lib2'), { delta: 0.1 })
|
|
91
|
+
*/
|
|
92
|
+
toBeFasterThan: (expected: BenchResult, options?: {
|
|
93
|
+
delta?: number;
|
|
94
|
+
}) => R;
|
|
95
|
+
/**
|
|
96
|
+
* Asserts that a benchmark result is slower than another benchmark result.
|
|
97
|
+
* Compares mean latency — higher is slower.
|
|
98
|
+
*
|
|
99
|
+
* @example
|
|
100
|
+
* const result = await bench.compare(
|
|
101
|
+
* bench('lib1', () => { lib1() }),
|
|
102
|
+
* bench('lib2', () => { lib2() }),
|
|
103
|
+
* )
|
|
104
|
+
* expect(result.get('lib2')).toBeSlowerThan(result.get('lib1'))
|
|
105
|
+
* expect(result.get('lib2')).toBeSlowerThan(result.get('lib1'), { delta: 0.2 })
|
|
106
|
+
*/
|
|
107
|
+
toBeSlowerThan: (expected: BenchResult, options?: {
|
|
108
|
+
delta?: number;
|
|
109
|
+
}) => R;
|
|
110
|
+
/**
|
|
111
|
+
* Ensures a `vi.when` chain has been exhausted.
|
|
112
|
+
*
|
|
113
|
+
* A chain is exhausted when at least one `calledWith` with an associated action (`then*`) has been registered
|
|
114
|
+
* and every registered behavior has been fully consumed. A chain with no registered
|
|
115
|
+
* behaviors, or with `calledWith` entries that have no associated `then*` actions, is never considered exhausted.
|
|
116
|
+
*
|
|
117
|
+
* @see {@link https://vitest.dev/api/expect#tohavebeenexhausted}
|
|
118
|
+
*
|
|
119
|
+
* @example
|
|
120
|
+
* const w = vi.when(spy).calledWith('hello').thenReturnOnce('HELLO')
|
|
121
|
+
*
|
|
122
|
+
* expect(w).not.toHaveBeenExhausted()
|
|
123
|
+
*
|
|
124
|
+
* expect(spy('hello')).toBe('HELLO')
|
|
125
|
+
*
|
|
126
|
+
* expect(w).toHaveBeenExhausted()
|
|
127
|
+
*/
|
|
128
|
+
toHaveBeenExhausted: () => R;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
interface HashMeta {
|
|
133
|
+
typecheck?: boolean;
|
|
134
|
+
__vitest_label__?: string;
|
|
135
|
+
}
|
|
136
|
+
declare function createFileTask(filepath: string, root: string, projectName: string | undefined, pool?: string, viteEnvironment?: string, meta?: HashMeta): File;
|
|
137
|
+
/**
|
|
138
|
+
* Generate a unique ID for a file based on its path and project name
|
|
139
|
+
* @param file File relative to the root of the project to keep ID the same between different machines
|
|
140
|
+
* @param projectName The name of the test project
|
|
141
|
+
*/
|
|
142
|
+
declare function generateFileHash(file: string, projectName: string | undefined, meta?: HashMeta): string;
|
|
143
|
+
|
|
144
|
+
export { createFileTask as c, generateFileHash as g };
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
var d = (e) => String(e);
|
|
3
|
+
d.open = d.close = "";
|
|
4
|
+
var i = () => d, t = "\x1B[39m", o = "\x1B[49m", F = (e, r, a, n, l) => {
|
|
5
|
+
let m = "", g = 0;
|
|
6
|
+
do
|
|
7
|
+
m += e.substring(g, n) + a, g = n + l, n = e.indexOf(r, g);
|
|
8
|
+
while (~n);
|
|
9
|
+
return m + e.substring(g);
|
|
10
|
+
}, u = (e, r, a = e, n = e.length) => {
|
|
11
|
+
let l = r.length, m = (g) => {
|
|
12
|
+
let s = g + "", x = s.indexOf(r, n);
|
|
13
|
+
return ~x ? e + F(s, r, a, x, l) + r : e + s + r;
|
|
14
|
+
};
|
|
15
|
+
return m.open = e, m.close = r, m;
|
|
16
|
+
}, B = (e, r) => u(e, r, e, 5), c = (e) => {
|
|
17
|
+
let r = e.charCodeAt(0) === 35 ? e.slice(1) : e, a = parseInt(r, 16) || 0;
|
|
18
|
+
return r.length < 6 ? `${(a >> 8 & 15) * 17};${(a >> 4 & 15) * 17};${(a & 15) * 17}` : `${a >> 16 & 255};${a >> 8 & 255};${a & 255}`;
|
|
19
|
+
};
|
|
20
|
+
function y(e) {
|
|
21
|
+
let r = e ? u : i;
|
|
22
|
+
return {
|
|
23
|
+
isColorSupported: e,
|
|
24
|
+
reset: r("\x1B[0m", "\x1B[0m"),
|
|
25
|
+
bold: r("\x1B[1m", "\x1B[22m", "\x1B[22m\x1B[1m"),
|
|
26
|
+
dim: r("\x1B[2m", "\x1B[22m", "\x1B[22m\x1B[2m"),
|
|
27
|
+
italic: r("\x1B[3m", "\x1B[23m"),
|
|
28
|
+
underline: r("\x1B[4m", "\x1B[24m"),
|
|
29
|
+
inverse: r("\x1B[7m", "\x1B[27m"),
|
|
30
|
+
hidden: r("\x1B[8m", "\x1B[28m"),
|
|
31
|
+
strikethrough: r("\x1B[9m", "\x1B[29m"),
|
|
32
|
+
black: r("\x1B[30m", t),
|
|
33
|
+
red: r("\x1B[31m", t),
|
|
34
|
+
green: r("\x1B[32m", t),
|
|
35
|
+
yellow: r("\x1B[33m", t),
|
|
36
|
+
blue: r("\x1B[34m", t),
|
|
37
|
+
magenta: r("\x1B[35m", t),
|
|
38
|
+
cyan: r("\x1B[36m", t),
|
|
39
|
+
white: r("\x1B[37m", t),
|
|
40
|
+
gray: r("\x1B[90m", t),
|
|
41
|
+
bgBlack: r("\x1B[40m", o),
|
|
42
|
+
bgRed: r("\x1B[41m", o),
|
|
43
|
+
bgGreen: r("\x1B[42m", o),
|
|
44
|
+
bgYellow: r("\x1B[43m", o),
|
|
45
|
+
bgBlue: r("\x1B[44m", o),
|
|
46
|
+
bgMagenta: r("\x1B[45m", o),
|
|
47
|
+
bgCyan: r("\x1B[46m", o),
|
|
48
|
+
bgWhite: r("\x1B[47m", o),
|
|
49
|
+
blackBright: r("\x1B[90m", t),
|
|
50
|
+
redBright: r("\x1B[91m", t),
|
|
51
|
+
greenBright: r("\x1B[92m", t),
|
|
52
|
+
yellowBright: r("\x1B[93m", t),
|
|
53
|
+
blueBright: r("\x1B[94m", t),
|
|
54
|
+
magentaBright: r("\x1B[95m", t),
|
|
55
|
+
cyanBright: r("\x1B[96m", t),
|
|
56
|
+
whiteBright: r("\x1B[97m", t),
|
|
57
|
+
bgBlackBright: r("\x1B[100m", o),
|
|
58
|
+
bgRedBright: r("\x1B[101m", o),
|
|
59
|
+
bgGreenBright: r("\x1B[102m", o),
|
|
60
|
+
bgYellowBright: r("\x1B[103m", o),
|
|
61
|
+
bgBlueBright: r("\x1B[104m", o),
|
|
62
|
+
bgMagentaBright: r("\x1B[105m", o),
|
|
63
|
+
bgCyanBright: r("\x1B[106m", o),
|
|
64
|
+
bgWhiteBright: r("\x1B[107m", o),
|
|
65
|
+
rgb: e ? (n, l, m) => B(`\x1B[38;2;${n};${l};${m}m`, t) : i,
|
|
66
|
+
bgRgb: e ? (n, l, m) => B(`\x1B[48;2;${n};${l};${m}m`, o) : i,
|
|
67
|
+
hex: e ? (n) => B(`\x1B[38;2;${c(n)}m`, t) : i,
|
|
68
|
+
bgHex: e ? (n) => B(`\x1B[48;2;${c(n)}m`, o) : i
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
function f() {
|
|
72
|
+
return y(false);
|
|
73
|
+
}
|
|
74
|
+
function C() {
|
|
75
|
+
let e = typeof process != "undefined" ? process : void 0, r = (e == null ? void 0 : e.env) || {}, a = r.FORCE_TTY !== "false", n = (e == null ? void 0 : e.argv) || [];
|
|
76
|
+
return !("NO_COLOR" in r || n.includes("--no-color")) && ("FORCE_COLOR" in r || n.includes("--color") || (e == null ? void 0 : e.platform) === "win32" || a && r.TERM !== "dumb" || "CI" in r) || typeof window != "undefined" && !!window.chrome;
|
|
77
|
+
}
|
|
78
|
+
function h({ force: e } = {}) {
|
|
79
|
+
let r = e || C();
|
|
80
|
+
return y(r);
|
|
81
|
+
}
|
|
82
|
+
var b = h();
|
|
83
|
+
function w() {
|
|
84
|
+
Object.assign(b, f());
|
|
85
|
+
}
|
|
86
|
+
var $ = b;
|
|
87
|
+
|
|
88
|
+
export { $, w };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { stripVTControlCharacters } from 'node:util';
|
|
2
|
-
import {
|
|
3
|
-
import { isAbsolute, relative, dirname, basename } from 'pathe';
|
|
4
|
-
import
|
|
2
|
+
import { t as truncateString$1 } from './display.BlTmubjj.js';
|
|
3
|
+
import { i as isAbsolute, a as relative, d as dirname, b as basename, s as slash } from './pathe.M-eThtNZ.zq3TM4NT.js';
|
|
4
|
+
import { $ } from './tinyrainbow.Do8I1XRG.js';
|
|
5
5
|
|
|
6
6
|
const F_RIGHT = "→";
|
|
7
7
|
const F_DOWN = "↓";
|
|
@@ -15,20 +15,20 @@ const F_TODO = "□";
|
|
|
15
15
|
const F_TREE_NODE_MIDDLE = "├──";
|
|
16
16
|
const F_TREE_NODE_END = "└──";
|
|
17
17
|
|
|
18
|
-
const pointer =
|
|
19
|
-
const skipped =
|
|
20
|
-
const todo =
|
|
21
|
-
const benchmarkPass =
|
|
22
|
-
const testPass =
|
|
23
|
-
const taskFail =
|
|
24
|
-
const suiteFail =
|
|
25
|
-
const pending =
|
|
26
|
-
const separator =
|
|
18
|
+
const pointer = $.yellow(F_POINTER);
|
|
19
|
+
const skipped = $.dim($.gray(F_DOWN));
|
|
20
|
+
const todo = $.dim($.gray(F_TODO));
|
|
21
|
+
const benchmarkPass = $.green(F_DOT);
|
|
22
|
+
const testPass = $.green(F_CHECK);
|
|
23
|
+
const taskFail = $.red(F_CROSS);
|
|
24
|
+
const suiteFail = $.red(F_POINTER);
|
|
25
|
+
const pending = $.gray("·");
|
|
26
|
+
const separator = $.dim(" > ");
|
|
27
27
|
const labelDefaultColors = [
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
28
|
+
$.bgYellow,
|
|
29
|
+
$.bgCyan,
|
|
30
|
+
$.bgGreen,
|
|
31
|
+
$.bgMagenta
|
|
32
32
|
];
|
|
33
33
|
function getCols(delta = 0) {
|
|
34
34
|
let length = process.stdout?.columns;
|
|
@@ -36,7 +36,7 @@ function getCols(delta = 0) {
|
|
|
36
36
|
return Math.max(length + delta, 0);
|
|
37
37
|
}
|
|
38
38
|
function errorBanner(message) {
|
|
39
|
-
return divider(
|
|
39
|
+
return divider($.bold($.bgRed(` ${message} `)), null, null, $.red);
|
|
40
40
|
}
|
|
41
41
|
function divider(text, left, right, color) {
|
|
42
42
|
const cols = getCols();
|
|
@@ -59,28 +59,30 @@ function formatTestPath(root, path) {
|
|
|
59
59
|
const dir = dirname(path);
|
|
60
60
|
const ext = path.match(/(\.(spec|test)\.[cm]?[tj]sx?)$/)?.[0] || "";
|
|
61
61
|
const base = basename(path, ext);
|
|
62
|
-
return slash(
|
|
62
|
+
return slash($.dim(`${dir}/`) + $.bold(base)) + $.dim(ext);
|
|
63
63
|
}
|
|
64
64
|
function renderSnapshotSummary(rootDir, snapshots) {
|
|
65
65
|
const summary = [];
|
|
66
|
-
if (snapshots.added) summary.push(
|
|
67
|
-
if (snapshots.unmatched) summary.push(
|
|
68
|
-
if (snapshots.updated) summary.push(
|
|
69
|
-
if (snapshots.filesRemoved)
|
|
70
|
-
|
|
66
|
+
if (snapshots.added) summary.push($.bold($.green(`${snapshots.added} written`)));
|
|
67
|
+
if (snapshots.unmatched) summary.push($.bold($.red(`${snapshots.unmatched} failed`)));
|
|
68
|
+
if (snapshots.updated) summary.push($.bold($.green(`${snapshots.updated} updated `)));
|
|
69
|
+
if (snapshots.filesRemoved) {
|
|
70
|
+
if (snapshots.didUpdate) summary.push($.bold($.green(`${snapshots.filesRemoved} files removed `)));
|
|
71
|
+
else summary.push($.bold($.yellow(`${snapshots.filesRemoved} files obsolete `)));
|
|
72
|
+
}
|
|
71
73
|
if (snapshots.filesRemovedList && snapshots.filesRemovedList.length) {
|
|
72
74
|
const [head, ...tail] = snapshots.filesRemovedList;
|
|
73
|
-
summary.push(`${
|
|
75
|
+
summary.push(`${$.gray(F_DOWN_RIGHT)} ${formatTestPath(rootDir, head)}`);
|
|
74
76
|
tail.forEach((key) => {
|
|
75
|
-
summary.push(` ${
|
|
77
|
+
summary.push(` ${$.gray(F_DOT)} ${formatTestPath(rootDir, key)}`);
|
|
76
78
|
});
|
|
77
79
|
}
|
|
78
80
|
if (snapshots.unchecked) {
|
|
79
|
-
if (snapshots.didUpdate) summary.push(
|
|
80
|
-
else summary.push(
|
|
81
|
+
if (snapshots.didUpdate) summary.push($.bold($.green(`${snapshots.unchecked} removed`)));
|
|
82
|
+
else summary.push($.bold($.yellow(`${snapshots.unchecked} obsolete`)));
|
|
81
83
|
snapshots.uncheckedKeysByFile.forEach((uncheckedFile) => {
|
|
82
|
-
summary.push(`${
|
|
83
|
-
uncheckedFile.keys.forEach((key) => summary.push(` ${
|
|
84
|
+
summary.push(`${$.gray(F_DOWN_RIGHT)} ${formatTestPath(rootDir, uncheckedFile.filePath)}`);
|
|
85
|
+
uncheckedFile.keys.forEach((key) => summary.push(` ${$.gray(F_DOT)} ${key}`));
|
|
84
86
|
});
|
|
85
87
|
}
|
|
86
88
|
return summary;
|
|
@@ -89,7 +91,7 @@ function countTestErrors(tasks) {
|
|
|
89
91
|
return tasks.reduce((c, i) => c + (i.result?.errors?.length || 0), 0);
|
|
90
92
|
}
|
|
91
93
|
function getStateString(tasks, name = "tests", showTotal = true) {
|
|
92
|
-
if (tasks.length === 0) return
|
|
94
|
+
if (tasks.length === 0) return $.dim(`no ${name}`);
|
|
93
95
|
const passed = tasks.reduce((acc, i) => {
|
|
94
96
|
// Exclude expected failures from passed count
|
|
95
97
|
if (i.result?.state === "pass" && i.type === "test" && i.fails) return acc;
|
|
@@ -104,12 +106,12 @@ function getStateString(tasks, name = "tests", showTotal = true) {
|
|
|
104
106
|
return acc;
|
|
105
107
|
}, 0);
|
|
106
108
|
return [
|
|
107
|
-
failed ?
|
|
108
|
-
passed ?
|
|
109
|
-
expectedFail ?
|
|
110
|
-
skipped ?
|
|
111
|
-
todo ?
|
|
112
|
-
].filter(Boolean).join(
|
|
109
|
+
failed ? $.bold($.red(`${failed} failed`)) : null,
|
|
110
|
+
passed ? $.bold($.green(`${passed} passed`)) : null,
|
|
111
|
+
expectedFail ? $.cyan(`${expectedFail} expected fail`) : null,
|
|
112
|
+
skipped ? $.yellow(`${skipped} skipped`) : null,
|
|
113
|
+
todo ? $.gray(`${todo} todo`) : null
|
|
114
|
+
].filter(Boolean).join($.dim(" | ")) + (showTotal ? $.gray(` (${tasks.length})`) : "");
|
|
113
115
|
}
|
|
114
116
|
function getStateSymbol(task) {
|
|
115
117
|
if (task.mode === "todo") return todo;
|
|
@@ -131,22 +133,25 @@ function formatTime(time) {
|
|
|
131
133
|
}
|
|
132
134
|
function formatProjectName(project, suffix = " ") {
|
|
133
135
|
if (!project?.name) return "";
|
|
134
|
-
if (
|
|
135
|
-
let background = project.color &&
|
|
136
|
-
if (!background)
|
|
137
|
-
|
|
136
|
+
if (!$.isColorSupported) return `|${project.name}|${suffix}`;
|
|
137
|
+
let background = project.color && $[`bg${capitalize(project.color)}`];
|
|
138
|
+
if (!background) {
|
|
139
|
+
const index = project.name.split("").reduce((acc, v, idx) => acc + v.charCodeAt(0) + idx, 0);
|
|
140
|
+
background = labelDefaultColors[index % labelDefaultColors.length];
|
|
141
|
+
}
|
|
142
|
+
return $.black(background(` ${project.name} `)) + suffix;
|
|
138
143
|
}
|
|
139
144
|
function withLabel(color, label, message) {
|
|
140
145
|
const bgColor = `bg${color.charAt(0).toUpperCase()}${color.slice(1)}`;
|
|
141
|
-
return `${
|
|
146
|
+
return `${$.bold($.black($[bgColor](` ${label} `)))} ${message ? $[color](message) : ""}`;
|
|
142
147
|
}
|
|
143
148
|
function padSummaryTitle(str) {
|
|
144
|
-
return
|
|
149
|
+
return $.dim(`${str.padStart(11)} `);
|
|
145
150
|
}
|
|
146
151
|
function truncateString(text, maxLength) {
|
|
147
152
|
const plainText = stripVTControlCharacters(text);
|
|
148
153
|
if (plainText.length <= maxLength) return text;
|
|
149
|
-
return
|
|
154
|
+
return truncateString$1(plainText, maxLength);
|
|
150
155
|
}
|
|
151
156
|
function capitalize(text) {
|
|
152
157
|
return `${text[0].toUpperCase()}${text.slice(1)}`;
|
|
@@ -161,29 +166,22 @@ function noun(count, singular, plural) {
|
|
|
161
166
|
|
|
162
167
|
var utils = /*#__PURE__*/Object.freeze({
|
|
163
168
|
__proto__: null,
|
|
164
|
-
benchmarkPass: benchmarkPass,
|
|
165
169
|
countTestErrors: countTestErrors,
|
|
166
170
|
divider: divider,
|
|
167
171
|
errorBanner: errorBanner,
|
|
168
172
|
formatProjectName: formatProjectName,
|
|
169
|
-
formatTestPath: formatTestPath,
|
|
170
173
|
formatTime: formatTime,
|
|
171
174
|
formatTimeString: formatTimeString,
|
|
175
|
+
getCols: getCols,
|
|
172
176
|
getStateString: getStateString,
|
|
173
177
|
getStateSymbol: getStateSymbol,
|
|
174
178
|
noun: noun,
|
|
175
179
|
padSummaryTitle: padSummaryTitle,
|
|
176
|
-
pending: pending,
|
|
177
|
-
pointer: pointer,
|
|
178
180
|
renderSnapshotSummary: renderSnapshotSummary,
|
|
179
181
|
separator: separator,
|
|
180
|
-
skipped: skipped,
|
|
181
|
-
suiteFail: suiteFail,
|
|
182
182
|
taskFail: taskFail,
|
|
183
|
-
testPass: testPass,
|
|
184
|
-
todo: todo,
|
|
185
183
|
truncateString: truncateString,
|
|
186
184
|
withLabel: withLabel
|
|
187
185
|
});
|
|
188
186
|
|
|
189
|
-
export {
|
|
187
|
+
export { F_TREE_NODE_MIDDLE as F, F_TREE_NODE_END as a, F_CHECK as b, F_POINTER as c, F_DOWN_RIGHT as d, formatProjectName as e, formatTimeString as f, getStateSymbol as g, getStateString as h, formatTime as i, countTestErrors as j, errorBanner as k, divider as l, F_RIGHT as m, noun as n, getCols as o, padSummaryTitle as p, truncateString as q, renderSnapshotSummary as r, separator as s, taskFail as t, utils as u, withLabel as w };
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { getSafeTimers } from '@vitest/utils/timers';
|
|
2
|
-
|
|
3
1
|
const NAME_WORKER_STATE = "__vitest_worker__";
|
|
4
2
|
class EnvironmentTeardownError extends Error {
|
|
5
3
|
name = "EnvironmentTeardownError";
|
|
@@ -41,19 +39,5 @@ function resetModules(modules, resetMocks = false) {
|
|
|
41
39
|
node.importers.clear();
|
|
42
40
|
});
|
|
43
41
|
}
|
|
44
|
-
function waitNextTick() {
|
|
45
|
-
const { setTimeout } = getSafeTimers();
|
|
46
|
-
return new Promise((resolve) => setTimeout(resolve, 0));
|
|
47
|
-
}
|
|
48
|
-
async function waitForImportsToResolve() {
|
|
49
|
-
await waitNextTick();
|
|
50
|
-
const state = getWorkerState();
|
|
51
|
-
const promises = [];
|
|
52
|
-
const resolvingCount = state.resolvingModules.size;
|
|
53
|
-
for (const [_, mod] of state.evaluatedModules.idToModuleMap) if (mod.promise && !mod.evaluated) promises.push(mod.promise);
|
|
54
|
-
if (!promises.length && !resolvingCount) return;
|
|
55
|
-
await Promise.allSettled(promises);
|
|
56
|
-
await waitForImportsToResolve();
|
|
57
|
-
}
|
|
58
42
|
|
|
59
|
-
export { EnvironmentTeardownError as E, getSafeWorkerState as a, getWorkerState as g, isChildProcess as i, provideWorkerState as p, resetModules as r
|
|
43
|
+
export { EnvironmentTeardownError as E, getSafeWorkerState as a, getWorkerState as g, isChildProcess as i, provideWorkerState as p, resetModules as r };
|