vitest 2.1.3 → 2.1.5
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 +1 -209
- package/dist/browser.d.ts +24 -24
- package/dist/browser.js +7 -7
- package/dist/chunks/{RandomSequencer.Bh5-tlNJ.js → RandomSequencer.CMRlh2v4.js} +143 -142
- package/dist/chunks/{base.BO5Jx7vw.js → base.BZZh4cSm.js} +3 -3
- package/dist/chunks/{benchmark.C8CRJYG4.js → benchmark.Cdu9hjj4.js} +2 -2
- package/dist/chunks/{benchmark.JVlTzojj.d.ts → benchmark.geERunq4.d.ts} +1 -1
- package/dist/chunks/{cac.BSMVokHR.js → cac.DWAW3Uh5.js} +11 -10
- package/dist/chunks/{cli-api.btGgw3PC.js → cli-api.BtqJwSCh.js} +828 -644
- package/dist/chunks/{config.Crbj2GAb.d.ts → config.Cy0C388Z.d.ts} +0 -1
- package/dist/chunks/{console.CfT1Wjed.js → console.BYGVloWk.js} +2 -6
- package/dist/chunks/{coverage.zlNdAMHK.js → coverage.BoMDb1ip.js} +1 -1
- package/dist/chunks/{creator.CBPphXqR.js → creator.IIqd8RWT.js} +8 -8
- package/dist/chunks/{execute._eQQfgI8.js → execute.2pr0rHgK.js} +8 -6
- package/dist/chunks/{globals.Bdzt04Qm.js → globals.D8ZVAdXd.js} +8 -13
- package/dist/chunks/{index.BpSiYbpB.js → index.68735LiX.js} +28 -5
- package/dist/chunks/{index.X0nbfr6-.js → index.BJDntFik.js} +7 -7
- package/dist/chunks/{index.CPD77dLA.js → index.CqYx2Nsr.js} +7 -7
- package/dist/chunks/{index.Dz2opmmU.js → index.DsZFoqi9.js} +3711 -3788
- package/dist/chunks/{index.lVXYBqEP.js → index.K90BXFOx.js} +186 -186
- package/dist/chunks/index.ckWaX2gY.js +54 -0
- package/dist/chunks/{index.4GFF2h22.js → index.nEwtF0bu.js} +6 -6
- package/dist/chunks/{node.Bx4JZjMG.js → node.AKq966Jp.js} +1 -5
- package/dist/chunks/{reporters.C4ZHgdxQ.d.ts → reporters.D7Jzd9GS.d.ts} +1246 -1221
- package/dist/chunks/{resolveConfig.Dha6ilPI.js → resolveConfig.RxKrDli4.js} +3196 -3176
- package/dist/chunks/{rpc.B7Mfb-Yf.js → rpc.C3q9uwRX.js} +2 -2
- package/dist/chunks/{run-once.Sxe67Wng.js → run-once.2ogXb3JV.js} +1 -1
- package/dist/chunks/{runBaseTests.Cx4wXyTR.js → runBaseTests.3qpJUEJM.js} +21 -25
- package/dist/chunks/{setup-common.BKyF15v_.js → setup-common.Dj6BZI3u.js} +3 -3
- package/dist/chunks/{suite.BMWOKiTe.d.ts → suite.B2jumIFP.d.ts} +2 -2
- package/dist/chunks/utils.C8RiOc4B.js +77 -0
- package/dist/chunks/{utils.CY6Spixo.js → utils.DNoFbBUZ.js} +7 -3
- package/dist/chunks/{vi.BskyZC5g.js → vi.DgezovHB.js} +177 -142
- package/dist/chunks/{vite.YH7MrecS.d.ts → vite.C-N5BBZe.d.ts} +1 -1
- package/dist/chunks/{vm.DB_hLchi.js → vm.Zr4qWzDJ.js} +8 -8
- package/dist/chunks/{worker.CcJLfX8w.d.ts → worker.B9FxPCaC.d.ts} +1 -1
- package/dist/chunks/{worker.B6RjTtbk.d.ts → worker.tN5KGIih.d.ts} +14 -4
- package/dist/cli.js +3 -4
- package/dist/config.cjs +4 -4
- package/dist/config.d.ts +11 -11
- package/dist/config.js +4 -4
- package/dist/coverage.d.ts +10 -10
- package/dist/coverage.js +8 -11
- package/dist/environments.d.ts +2 -2
- package/dist/environments.js +1 -1
- package/dist/execute.d.ts +54 -54
- package/dist/execute.js +7 -6
- package/dist/index.d.ts +106 -1101
- package/dist/index.js +7 -18
- package/dist/node.d.ts +44 -42
- package/dist/node.js +23 -29
- package/dist/path.js +1 -1
- package/dist/reporters.d.ts +10 -10
- package/dist/reporters.js +12 -18
- package/dist/runners.d.ts +12 -19
- package/dist/runners.js +142 -148
- package/dist/snapshot.js +2 -6
- package/dist/suite.d.ts +2 -2
- package/dist/suite.js +2 -6
- package/dist/worker.js +10 -7
- package/dist/workers/forks.js +9 -8
- package/dist/workers/runVmTests.js +16 -20
- package/dist/workers/threads.js +9 -8
- package/dist/workers/vmForks.js +9 -12
- package/dist/workers/vmThreads.js +9 -12
- package/dist/workers.d.ts +14 -14
- package/dist/workers.js +15 -18
- package/package.json +27 -27
- package/dist/chunks/base.DwXGwWst.js +0 -89
- package/dist/chunks/env.CmHVDJnw.js +0 -7
- package/dist/chunks/index.-d_XpZEA.js +0 -140
- package/dist/chunks/index.CxRxs566.js +0 -23
- package/dist/chunks/tasks.BZnCS9aT.js +0 -18
- package/dist/chunks/utils.Ck2hJTRs.js +0 -23
- package/dist/chunks/{environment.CzISCQ7o.d.ts → environment.LoooBwUu.d.ts} +24 -24
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { getSafeTimers } from '@vitest/utils';
|
|
2
|
-
import { c as createBirpc } from './index.
|
|
3
|
-
import { g as getWorkerState } from './utils.
|
|
2
|
+
import { c as createBirpc } from './index.68735LiX.js';
|
|
3
|
+
import { g as getWorkerState } from './utils.C8RiOc4B.js';
|
|
4
4
|
|
|
5
5
|
const { get } = Reflect;
|
|
6
6
|
function withSafeTimers(fn) {
|
|
@@ -1,39 +1,35 @@
|
|
|
1
1
|
import { performance } from 'node:perf_hooks';
|
|
2
2
|
import { startTests, collectTests } from '@vitest/runner';
|
|
3
|
-
import '
|
|
4
|
-
import '
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import './env.CmHVDJnw.js';
|
|
8
|
-
import { a as globalExpect, r as resetModules, v as vi } from './vi.BskyZC5g.js';
|
|
9
|
-
import { a as startCoverageInsideWorker, s as stopCoverageInsideWorker } from './coverage.zlNdAMHK.js';
|
|
10
|
-
import { a as resolveSnapshotEnvironment, s as setupChaiConfig, r as resolveTestRunner } from './index.4GFF2h22.js';
|
|
3
|
+
import { a as resolveSnapshotEnvironment, s as setupChaiConfig, r as resolveTestRunner } from './index.nEwtF0bu.js';
|
|
4
|
+
import { s as startCoverageInsideWorker, a as stopCoverageInsideWorker } from './coverage.BoMDb1ip.js';
|
|
5
|
+
import { a as globalExpect, v as vi } from './vi.DgezovHB.js';
|
|
6
|
+
import { c as closeInspector } from './inspector.70d6emsh.js';
|
|
11
7
|
import { createRequire } from 'node:module';
|
|
12
|
-
import util from 'node:util';
|
|
13
8
|
import timers from 'node:timers';
|
|
14
|
-
import
|
|
9
|
+
import util from 'node:util';
|
|
10
|
+
import { getSafeTimers } from '@vitest/utils';
|
|
15
11
|
import { KNOWN_ASSET_TYPES } from 'vite-node/constants';
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
19
|
-
import '
|
|
12
|
+
import { installSourcemapsSupport } from 'vite-node/source-map';
|
|
13
|
+
import { V as VitestIndex } from './index.ckWaX2gY.js';
|
|
14
|
+
import { s as setupCommonEnv } from './setup-common.Dj6BZI3u.js';
|
|
15
|
+
import { g as getWorkerState, r as resetModules } from './utils.C8RiOc4B.js';
|
|
20
16
|
import 'chai';
|
|
21
|
-
import '
|
|
17
|
+
import 'node:path';
|
|
18
|
+
import '../path.js';
|
|
19
|
+
import 'node:url';
|
|
20
|
+
import './rpc.C3q9uwRX.js';
|
|
21
|
+
import './index.68735LiX.js';
|
|
22
22
|
import '@vitest/expect';
|
|
23
|
+
import '@vitest/runner/utils';
|
|
24
|
+
import './_commonjsHelpers.BFTU3MAI.js';
|
|
23
25
|
import '@vitest/snapshot';
|
|
24
26
|
import '@vitest/utils/error';
|
|
25
|
-
import './tasks.BZnCS9aT.js';
|
|
26
27
|
import '@vitest/utils/source-map';
|
|
27
|
-
import './base.DwXGwWst.js';
|
|
28
28
|
import './date.W2xKR2qe.js';
|
|
29
29
|
import '@vitest/spy';
|
|
30
|
-
import '
|
|
31
|
-
import '
|
|
32
|
-
import '
|
|
33
|
-
import './index.BpSiYbpB.js';
|
|
34
|
-
import './benchmark.C8CRJYG4.js';
|
|
35
|
-
import './index.CxRxs566.js';
|
|
36
|
-
import './run-once.Sxe67Wng.js';
|
|
30
|
+
import './run-once.2ogXb3JV.js';
|
|
31
|
+
import './benchmark.Cdu9hjj4.js';
|
|
32
|
+
import 'expect-type';
|
|
37
33
|
|
|
38
34
|
let globalSetup = false;
|
|
39
35
|
async function setupGlobalEnv(config, { environment }, executor) {
|
|
@@ -81,7 +77,7 @@ function resolveAsset(mod, url) {
|
|
|
81
77
|
mod.exports = url;
|
|
82
78
|
}
|
|
83
79
|
async function setupConsoleLogSpy() {
|
|
84
|
-
const { createCustomConsole } = await import('./console.
|
|
80
|
+
const { createCustomConsole } = await import('./console.BYGVloWk.js');
|
|
85
81
|
globalThis.console = createCustomConsole();
|
|
86
82
|
}
|
|
87
83
|
async function withEnv({ environment }, options, fn) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { setSafeTimers } from '@vitest/utils';
|
|
2
1
|
import { addSerializer } from '@vitest/snapshot';
|
|
3
|
-
import {
|
|
2
|
+
import { setSafeTimers } from '@vitest/utils';
|
|
3
|
+
import { r as resetRunOnceCounter } from './run-once.2ogXb3JV.js';
|
|
4
4
|
|
|
5
5
|
let globalSetup = false;
|
|
6
6
|
async function setupCommonEnv(config) {
|
|
@@ -13,7 +13,7 @@ async function setupCommonEnv(config) {
|
|
|
13
13
|
globalSetup = true;
|
|
14
14
|
setSafeTimers();
|
|
15
15
|
if (config.globals) {
|
|
16
|
-
(await import('./globals.
|
|
16
|
+
(await import('./globals.D8ZVAdXd.js')).registerApiGlobally();
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
19
|
function setupDefines(defines) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Custom } from '@vitest/runner';
|
|
2
|
-
import '
|
|
3
|
-
import { b as BenchFunction, c as BenchmarkAPI } from './benchmark.JVlTzojj.js';
|
|
2
|
+
import { a as BenchFunction, c as BenchmarkAPI } from './benchmark.geERunq4.js';
|
|
4
3
|
import { Options } from 'tinybench';
|
|
4
|
+
import '@vitest/runner/utils';
|
|
5
5
|
|
|
6
6
|
declare function getBenchOptions(key: Custom): Options;
|
|
7
7
|
declare function getBenchFn(key: Custom): BenchFunction;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { getSafeTimers } from '@vitest/utils';
|
|
2
|
+
|
|
3
|
+
const NAME_WORKER_STATE = "__vitest_worker__";
|
|
4
|
+
function getWorkerState() {
|
|
5
|
+
const workerState = globalThis[NAME_WORKER_STATE];
|
|
6
|
+
if (!workerState) {
|
|
7
|
+
const errorMsg = 'Vitest failed to access its internal state.\n\nOne of the following is possible:\n- "vitest" is imported directly without running "vitest" command\n- "vitest" is imported inside "globalSetup" (to fix this, use "setupFiles" instead, because "globalSetup" runs in a different context)\n- Otherwise, it might be a Vitest bug. Please report it to https://github.com/vitest-dev/vitest/issues\n';
|
|
8
|
+
throw new Error(errorMsg);
|
|
9
|
+
}
|
|
10
|
+
return workerState;
|
|
11
|
+
}
|
|
12
|
+
function provideWorkerState(context, state) {
|
|
13
|
+
Object.defineProperty(context, NAME_WORKER_STATE, {
|
|
14
|
+
value: state,
|
|
15
|
+
configurable: true,
|
|
16
|
+
writable: true,
|
|
17
|
+
enumerable: false
|
|
18
|
+
});
|
|
19
|
+
return state;
|
|
20
|
+
}
|
|
21
|
+
function getCurrentEnvironment() {
|
|
22
|
+
const state = getWorkerState();
|
|
23
|
+
return state?.environment.name;
|
|
24
|
+
}
|
|
25
|
+
function isChildProcess() {
|
|
26
|
+
return typeof process !== "undefined" && !!process.send;
|
|
27
|
+
}
|
|
28
|
+
function setProcessTitle(title) {
|
|
29
|
+
try {
|
|
30
|
+
process.title = `node (${title})`;
|
|
31
|
+
} catch {
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
function resetModules(modules, resetMocks = false) {
|
|
35
|
+
const skipPaths = [
|
|
36
|
+
// Vitest
|
|
37
|
+
/\/vitest\/dist\//,
|
|
38
|
+
/\/vite-node\/dist\//,
|
|
39
|
+
// yarn's .store folder
|
|
40
|
+
/vitest-virtual-\w+\/dist/,
|
|
41
|
+
// cnpm
|
|
42
|
+
/@vitest\/dist/,
|
|
43
|
+
// don't clear mocks
|
|
44
|
+
...!resetMocks ? [/^mock:/] : []
|
|
45
|
+
];
|
|
46
|
+
modules.forEach((mod, path) => {
|
|
47
|
+
if (skipPaths.some((re) => re.test(path))) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
modules.invalidateModule(mod);
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
function waitNextTick() {
|
|
54
|
+
const { setTimeout } = getSafeTimers();
|
|
55
|
+
return new Promise((resolve) => setTimeout(resolve, 0));
|
|
56
|
+
}
|
|
57
|
+
async function waitForImportsToResolve() {
|
|
58
|
+
await waitNextTick();
|
|
59
|
+
const state = getWorkerState();
|
|
60
|
+
const promises = [];
|
|
61
|
+
let resolvingCount = 0;
|
|
62
|
+
for (const mod of state.moduleCache.values()) {
|
|
63
|
+
if (mod.promise && !mod.evaluated) {
|
|
64
|
+
promises.push(mod.promise);
|
|
65
|
+
}
|
|
66
|
+
if (mod.resolving) {
|
|
67
|
+
resolvingCount++;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
if (!promises.length && !resolvingCount) {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
await Promise.allSettled(promises);
|
|
74
|
+
await waitForImportsToResolve();
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export { getCurrentEnvironment as a, getWorkerState as g, isChildProcess as i, provideWorkerState as p, resetModules as r, setProcessTitle as s, waitForImportsToResolve as w };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { stripVTControlCharacters } from 'node:util';
|
|
2
|
+
import { slash } from '@vitest/utils';
|
|
2
3
|
import { isAbsolute, relative, dirname, basename } from 'pathe';
|
|
3
4
|
import c from 'tinyrainbow';
|
|
4
|
-
import { a as slash } from './base.DwXGwWst.js';
|
|
5
5
|
|
|
6
6
|
const F_RIGHT = "\u2192";
|
|
7
7
|
const F_DOWN = "\u2193";
|
|
@@ -179,6 +179,9 @@ function formatProjectName(name, suffix = " ") {
|
|
|
179
179
|
const colors = [c.blue, c.yellow, c.cyan, c.green, c.magenta];
|
|
180
180
|
return colors[index % colors.length](`|${name}|`) + suffix;
|
|
181
181
|
}
|
|
182
|
+
function withLabel(color, label, message) {
|
|
183
|
+
return `${c.bold(c.inverse(c[color](` ${label} `)))} ${c[color](message)}`;
|
|
184
|
+
}
|
|
182
185
|
|
|
183
186
|
var utils = /*#__PURE__*/Object.freeze({
|
|
184
187
|
__proto__: null,
|
|
@@ -202,7 +205,8 @@ var utils = /*#__PURE__*/Object.freeze({
|
|
|
202
205
|
spinnerMap: spinnerMap,
|
|
203
206
|
suiteFail: suiteFail,
|
|
204
207
|
taskFail: taskFail,
|
|
205
|
-
testPass: testPass
|
|
208
|
+
testPass: testPass,
|
|
209
|
+
withLabel: withLabel
|
|
206
210
|
});
|
|
207
211
|
|
|
208
|
-
export {
|
|
212
|
+
export { F_POINTER as F, formatTimeString as a, F_RIGHT as b, F_CHECK as c, divider as d, getStateString as e, formatProjectName as f, getStateSymbol as g, countTestErrors as h, getCols as i, getHookStateSymbol as j, renderSnapshotSummary as r, taskFail as t, utils as u, withLabel as w };
|
|
@@ -1,61 +1,140 @@
|
|
|
1
|
+
import { equals, iterableEquality, subsetEquality, JestExtend, JestChaiExpect, JestAsymmetricMatchers, GLOBAL_EXPECT, ASYMMETRIC_MATCHERS_OBJECT, getState, setState, addCustomEqualityTesters } from '@vitest/expect';
|
|
2
|
+
import { getCurrentTest } from '@vitest/runner';
|
|
3
|
+
import { getNames, getTestName } from '@vitest/runner/utils';
|
|
1
4
|
import * as chai$1 from 'chai';
|
|
5
|
+
import { g as getWorkerState, a as getCurrentEnvironment, i as isChildProcess, r as resetModules, w as waitForImportsToResolve } from './utils.C8RiOc4B.js';
|
|
6
|
+
import { getSafeTimers, assertTypes, createSimpleStackTrace } from '@vitest/utils';
|
|
2
7
|
import { g as getDefaultExportFromCjs, c as commonjsGlobal } from './_commonjsHelpers.BFTU3MAI.js';
|
|
3
|
-
import { equals, iterableEquality, subsetEquality, JestExtend, JestChaiExpect, JestAsymmetricMatchers, GLOBAL_EXPECT, ASYMMETRIC_MATCHERS_OBJECT, getState, setState, addCustomEqualityTesters } from '@vitest/expect';
|
|
4
8
|
import { stripSnapshotIndentation, addSerializer, SnapshotClient } from '@vitest/snapshot';
|
|
5
|
-
import { getNames } from '@vitest/runner/utils';
|
|
6
9
|
import '@vitest/utils/error';
|
|
7
|
-
import { getCurrentTest } from '@vitest/runner';
|
|
8
|
-
import { g as getTestName } from './tasks.BZnCS9aT.js';
|
|
9
|
-
import { g as getWorkerState, a as getCurrentEnvironment } from './utils.Ck2hJTRs.js';
|
|
10
|
-
import { getSafeTimers, assertTypes, createSimpleStackTrace } from '@vitest/utils';
|
|
11
|
-
import 'pathe';
|
|
12
|
-
import './env.CmHVDJnw.js';
|
|
13
10
|
import { parseSingleStack } from '@vitest/utils/source-map';
|
|
14
|
-
import { i as isChildProcess } from './base.DwXGwWst.js';
|
|
15
11
|
import { R as RealDate, r as resetDate, m as mockDate } from './date.W2xKR2qe.js';
|
|
16
12
|
import { spyOn, fn, isMockFunction, mocks } from '@vitest/spy';
|
|
17
13
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
14
|
+
const unsupported = [
|
|
15
|
+
// .poll is meant to retry matchers until they succeed, and
|
|
16
|
+
// snapshots will always succeed as long as the poll method doesn't thow an error
|
|
17
|
+
// in this case using the `vi.waitFor` method is more appropriate
|
|
18
|
+
"matchSnapshot",
|
|
19
|
+
"toMatchSnapshot",
|
|
20
|
+
"toMatchInlineSnapshot",
|
|
21
|
+
"toThrowErrorMatchingSnapshot",
|
|
22
|
+
"toThrowErrorMatchingInlineSnapshot",
|
|
23
|
+
// toThrow will never succeed because we call the poll callback until it doesn't throw
|
|
24
|
+
"throws",
|
|
25
|
+
"Throw",
|
|
26
|
+
"throw",
|
|
27
|
+
"toThrow",
|
|
28
|
+
"toThrowError"
|
|
29
|
+
// these are not supported because you can call them without `.poll`,
|
|
30
|
+
// we throw an error inside the rejects/resolves methods to prevent this
|
|
31
|
+
// rejects,
|
|
32
|
+
// resolves
|
|
33
|
+
];
|
|
34
|
+
function createExpectPoll(expect) {
|
|
35
|
+
return function poll(fn, options = {}) {
|
|
36
|
+
const state = getWorkerState();
|
|
37
|
+
const defaults = state.config.expect?.poll ?? {};
|
|
38
|
+
const {
|
|
39
|
+
interval = defaults.interval ?? 50,
|
|
40
|
+
timeout = defaults.timeout ?? 1e3,
|
|
41
|
+
message
|
|
42
|
+
} = options;
|
|
43
|
+
const assertion = expect(null, message).withContext({
|
|
44
|
+
poll: true
|
|
45
|
+
});
|
|
46
|
+
fn = fn.bind(assertion);
|
|
47
|
+
const test = chai$1.util.flag(assertion, "vitest-test");
|
|
48
|
+
if (!test) {
|
|
49
|
+
throw new Error("expect.poll() must be called inside a test");
|
|
33
50
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
51
|
+
const proxy = new Proxy(assertion, {
|
|
52
|
+
get(target, key, receiver) {
|
|
53
|
+
const assertionFunction = Reflect.get(target, key, receiver);
|
|
54
|
+
if (typeof assertionFunction !== "function") {
|
|
55
|
+
return assertionFunction instanceof chai$1.Assertion ? proxy : assertionFunction;
|
|
56
|
+
}
|
|
57
|
+
if (key === "assert") {
|
|
58
|
+
return assertionFunction;
|
|
59
|
+
}
|
|
60
|
+
if (typeof key === "string" && unsupported.includes(key)) {
|
|
61
|
+
throw new SyntaxError(
|
|
62
|
+
`expect.poll() is not supported in combination with .${key}(). Use vi.waitFor() if your assertion condition is unstable.`
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
return function(...args) {
|
|
66
|
+
const STACK_TRACE_ERROR = new Error("STACK_TRACE_ERROR");
|
|
67
|
+
const promise = () => new Promise((resolve, reject) => {
|
|
68
|
+
let intervalId;
|
|
69
|
+
let lastError;
|
|
70
|
+
const { setTimeout, clearTimeout } = getSafeTimers();
|
|
71
|
+
const timeoutId = setTimeout(() => {
|
|
72
|
+
clearTimeout(intervalId);
|
|
73
|
+
reject(
|
|
74
|
+
copyStackTrace$1(
|
|
75
|
+
new Error(`Matcher did not succeed in ${timeout}ms`, {
|
|
76
|
+
cause: lastError
|
|
77
|
+
}),
|
|
78
|
+
STACK_TRACE_ERROR
|
|
79
|
+
)
|
|
80
|
+
);
|
|
81
|
+
}, timeout);
|
|
82
|
+
const check = async () => {
|
|
83
|
+
try {
|
|
84
|
+
chai$1.util.flag(assertion, "_name", key);
|
|
85
|
+
const obj = await fn();
|
|
86
|
+
chai$1.util.flag(assertion, "object", obj);
|
|
87
|
+
resolve(await assertionFunction.call(assertion, ...args));
|
|
88
|
+
clearTimeout(intervalId);
|
|
89
|
+
clearTimeout(timeoutId);
|
|
90
|
+
} catch (err) {
|
|
91
|
+
lastError = err;
|
|
92
|
+
intervalId = setTimeout(check, interval);
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
check();
|
|
96
|
+
});
|
|
97
|
+
let awaited = false;
|
|
98
|
+
test.onFinished ??= [];
|
|
99
|
+
test.onFinished.push(() => {
|
|
100
|
+
if (!awaited) {
|
|
101
|
+
const negated = chai$1.util.flag(assertion, "negate") ? "not." : "";
|
|
102
|
+
const name = chai$1.util.flag(assertion, "_poll.element") ? "element(locator)" : "poll(assertion)";
|
|
103
|
+
const assertionString = `expect.${name}.${negated}${String(key)}()`;
|
|
104
|
+
const error = new Error(
|
|
105
|
+
`${assertionString} was not awaited. This assertion is asynchronous and must be awaited; otherwise, it is not executed to avoid unhandled rejections:
|
|
106
|
+
|
|
107
|
+
await ${assertionString}
|
|
108
|
+
`
|
|
109
|
+
);
|
|
110
|
+
throw copyStackTrace$1(error, STACK_TRACE_ERROR);
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
let resultPromise;
|
|
114
|
+
return {
|
|
115
|
+
then(onFulfilled, onRejected) {
|
|
116
|
+
awaited = true;
|
|
117
|
+
return (resultPromise ||= promise()).then(onFulfilled, onRejected);
|
|
118
|
+
},
|
|
119
|
+
catch(onRejected) {
|
|
120
|
+
return (resultPromise ||= promise()).catch(onRejected);
|
|
121
|
+
},
|
|
122
|
+
finally(onFinally) {
|
|
123
|
+
return (resultPromise ||= promise()).finally(onFinally);
|
|
124
|
+
},
|
|
125
|
+
[Symbol.toStringTag]: "Promise"
|
|
126
|
+
};
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
return proxy;
|
|
131
|
+
};
|
|
40
132
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
const promises = [];
|
|
45
|
-
let resolvingCount = 0;
|
|
46
|
-
for (const mod of state.moduleCache.values()) {
|
|
47
|
-
if (mod.promise && !mod.evaluated) {
|
|
48
|
-
promises.push(mod.promise);
|
|
49
|
-
}
|
|
50
|
-
if (mod.resolving) {
|
|
51
|
-
resolvingCount++;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
if (!promises.length && !resolvingCount) {
|
|
55
|
-
return;
|
|
133
|
+
function copyStackTrace$1(target, source) {
|
|
134
|
+
if (source.stack !== void 0) {
|
|
135
|
+
target.stack = source.stack.replace(source.message, target.message);
|
|
56
136
|
}
|
|
57
|
-
|
|
58
|
-
await waitForImportsToResolve();
|
|
137
|
+
return target;
|
|
59
138
|
}
|
|
60
139
|
|
|
61
140
|
function commonjsRequire(path) {
|
|
@@ -157,9 +236,20 @@ function requireChaiSubset () {
|
|
|
157
236
|
var chaiSubsetExports = requireChaiSubset();
|
|
158
237
|
var Subset = /*@__PURE__*/getDefaultExportFromCjs(chaiSubsetExports);
|
|
159
238
|
|
|
160
|
-
function
|
|
239
|
+
function createAssertionMessage(util, assertion, hasArgs) {
|
|
240
|
+
const not = util.flag(assertion, "negate") ? "not." : "";
|
|
241
|
+
const name = `${util.flag(assertion, "_name")}(${"expected" })`;
|
|
242
|
+
const promiseName = util.flag(assertion, "promise");
|
|
243
|
+
const promise = promiseName ? `.${promiseName}` : "";
|
|
244
|
+
return `expect(actual)${promise}.${not}${name}`;
|
|
245
|
+
}
|
|
246
|
+
function recordAsyncExpect(_test, promise, assertion, error) {
|
|
247
|
+
const test = _test;
|
|
161
248
|
if (test && promise instanceof Promise) {
|
|
162
249
|
promise = promise.finally(() => {
|
|
250
|
+
if (!test.promises) {
|
|
251
|
+
return;
|
|
252
|
+
}
|
|
163
253
|
const index = test.promises.indexOf(promise);
|
|
164
254
|
if (index !== -1) {
|
|
165
255
|
test.promises.splice(index, 1);
|
|
@@ -169,6 +259,33 @@ function recordAsyncExpect(test, promise) {
|
|
|
169
259
|
test.promises = [];
|
|
170
260
|
}
|
|
171
261
|
test.promises.push(promise);
|
|
262
|
+
let resolved = false;
|
|
263
|
+
test.onFinished ??= [];
|
|
264
|
+
test.onFinished.push(() => {
|
|
265
|
+
if (!resolved) {
|
|
266
|
+
const processor = globalThis.__vitest_worker__?.onFilterStackTrace || ((s) => s || "");
|
|
267
|
+
const stack = processor(error.stack);
|
|
268
|
+
console.warn([
|
|
269
|
+
`Promise returned by \`${assertion}\` was not awaited. `,
|
|
270
|
+
"Vitest currently auto-awaits hanging assertions at the end of the test, but this will cause the test to fail in Vitest 3. ",
|
|
271
|
+
"Please remember to await the assertion.\n",
|
|
272
|
+
stack
|
|
273
|
+
].join(""));
|
|
274
|
+
}
|
|
275
|
+
});
|
|
276
|
+
return {
|
|
277
|
+
then(onFullfilled, onRejected) {
|
|
278
|
+
resolved = true;
|
|
279
|
+
return promise.then(onFullfilled, onRejected);
|
|
280
|
+
},
|
|
281
|
+
catch(onRejected) {
|
|
282
|
+
return promise.catch(onRejected);
|
|
283
|
+
},
|
|
284
|
+
finally(onFinally) {
|
|
285
|
+
return promise.finally(onFinally);
|
|
286
|
+
},
|
|
287
|
+
[Symbol.toStringTag]: "Promise"
|
|
288
|
+
};
|
|
172
289
|
}
|
|
173
290
|
return promise;
|
|
174
291
|
}
|
|
@@ -215,6 +332,7 @@ const SnapshotPlugin = (chai, utils) => {
|
|
|
215
332
|
chai.Assertion.prototype,
|
|
216
333
|
key,
|
|
217
334
|
function(properties, message) {
|
|
335
|
+
utils.flag(this, "_name", key);
|
|
218
336
|
const isNot = utils.flag(this, "negate");
|
|
219
337
|
if (isNot) {
|
|
220
338
|
throw new Error(`${key} cannot be used with "not"`);
|
|
@@ -241,10 +359,12 @@ const SnapshotPlugin = (chai, utils) => {
|
|
|
241
359
|
chai.Assertion.prototype,
|
|
242
360
|
"toMatchFileSnapshot",
|
|
243
361
|
function(file, message) {
|
|
362
|
+
utils.flag(this, "_name", "toMatchFileSnapshot");
|
|
244
363
|
const isNot = utils.flag(this, "negate");
|
|
245
364
|
if (isNot) {
|
|
246
365
|
throw new Error('toMatchFileSnapshot cannot be used with "not"');
|
|
247
366
|
}
|
|
367
|
+
const error = new Error("resolves");
|
|
248
368
|
const expected = utils.flag(this, "object");
|
|
249
369
|
const test = utils.flag(this, "vitest-test");
|
|
250
370
|
const errorMessage = utils.flag(this, "message");
|
|
@@ -258,13 +378,19 @@ const SnapshotPlugin = (chai, utils) => {
|
|
|
258
378
|
errorMessage,
|
|
259
379
|
...getTestNames(test)
|
|
260
380
|
});
|
|
261
|
-
return recordAsyncExpect(
|
|
381
|
+
return recordAsyncExpect(
|
|
382
|
+
test,
|
|
383
|
+
promise,
|
|
384
|
+
createAssertionMessage(utils, this),
|
|
385
|
+
error
|
|
386
|
+
);
|
|
262
387
|
}
|
|
263
388
|
);
|
|
264
389
|
utils.addMethod(
|
|
265
390
|
chai.Assertion.prototype,
|
|
266
391
|
"toMatchInlineSnapshot",
|
|
267
392
|
function __INLINE_SNAPSHOT__(properties, inlineSnapshot, message) {
|
|
393
|
+
utils.flag(this, "_name", "toMatchInlineSnapshot");
|
|
268
394
|
const isNot = utils.flag(this, "negate");
|
|
269
395
|
if (isNot) {
|
|
270
396
|
throw new Error('toMatchInlineSnapshot cannot be used with "not"');
|
|
@@ -303,6 +429,7 @@ const SnapshotPlugin = (chai, utils) => {
|
|
|
303
429
|
chai.Assertion.prototype,
|
|
304
430
|
"toThrowErrorMatchingSnapshot",
|
|
305
431
|
function(message) {
|
|
432
|
+
utils.flag(this, "_name", "toThrowErrorMatchingSnapshot");
|
|
306
433
|
const isNot = utils.flag(this, "negate");
|
|
307
434
|
if (isNot) {
|
|
308
435
|
throw new Error(
|
|
@@ -365,98 +492,6 @@ chai$1.use(Subset);
|
|
|
365
492
|
chai$1.use(SnapshotPlugin);
|
|
366
493
|
chai$1.use(JestAsymmetricMatchers);
|
|
367
494
|
|
|
368
|
-
const unsupported = [
|
|
369
|
-
// .poll is meant to retry matchers until they succeed, and
|
|
370
|
-
// snapshots will always succeed as long as the poll method doesn't thow an error
|
|
371
|
-
// in this case using the `vi.waitFor` method is more appropriate
|
|
372
|
-
"matchSnapshot",
|
|
373
|
-
"toMatchSnapshot",
|
|
374
|
-
"toMatchInlineSnapshot",
|
|
375
|
-
"toThrowErrorMatchingSnapshot",
|
|
376
|
-
"toThrowErrorMatchingInlineSnapshot",
|
|
377
|
-
// toThrow will never succeed because we call the poll callback until it doesn't throw
|
|
378
|
-
"throws",
|
|
379
|
-
"Throw",
|
|
380
|
-
"throw",
|
|
381
|
-
"toThrow",
|
|
382
|
-
"toThrowError"
|
|
383
|
-
// these are not supported because you can call them without `.poll`,
|
|
384
|
-
// we throw an error inside the rejects/resolves methods to prevent this
|
|
385
|
-
// rejects,
|
|
386
|
-
// resolves
|
|
387
|
-
];
|
|
388
|
-
function createExpectPoll(expect) {
|
|
389
|
-
return function poll(fn, options = {}) {
|
|
390
|
-
const state = getWorkerState();
|
|
391
|
-
const defaults = state.config.expect?.poll ?? {};
|
|
392
|
-
const {
|
|
393
|
-
interval = defaults.interval ?? 50,
|
|
394
|
-
timeout = defaults.timeout ?? 1e3,
|
|
395
|
-
message
|
|
396
|
-
} = options;
|
|
397
|
-
const assertion = expect(null, message).withContext({
|
|
398
|
-
poll: true
|
|
399
|
-
});
|
|
400
|
-
fn = fn.bind(assertion);
|
|
401
|
-
const proxy = new Proxy(assertion, {
|
|
402
|
-
get(target, key, receiver) {
|
|
403
|
-
const assertionFunction = Reflect.get(target, key, receiver);
|
|
404
|
-
if (typeof assertionFunction !== "function") {
|
|
405
|
-
return assertionFunction instanceof chai$1.Assertion ? proxy : assertionFunction;
|
|
406
|
-
}
|
|
407
|
-
if (key === "assert") {
|
|
408
|
-
return assertionFunction;
|
|
409
|
-
}
|
|
410
|
-
if (typeof key === "string" && unsupported.includes(key)) {
|
|
411
|
-
throw new SyntaxError(
|
|
412
|
-
`expect.poll() is not supported in combination with .${key}(). Use vi.waitFor() if your assertion condition is unstable.`
|
|
413
|
-
);
|
|
414
|
-
}
|
|
415
|
-
return function(...args) {
|
|
416
|
-
const STACK_TRACE_ERROR = new Error("STACK_TRACE_ERROR");
|
|
417
|
-
return new Promise((resolve, reject) => {
|
|
418
|
-
let intervalId;
|
|
419
|
-
let lastError;
|
|
420
|
-
const { setTimeout, clearTimeout } = getSafeTimers();
|
|
421
|
-
const timeoutId = setTimeout(() => {
|
|
422
|
-
clearTimeout(intervalId);
|
|
423
|
-
reject(
|
|
424
|
-
copyStackTrace$1(
|
|
425
|
-
new Error(`Matcher did not succeed in ${timeout}ms`, {
|
|
426
|
-
cause: lastError
|
|
427
|
-
}),
|
|
428
|
-
STACK_TRACE_ERROR
|
|
429
|
-
)
|
|
430
|
-
);
|
|
431
|
-
}, timeout);
|
|
432
|
-
const check = async () => {
|
|
433
|
-
try {
|
|
434
|
-
chai$1.util.flag(assertion, "_name", key);
|
|
435
|
-
const obj = await fn();
|
|
436
|
-
chai$1.util.flag(assertion, "object", obj);
|
|
437
|
-
resolve(await assertionFunction.call(assertion, ...args));
|
|
438
|
-
clearTimeout(intervalId);
|
|
439
|
-
clearTimeout(timeoutId);
|
|
440
|
-
} catch (err) {
|
|
441
|
-
lastError = err;
|
|
442
|
-
intervalId = setTimeout(check, interval);
|
|
443
|
-
}
|
|
444
|
-
};
|
|
445
|
-
check();
|
|
446
|
-
});
|
|
447
|
-
};
|
|
448
|
-
}
|
|
449
|
-
});
|
|
450
|
-
return proxy;
|
|
451
|
-
};
|
|
452
|
-
}
|
|
453
|
-
function copyStackTrace$1(target, source) {
|
|
454
|
-
if (source.stack !== void 0) {
|
|
455
|
-
target.stack = source.stack.replace(source.message, target.message);
|
|
456
|
-
}
|
|
457
|
-
return target;
|
|
458
|
-
}
|
|
459
|
-
|
|
460
495
|
function createExpect(test) {
|
|
461
496
|
const expect = (value, message) => {
|
|
462
497
|
const { assertionCalls } = getState(expect);
|
|
@@ -3942,4 +3977,4 @@ function getImporter(name) {
|
|
|
3942
3977
|
return stack?.file || "";
|
|
3943
3978
|
}
|
|
3944
3979
|
|
|
3945
|
-
export { globalExpect as a, vitest as b, createExpect as c, getSnapshotClient as g,
|
|
3980
|
+
export { globalExpect as a, vitest as b, createExpect as c, getSnapshotClient as g, vi as v };
|
|
@@ -1,18 +1,15 @@
|
|
|
1
|
-
import vm, { isContext } from 'node:vm';
|
|
2
1
|
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
2
|
+
import vm, { isContext } from 'node:vm';
|
|
3
3
|
import { dirname, basename, extname, normalize, join, resolve } from 'pathe';
|
|
4
|
-
import { createCustomConsole } from './console.CfT1Wjed.js';
|
|
5
|
-
import { g as getDefaultRequestStubs, s as startVitestExecutor } from './execute._eQQfgI8.js';
|
|
6
4
|
import { distDir } from '../path.js';
|
|
7
|
-
import {
|
|
5
|
+
import { createCustomConsole } from './console.BYGVloWk.js';
|
|
6
|
+
import { g as getDefaultRequestStubs, s as startVitestExecutor } from './execute.2pr0rHgK.js';
|
|
8
7
|
import fs from 'node:fs';
|
|
8
|
+
import { dirname as dirname$1 } from 'node:path';
|
|
9
9
|
import { isNodeBuiltin, isPrimitive, toArray, getCachedData, setCacheData } from 'vite-node/utils';
|
|
10
10
|
import { createRequire, Module } from 'node:module';
|
|
11
11
|
import { CSS_LANGS_RE, KNOWN_ASSET_RE } from 'vite-node/constants';
|
|
12
|
-
import '
|
|
13
|
-
import '@vitest/utils';
|
|
14
|
-
import { p as provideWorkerState } from './utils.Ck2hJTRs.js';
|
|
15
|
-
import './env.CmHVDJnw.js';
|
|
12
|
+
import { p as provideWorkerState } from './utils.C8RiOc4B.js';
|
|
16
13
|
|
|
17
14
|
const _require = createRequire(import.meta.url);
|
|
18
15
|
const requiresCache = /* @__PURE__ */ new WeakMap();
|
|
@@ -119,6 +116,9 @@ class CommonjsExecutor {
|
|
|
119
116
|
// @ts-expect-error not typed
|
|
120
117
|
static globalPaths = Module.globalPaths;
|
|
121
118
|
static isBuiltin = Module.isBuiltin;
|
|
119
|
+
static constants = Module.constants;
|
|
120
|
+
static enableCompileCache = Module.enableCompileCache;
|
|
121
|
+
static getCompileCacheDir = Module.getCompileCacheDir;
|
|
122
122
|
static Module = Module$1;
|
|
123
123
|
};
|
|
124
124
|
this.extensions[".js"] = this.requireJs;
|