vitest 3.1.0-beta.1 → 3.1.0-beta.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/browser.js +4 -4
- package/dist/chunks/base.CylSMlTD.js +41 -0
- package/dist/chunks/benchmark.BKUatJGy.js +39 -0
- package/dist/chunks/cac.JtTXbKz0.js +1525 -0
- package/dist/chunks/{cli-api.BwkkJsRe.js → cli-api.BTtPTYMs.js} +4638 -5072
- package/dist/chunks/console.D6t261w0.js +173 -0
- package/dist/chunks/constants.BZZyIeIE.js +43 -0
- package/dist/chunks/coverage.0iPg4Wrz.js +33 -0
- package/dist/chunks/{coverage.gV8doR2Y.js → coverage.C2ohxaN0.js} +2216 -2479
- package/dist/chunks/creator.BEXek7yQ.js +640 -0
- package/dist/chunks/date.CDOsz-HY.js +53 -0
- package/dist/chunks/defaults.DmfNPoe5.js +114 -0
- package/dist/chunks/{env.D4Lgay0q.js → env.Dq0hM4Xv.js} +1 -1
- package/dist/chunks/execute.DZKwfrTs.js +791 -0
- package/dist/chunks/git.DXfdBEfR.js +74 -0
- package/dist/chunks/{globals.BEpDe-k3.js → globals.DCbUWjip.js} +10 -10
- package/dist/chunks/{index.D7Ny8f_s.js → index.BDobFbcz.js} +6 -7
- package/dist/chunks/index.DFXFpH3w.js +607 -0
- package/dist/chunks/index.VfYQ6MXY.js +104 -0
- package/dist/chunks/index.ZIOEXBQB.js +2382 -0
- package/dist/chunks/inspector.DbDkSkFn.js +54 -0
- package/dist/chunks/node.IqGoMrm4.js +15 -0
- package/dist/chunks/{reporters.d.r7poTZjA.d.ts → reporters.d.5g6jXhoW.d.ts} +14 -3
- package/dist/chunks/rpc.DGgL5dw7.js +92 -0
- package/dist/chunks/run-once.I7PpBOk1.js +47 -0
- package/dist/chunks/runBaseTests.CqmKSG99.js +134 -0
- package/dist/chunks/setup-common.DEGDGBiA.js +88 -0
- package/dist/chunks/{typechecker.BlF3eHsb.js → typechecker.C2IpOhid.js} +620 -622
- package/dist/chunks/utils.BfxieIyZ.js +66 -0
- package/dist/chunks/utils.CtocqOoE.js +72 -0
- package/dist/chunks/utils.OLmtDstN.js +194 -0
- package/dist/chunks/{vi.nSCvwQ7l.js → vi.B-PuvDzu.js} +878 -1019
- package/dist/chunks/vite.d.Dh1jE-_V.d.ts +23 -0
- package/dist/chunks/vm.BW5voG-u.js +789 -0
- package/dist/cli.js +2 -2
- package/dist/config.cjs +97 -103
- package/dist/config.d.ts +3 -3
- package/dist/config.js +6 -6
- package/dist/coverage.d.ts +1 -1
- package/dist/coverage.js +6 -6
- package/dist/environments.js +1 -1
- package/dist/execute.js +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +6 -6
- package/dist/node.d.ts +3 -3
- package/dist/node.js +36 -45
- package/dist/path.js +1 -4
- package/dist/reporters.d.ts +1 -1
- package/dist/reporters.js +4 -4
- package/dist/runners.js +231 -267
- package/dist/snapshot.js +2 -2
- package/dist/suite.js +2 -2
- package/dist/worker.js +98 -114
- package/dist/workers/forks.js +22 -22
- package/dist/workers/runVmTests.js +61 -66
- package/dist/workers/threads.js +13 -13
- package/dist/workers/vmForks.js +24 -24
- package/dist/workers/vmThreads.js +15 -15
- package/dist/workers.js +10 -10
- package/package.json +11 -11
- package/dist/chunks/base.DV59CbtV.js +0 -45
- package/dist/chunks/benchmark.DL72EVN-.js +0 -40
- package/dist/chunks/cac.BjmXy7OV.js +0 -1664
- package/dist/chunks/console.CN7AiMGV.js +0 -179
- package/dist/chunks/constants.DTYd6dNH.js +0 -46
- package/dist/chunks/coverage.A3sS5-Wm.js +0 -40
- package/dist/chunks/creator.BsBnpTzI.js +0 -670
- package/dist/chunks/date.W2xKR2qe.js +0 -53
- package/dist/chunks/defaults.C2Ndd9wx.js +0 -119
- package/dist/chunks/execute.eDH0aFFd.js +0 -839
- package/dist/chunks/git.B5SDxu-n.js +0 -69
- package/dist/chunks/index.DOyx6FYJ.js +0 -2551
- package/dist/chunks/index.K90BXFOx.js +0 -658
- package/dist/chunks/index.uXkkC4xl.js +0 -111
- package/dist/chunks/inspector.DKLceBVD.js +0 -54
- package/dist/chunks/node.AKq966Jp.js +0 -15
- package/dist/chunks/rpc.TVf73xOu.js +0 -102
- package/dist/chunks/run-once.2ogXb3JV.js +0 -28
- package/dist/chunks/runBaseTests.BVrL_ow3.js +0 -142
- package/dist/chunks/setup-common.CPvtqi8q.js +0 -96
- package/dist/chunks/utils.C8RiOc4B.js +0 -77
- package/dist/chunks/utils.Cn0zI1t3.js +0 -68
- package/dist/chunks/utils.bLM2atbD.js +0 -198
- package/dist/chunks/vite.d.Fvq-NZoa.d.ts +0 -11
- package/dist/chunks/vm.jEFQDlX_.js +0 -852
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
import * as chai from 'chai';
|
|
2
|
-
import { resolve } from 'node:path';
|
|
3
|
-
import { l as loadDiffConfig, b as loadSnapshotSerializers, t as takeCoverageInsideWorker } from './setup-common.CPvtqi8q.js';
|
|
4
|
-
import { distDir } from '../path.js';
|
|
5
|
-
import { r as rpc } from './rpc.TVf73xOu.js';
|
|
6
|
-
import { g as getWorkerState } from './utils.C8RiOc4B.js';
|
|
7
|
-
|
|
8
|
-
function setupChaiConfig(config) {
|
|
9
|
-
Object.assign(chai.config, config);
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
async function resolveSnapshotEnvironment(config, executor) {
|
|
13
|
-
if (!config.snapshotEnvironment) {
|
|
14
|
-
const { VitestNodeSnapshotEnvironment } = await import('./node.AKq966Jp.js');
|
|
15
|
-
return new VitestNodeSnapshotEnvironment();
|
|
16
|
-
}
|
|
17
|
-
const mod = await executor.executeId(config.snapshotEnvironment);
|
|
18
|
-
if (typeof mod.default !== "object" || !mod.default) {
|
|
19
|
-
throw new Error(
|
|
20
|
-
"Snapshot environment module must have a default export object with a shape of `SnapshotEnvironment`"
|
|
21
|
-
);
|
|
22
|
-
}
|
|
23
|
-
return mod.default;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const runnersFile = resolve(distDir, "runners.js");
|
|
27
|
-
async function getTestRunnerConstructor(config, executor) {
|
|
28
|
-
if (!config.runner) {
|
|
29
|
-
const { VitestTestRunner, NodeBenchmarkRunner } = await executor.executeFile(runnersFile);
|
|
30
|
-
return config.mode === "test" ? VitestTestRunner : NodeBenchmarkRunner;
|
|
31
|
-
}
|
|
32
|
-
const mod = await executor.executeId(config.runner);
|
|
33
|
-
if (!mod.default && typeof mod.default !== "function") {
|
|
34
|
-
throw new Error(
|
|
35
|
-
`Runner must export a default function, but got ${typeof mod.default} imported from ${config.runner}`
|
|
36
|
-
);
|
|
37
|
-
}
|
|
38
|
-
return mod.default;
|
|
39
|
-
}
|
|
40
|
-
async function resolveTestRunner(config, executor) {
|
|
41
|
-
const TestRunner = await getTestRunnerConstructor(config, executor);
|
|
42
|
-
const testRunner = new TestRunner(config);
|
|
43
|
-
Object.defineProperty(testRunner, "__vitest_executor", {
|
|
44
|
-
value: executor,
|
|
45
|
-
enumerable: false,
|
|
46
|
-
configurable: false
|
|
47
|
-
});
|
|
48
|
-
if (!testRunner.config) {
|
|
49
|
-
testRunner.config = config;
|
|
50
|
-
}
|
|
51
|
-
if (!testRunner.importFile) {
|
|
52
|
-
throw new Error('Runner must implement "importFile" method.');
|
|
53
|
-
}
|
|
54
|
-
const [diffOptions] = await Promise.all([
|
|
55
|
-
loadDiffConfig(config, executor),
|
|
56
|
-
loadSnapshotSerializers(config, executor)
|
|
57
|
-
]);
|
|
58
|
-
testRunner.config.diffOptions = diffOptions;
|
|
59
|
-
const originalOnTaskUpdate = testRunner.onTaskUpdate;
|
|
60
|
-
testRunner.onTaskUpdate = async (task, events) => {
|
|
61
|
-
const p = rpc().onTaskUpdate(task, events);
|
|
62
|
-
await originalOnTaskUpdate?.call(testRunner, task, events);
|
|
63
|
-
return p;
|
|
64
|
-
};
|
|
65
|
-
const originalOnCollectStart = testRunner.onCollectStart;
|
|
66
|
-
testRunner.onCollectStart = async (file) => {
|
|
67
|
-
await rpc().onQueued(file);
|
|
68
|
-
await originalOnCollectStart?.call(testRunner, file);
|
|
69
|
-
};
|
|
70
|
-
const originalOnCollected = testRunner.onCollected;
|
|
71
|
-
testRunner.onCollected = async (files) => {
|
|
72
|
-
const state = getWorkerState();
|
|
73
|
-
files.forEach((file) => {
|
|
74
|
-
file.prepareDuration = state.durations.prepare;
|
|
75
|
-
file.environmentLoad = state.durations.environment;
|
|
76
|
-
state.durations.prepare = 0;
|
|
77
|
-
state.durations.environment = 0;
|
|
78
|
-
});
|
|
79
|
-
rpc().onCollected(files);
|
|
80
|
-
await originalOnCollected?.call(testRunner, files);
|
|
81
|
-
};
|
|
82
|
-
const originalOnAfterRun = testRunner.onAfterRunFiles;
|
|
83
|
-
testRunner.onAfterRunFiles = async (files) => {
|
|
84
|
-
const state = getWorkerState();
|
|
85
|
-
const coverage = await takeCoverageInsideWorker(config.coverage, executor);
|
|
86
|
-
if (coverage) {
|
|
87
|
-
rpc().onAfterSuiteRun({
|
|
88
|
-
coverage,
|
|
89
|
-
testFiles: files.map((file) => file.name).sort(),
|
|
90
|
-
transformMode: state.environment.transformMode,
|
|
91
|
-
projectName: state.ctx.projectName
|
|
92
|
-
});
|
|
93
|
-
}
|
|
94
|
-
await originalOnAfterRun?.call(testRunner, files);
|
|
95
|
-
};
|
|
96
|
-
const originalOnAfterRunTask = testRunner.onAfterRunTask;
|
|
97
|
-
testRunner.onAfterRunTask = async (test) => {
|
|
98
|
-
if (config.bail && test.result?.state === "fail") {
|
|
99
|
-
const previousFailures = await rpc().getCountOfFailedTests();
|
|
100
|
-
const currentFailures = 1 + previousFailures;
|
|
101
|
-
if (currentFailures >= config.bail) {
|
|
102
|
-
rpc().onCancel("test-failure");
|
|
103
|
-
testRunner.onCancel?.("test-failure");
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
await originalOnAfterRunTask?.call(testRunner, test);
|
|
107
|
-
};
|
|
108
|
-
return testRunner;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
export { resolveSnapshotEnvironment as a, resolveTestRunner as r, setupChaiConfig as s };
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import { createRequire } from 'node:module';
|
|
2
|
-
import { pathToFileURL } from 'node:url';
|
|
3
|
-
|
|
4
|
-
const __require = createRequire(import.meta.url);
|
|
5
|
-
let inspector;
|
|
6
|
-
let session;
|
|
7
|
-
function setupInspect(ctx) {
|
|
8
|
-
const config = ctx.config;
|
|
9
|
-
const isEnabled = config.inspector.enabled;
|
|
10
|
-
if (isEnabled) {
|
|
11
|
-
inspector = __require("node:inspector");
|
|
12
|
-
const isOpen = inspector.url() !== void 0;
|
|
13
|
-
if (!isOpen) {
|
|
14
|
-
inspector.open(
|
|
15
|
-
config.inspector.port,
|
|
16
|
-
config.inspector.host,
|
|
17
|
-
config.inspector.waitForDebugger
|
|
18
|
-
);
|
|
19
|
-
if (config.inspectBrk) {
|
|
20
|
-
const firstTestFile = typeof ctx.files[0] === "string" ? ctx.files[0] : ctx.files[0].filepath;
|
|
21
|
-
if (firstTestFile) {
|
|
22
|
-
session = new inspector.Session();
|
|
23
|
-
session.connect();
|
|
24
|
-
session.post("Debugger.enable");
|
|
25
|
-
session.post("Debugger.setBreakpointByUrl", {
|
|
26
|
-
lineNumber: 0,
|
|
27
|
-
url: pathToFileURL(firstTestFile)
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
const keepOpen = shouldKeepOpen(config);
|
|
34
|
-
return function cleanup() {
|
|
35
|
-
if (isEnabled && !keepOpen && inspector) {
|
|
36
|
-
inspector.close();
|
|
37
|
-
session?.disconnect();
|
|
38
|
-
}
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
function closeInspector(config) {
|
|
42
|
-
const keepOpen = shouldKeepOpen(config);
|
|
43
|
-
if (inspector && !keepOpen) {
|
|
44
|
-
inspector.close();
|
|
45
|
-
session?.disconnect();
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
function shouldKeepOpen(config) {
|
|
49
|
-
const isIsolatedSingleThread = config.pool === "threads" && config.poolOptions?.threads?.isolate === false && config.poolOptions?.threads?.singleThread;
|
|
50
|
-
const isIsolatedSingleFork = config.pool === "forks" && config.poolOptions?.forks?.isolate === false && config.poolOptions?.forks?.singleFork;
|
|
51
|
-
return config.watch && (isIsolatedSingleFork || isIsolatedSingleThread);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
export { closeInspector as c, setupInspect as s };
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { NodeSnapshotEnvironment } from '@vitest/snapshot/environment';
|
|
2
|
-
import { g as getWorkerState } from './utils.C8RiOc4B.js';
|
|
3
|
-
import '@vitest/utils';
|
|
4
|
-
|
|
5
|
-
class VitestNodeSnapshotEnvironment extends NodeSnapshotEnvironment {
|
|
6
|
-
getHeader() {
|
|
7
|
-
return `// Vitest Snapshot v${this.getVersion()}, https://vitest.dev/guide/snapshot.html`;
|
|
8
|
-
}
|
|
9
|
-
resolvePath(filepath) {
|
|
10
|
-
const rpc = getWorkerState().rpc;
|
|
11
|
-
return rpc.resolveSnapshotPath(filepath);
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export { VitestNodeSnapshotEnvironment };
|
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
import { getSafeTimers } from '@vitest/utils';
|
|
2
|
-
import { c as createBirpc } from './index.68735LiX.js';
|
|
3
|
-
import { g as getWorkerState } from './utils.C8RiOc4B.js';
|
|
4
|
-
|
|
5
|
-
const { get } = Reflect;
|
|
6
|
-
function withSafeTimers(fn) {
|
|
7
|
-
const { setTimeout, clearTimeout, nextTick, setImmediate, clearImmediate } = getSafeTimers();
|
|
8
|
-
const currentSetTimeout = globalThis.setTimeout;
|
|
9
|
-
const currentClearTimeout = globalThis.clearTimeout;
|
|
10
|
-
const currentSetImmediate = globalThis.setImmediate;
|
|
11
|
-
const currentClearImmediate = globalThis.clearImmediate;
|
|
12
|
-
const currentNextTick = globalThis.process?.nextTick;
|
|
13
|
-
try {
|
|
14
|
-
globalThis.setTimeout = setTimeout;
|
|
15
|
-
globalThis.clearTimeout = clearTimeout;
|
|
16
|
-
globalThis.setImmediate = setImmediate;
|
|
17
|
-
globalThis.clearImmediate = clearImmediate;
|
|
18
|
-
if (globalThis.process) {
|
|
19
|
-
globalThis.process.nextTick = nextTick;
|
|
20
|
-
}
|
|
21
|
-
const result = fn();
|
|
22
|
-
return result;
|
|
23
|
-
} finally {
|
|
24
|
-
globalThis.setTimeout = currentSetTimeout;
|
|
25
|
-
globalThis.clearTimeout = currentClearTimeout;
|
|
26
|
-
globalThis.setImmediate = currentSetImmediate;
|
|
27
|
-
globalThis.clearImmediate = currentClearImmediate;
|
|
28
|
-
if (globalThis.process) {
|
|
29
|
-
nextTick(() => {
|
|
30
|
-
globalThis.process.nextTick = currentNextTick;
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
const promises = /* @__PURE__ */ new Set();
|
|
36
|
-
async function rpcDone() {
|
|
37
|
-
if (!promises.size) {
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
const awaitable = Array.from(promises);
|
|
41
|
-
return Promise.all(awaitable);
|
|
42
|
-
}
|
|
43
|
-
function createRuntimeRpc(options) {
|
|
44
|
-
let setCancel = (_reason) => {
|
|
45
|
-
};
|
|
46
|
-
const onCancel = new Promise((resolve) => {
|
|
47
|
-
setCancel = resolve;
|
|
48
|
-
});
|
|
49
|
-
const rpc2 = createSafeRpc(
|
|
50
|
-
createBirpc(
|
|
51
|
-
{
|
|
52
|
-
onCancel: setCancel
|
|
53
|
-
},
|
|
54
|
-
{
|
|
55
|
-
eventNames: [
|
|
56
|
-
"onUserConsoleLog",
|
|
57
|
-
"onCollected",
|
|
58
|
-
"onCancel"
|
|
59
|
-
],
|
|
60
|
-
onTimeoutError(functionName, args) {
|
|
61
|
-
let message = `[vitest-worker]: Timeout calling "${functionName}"`;
|
|
62
|
-
if (functionName === "fetch" || functionName === "transform" || functionName === "resolveId") {
|
|
63
|
-
message += ` with "${JSON.stringify(args)}"`;
|
|
64
|
-
}
|
|
65
|
-
if (functionName === "onUnhandledError") {
|
|
66
|
-
message += ` with "${args[0]?.message || args[0]}"`;
|
|
67
|
-
}
|
|
68
|
-
throw new Error(message);
|
|
69
|
-
},
|
|
70
|
-
...options
|
|
71
|
-
}
|
|
72
|
-
)
|
|
73
|
-
);
|
|
74
|
-
return {
|
|
75
|
-
rpc: rpc2,
|
|
76
|
-
onCancel
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
|
-
function createSafeRpc(rpc2) {
|
|
80
|
-
return new Proxy(rpc2, {
|
|
81
|
-
get(target, p, handler) {
|
|
82
|
-
const sendCall = get(target, p, handler);
|
|
83
|
-
const safeSendCall = (...args) => withSafeTimers(async () => {
|
|
84
|
-
const result = sendCall(...args);
|
|
85
|
-
promises.add(result);
|
|
86
|
-
try {
|
|
87
|
-
return await result;
|
|
88
|
-
} finally {
|
|
89
|
-
promises.delete(result);
|
|
90
|
-
}
|
|
91
|
-
});
|
|
92
|
-
safeSendCall.asEvent = sendCall.asEvent;
|
|
93
|
-
return safeSendCall;
|
|
94
|
-
}
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
function rpc() {
|
|
98
|
-
const { rpc: rpc2 } = getWorkerState();
|
|
99
|
-
return rpc2;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
export { rpcDone as a, createRuntimeRpc as c, rpc as r };
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { g as getWorkerState } from './utils.C8RiOc4B.js';
|
|
2
|
-
|
|
3
|
-
const filesCount = /* @__PURE__ */ new Map();
|
|
4
|
-
const cache = /* @__PURE__ */ new Map();
|
|
5
|
-
function runOnce(fn, key) {
|
|
6
|
-
const filepath = getWorkerState().filepath || "__unknown_files__";
|
|
7
|
-
if (!key) {
|
|
8
|
-
filesCount.set(filepath, (filesCount.get(filepath) || 0) + 1);
|
|
9
|
-
key = String(filesCount.get(filepath));
|
|
10
|
-
}
|
|
11
|
-
const id = `${filepath}:${key}`;
|
|
12
|
-
if (!cache.has(id)) {
|
|
13
|
-
cache.set(id, fn());
|
|
14
|
-
}
|
|
15
|
-
return cache.get(id);
|
|
16
|
-
}
|
|
17
|
-
function isFirstRun() {
|
|
18
|
-
let firstRun = false;
|
|
19
|
-
runOnce(() => {
|
|
20
|
-
firstRun = true;
|
|
21
|
-
}, "__vitest_first_run__");
|
|
22
|
-
return firstRun;
|
|
23
|
-
}
|
|
24
|
-
function resetRunOnceCounter() {
|
|
25
|
-
filesCount.clear();
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export { runOnce as a, isFirstRun as i, resetRunOnceCounter as r };
|
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
import { performance } from 'node:perf_hooks';
|
|
2
|
-
import { startTests, collectTests } from '@vitest/runner';
|
|
3
|
-
import { a as resolveSnapshotEnvironment, s as setupChaiConfig, r as resolveTestRunner } from './index.uXkkC4xl.js';
|
|
4
|
-
import { c as setupCommonEnv, s as startCoverageInsideWorker, a as stopCoverageInsideWorker } from './setup-common.CPvtqi8q.js';
|
|
5
|
-
import { a as globalExpect, v as vi } from './vi.nSCvwQ7l.js';
|
|
6
|
-
import { c as closeInspector } from './inspector.DKLceBVD.js';
|
|
7
|
-
import { createRequire } from 'node:module';
|
|
8
|
-
import timers from 'node:timers';
|
|
9
|
-
import timersPromises from 'node:timers/promises';
|
|
10
|
-
import util from 'node:util';
|
|
11
|
-
import { getSafeTimers } from '@vitest/utils';
|
|
12
|
-
import { KNOWN_ASSET_TYPES } from 'vite-node/constants';
|
|
13
|
-
import { installSourcemapsSupport } from 'vite-node/source-map';
|
|
14
|
-
import { V as VitestIndex } from './index.D7Ny8f_s.js';
|
|
15
|
-
import { g as getWorkerState, r as resetModules } from './utils.C8RiOc4B.js';
|
|
16
|
-
import 'chai';
|
|
17
|
-
import 'node:path';
|
|
18
|
-
import '../path.js';
|
|
19
|
-
import 'node:url';
|
|
20
|
-
import './rpc.TVf73xOu.js';
|
|
21
|
-
import './index.68735LiX.js';
|
|
22
|
-
import './coverage.A3sS5-Wm.js';
|
|
23
|
-
import '@vitest/snapshot';
|
|
24
|
-
import './run-once.2ogXb3JV.js';
|
|
25
|
-
import '@vitest/expect';
|
|
26
|
-
import '@vitest/runner/utils';
|
|
27
|
-
import './_commonjsHelpers.BFTU3MAI.js';
|
|
28
|
-
import '@vitest/utils/error';
|
|
29
|
-
import '@vitest/spy';
|
|
30
|
-
import '@vitest/utils/source-map';
|
|
31
|
-
import './date.W2xKR2qe.js';
|
|
32
|
-
import './benchmark.DL72EVN-.js';
|
|
33
|
-
import 'expect-type';
|
|
34
|
-
|
|
35
|
-
let globalSetup = false;
|
|
36
|
-
async function setupGlobalEnv(config, { environment }, executor) {
|
|
37
|
-
await setupCommonEnv(config);
|
|
38
|
-
Object.defineProperty(globalThis, "__vitest_index__", {
|
|
39
|
-
value: VitestIndex,
|
|
40
|
-
enumerable: false
|
|
41
|
-
});
|
|
42
|
-
const state = getWorkerState();
|
|
43
|
-
if (!state.config.snapshotOptions.snapshotEnvironment) {
|
|
44
|
-
state.config.snapshotOptions.snapshotEnvironment = await resolveSnapshotEnvironment(config, executor);
|
|
45
|
-
}
|
|
46
|
-
if (globalSetup) {
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
globalSetup = true;
|
|
50
|
-
if (environment.transformMode === "web") {
|
|
51
|
-
const _require = createRequire(import.meta.url);
|
|
52
|
-
_require.extensions[".css"] = resolveCss;
|
|
53
|
-
_require.extensions[".scss"] = resolveCss;
|
|
54
|
-
_require.extensions[".sass"] = resolveCss;
|
|
55
|
-
_require.extensions[".less"] = resolveCss;
|
|
56
|
-
KNOWN_ASSET_TYPES.forEach((type) => {
|
|
57
|
-
_require.extensions[`.${type}`] = resolveAsset;
|
|
58
|
-
});
|
|
59
|
-
process.env.SSR = "";
|
|
60
|
-
} else {
|
|
61
|
-
process.env.SSR = "1";
|
|
62
|
-
}
|
|
63
|
-
globalThis.__vitest_required__ = {
|
|
64
|
-
util,
|
|
65
|
-
timers,
|
|
66
|
-
timersPromises
|
|
67
|
-
};
|
|
68
|
-
installSourcemapsSupport({
|
|
69
|
-
getSourceMap: (source) => state.moduleCache.getSourceMap(source)
|
|
70
|
-
});
|
|
71
|
-
if (!config.disableConsoleIntercept) {
|
|
72
|
-
await setupConsoleLogSpy();
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
function resolveCss(mod) {
|
|
76
|
-
mod.exports = "";
|
|
77
|
-
}
|
|
78
|
-
function resolveAsset(mod, url) {
|
|
79
|
-
mod.exports = url;
|
|
80
|
-
}
|
|
81
|
-
async function setupConsoleLogSpy() {
|
|
82
|
-
const { createCustomConsole } = await import('./console.CN7AiMGV.js');
|
|
83
|
-
globalThis.console = createCustomConsole();
|
|
84
|
-
}
|
|
85
|
-
async function withEnv({ environment }, options, fn) {
|
|
86
|
-
globalThis.__vitest_environment__ = environment.name;
|
|
87
|
-
globalExpect.setState({
|
|
88
|
-
environment: environment.name
|
|
89
|
-
});
|
|
90
|
-
const env = await environment.setup(globalThis, options);
|
|
91
|
-
try {
|
|
92
|
-
await fn();
|
|
93
|
-
} finally {
|
|
94
|
-
const { setTimeout } = getSafeTimers();
|
|
95
|
-
await new Promise((resolve) => setTimeout(resolve));
|
|
96
|
-
await env.teardown(globalThis);
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
async function run(method, files, config, environment, executor) {
|
|
101
|
-
const workerState = getWorkerState();
|
|
102
|
-
const isIsolatedThreads = config.pool === "threads" && (config.poolOptions?.threads?.isolate ?? true);
|
|
103
|
-
const isIsolatedForks = config.pool === "forks" && (config.poolOptions?.forks?.isolate ?? true);
|
|
104
|
-
const isolate = isIsolatedThreads || isIsolatedForks;
|
|
105
|
-
await setupGlobalEnv(config, environment, executor);
|
|
106
|
-
await startCoverageInsideWorker(config.coverage, executor, { isolate });
|
|
107
|
-
if (config.chaiConfig) {
|
|
108
|
-
setupChaiConfig(config.chaiConfig);
|
|
109
|
-
}
|
|
110
|
-
const runner = await resolveTestRunner(config, executor);
|
|
111
|
-
workerState.onCancel.then((reason) => {
|
|
112
|
-
closeInspector(config);
|
|
113
|
-
runner.onCancel?.(reason);
|
|
114
|
-
});
|
|
115
|
-
workerState.durations.prepare = performance.now() - workerState.durations.prepare;
|
|
116
|
-
workerState.durations.environment = performance.now();
|
|
117
|
-
await withEnv(
|
|
118
|
-
environment,
|
|
119
|
-
environment.options || config.environmentOptions || {},
|
|
120
|
-
async () => {
|
|
121
|
-
workerState.durations.environment = performance.now() - workerState.durations.environment;
|
|
122
|
-
for (const file of files) {
|
|
123
|
-
if (isolate) {
|
|
124
|
-
executor.mocker.reset();
|
|
125
|
-
resetModules(workerState.moduleCache, true);
|
|
126
|
-
}
|
|
127
|
-
workerState.filepath = file.filepath;
|
|
128
|
-
if (method === "run") {
|
|
129
|
-
await startTests([file], runner);
|
|
130
|
-
} else {
|
|
131
|
-
await collectTests([file], runner);
|
|
132
|
-
}
|
|
133
|
-
vi.resetConfig();
|
|
134
|
-
vi.restoreAllMocks();
|
|
135
|
-
}
|
|
136
|
-
await stopCoverageInsideWorker(config.coverage, executor, { isolate });
|
|
137
|
-
}
|
|
138
|
-
);
|
|
139
|
-
workerState.environmentTeardownRun = true;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
export { run };
|
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
import { r as resolveCoverageProviderModule } from './coverage.A3sS5-Wm.js';
|
|
2
|
-
import { addSerializer } from '@vitest/snapshot';
|
|
3
|
-
import { setSafeTimers } from '@vitest/utils';
|
|
4
|
-
import { r as resetRunOnceCounter } from './run-once.2ogXb3JV.js';
|
|
5
|
-
|
|
6
|
-
async function startCoverageInsideWorker(options, loader, runtimeOptions) {
|
|
7
|
-
const coverageModule = await resolveCoverageProviderModule(options, loader);
|
|
8
|
-
if (coverageModule) {
|
|
9
|
-
return coverageModule.startCoverage?.(runtimeOptions);
|
|
10
|
-
}
|
|
11
|
-
return null;
|
|
12
|
-
}
|
|
13
|
-
async function takeCoverageInsideWorker(options, loader) {
|
|
14
|
-
const coverageModule = await resolveCoverageProviderModule(options, loader);
|
|
15
|
-
if (coverageModule) {
|
|
16
|
-
return coverageModule.takeCoverage?.({ moduleExecutionInfo: loader.moduleExecutionInfo });
|
|
17
|
-
}
|
|
18
|
-
return null;
|
|
19
|
-
}
|
|
20
|
-
async function stopCoverageInsideWorker(options, loader, runtimeOptions) {
|
|
21
|
-
const coverageModule = await resolveCoverageProviderModule(options, loader);
|
|
22
|
-
if (coverageModule) {
|
|
23
|
-
return coverageModule.stopCoverage?.(runtimeOptions);
|
|
24
|
-
}
|
|
25
|
-
return null;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
let globalSetup = false;
|
|
29
|
-
async function setupCommonEnv(config) {
|
|
30
|
-
resetRunOnceCounter();
|
|
31
|
-
setupDefines(config.defines);
|
|
32
|
-
setupEnv(config.env);
|
|
33
|
-
if (globalSetup) {
|
|
34
|
-
return;
|
|
35
|
-
}
|
|
36
|
-
globalSetup = true;
|
|
37
|
-
setSafeTimers();
|
|
38
|
-
if (config.globals) {
|
|
39
|
-
(await import('./globals.BEpDe-k3.js')).registerApiGlobally();
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
function setupDefines(defines) {
|
|
43
|
-
for (const key in defines) {
|
|
44
|
-
globalThis[key] = defines[key];
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
function setupEnv(env) {
|
|
48
|
-
if (typeof process === "undefined") {
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
|
-
const { PROD, DEV, ...restEnvs } = env;
|
|
52
|
-
process.env.PROD = PROD ? "1" : "";
|
|
53
|
-
process.env.DEV = DEV ? "1" : "";
|
|
54
|
-
for (const key in restEnvs) {
|
|
55
|
-
process.env[key] = env[key];
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
async function loadDiffConfig(config, executor) {
|
|
59
|
-
if (typeof config.diff === "object") {
|
|
60
|
-
return config.diff;
|
|
61
|
-
}
|
|
62
|
-
if (typeof config.diff !== "string") {
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
const diffModule = await executor.executeId(config.diff);
|
|
66
|
-
if (diffModule && typeof diffModule.default === "object" && diffModule.default != null) {
|
|
67
|
-
return diffModule.default;
|
|
68
|
-
} else {
|
|
69
|
-
throw new Error(
|
|
70
|
-
`invalid diff config file ${config.diff}. Must have a default export with config object`
|
|
71
|
-
);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
async function loadSnapshotSerializers(config, executor) {
|
|
75
|
-
const files = config.snapshotSerializers;
|
|
76
|
-
const snapshotSerializers = await Promise.all(
|
|
77
|
-
files.map(async (file) => {
|
|
78
|
-
const mo = await executor.executeId(file);
|
|
79
|
-
if (!mo || typeof mo.default !== "object" || mo.default === null) {
|
|
80
|
-
throw new Error(
|
|
81
|
-
`invalid snapshot serializer file ${file}. Must export a default object`
|
|
82
|
-
);
|
|
83
|
-
}
|
|
84
|
-
const config2 = mo.default;
|
|
85
|
-
if (typeof config2.test !== "function" || typeof config2.serialize !== "function" && typeof config2.print !== "function") {
|
|
86
|
-
throw new TypeError(
|
|
87
|
-
`invalid snapshot serializer in ${file}. Must have a 'test' method along with either a 'serialize' or 'print' method.`
|
|
88
|
-
);
|
|
89
|
-
}
|
|
90
|
-
return config2;
|
|
91
|
-
})
|
|
92
|
-
);
|
|
93
|
-
snapshotSerializers.forEach((serializer) => addSerializer(serializer));
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
export { stopCoverageInsideWorker as a, loadSnapshotSerializers as b, setupCommonEnv as c, loadDiffConfig as l, startCoverageInsideWorker as s, takeCoverageInsideWorker as t };
|
|
@@ -1,77 +0,0 @@
|
|
|
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,68 +0,0 @@
|
|
|
1
|
-
import { parseRegexp } from '@vitest/utils';
|
|
2
|
-
|
|
3
|
-
const REGEXP_WRAP_PREFIX = "$$vitest:";
|
|
4
|
-
const processSend = process.send?.bind(process);
|
|
5
|
-
const processOn = process.on?.bind(process);
|
|
6
|
-
const processOff = process.off?.bind(process);
|
|
7
|
-
const dispose = [];
|
|
8
|
-
function createThreadsRpcOptions({
|
|
9
|
-
port
|
|
10
|
-
}) {
|
|
11
|
-
return {
|
|
12
|
-
post: (v) => {
|
|
13
|
-
port.postMessage(v);
|
|
14
|
-
},
|
|
15
|
-
on: (fn) => {
|
|
16
|
-
port.addListener("message", fn);
|
|
17
|
-
}
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
function disposeInternalListeners() {
|
|
21
|
-
for (const fn of dispose) {
|
|
22
|
-
try {
|
|
23
|
-
fn();
|
|
24
|
-
} catch {
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
dispose.length = 0;
|
|
28
|
-
}
|
|
29
|
-
function createForksRpcOptions(nodeV8) {
|
|
30
|
-
return {
|
|
31
|
-
serialize: nodeV8.serialize,
|
|
32
|
-
deserialize: (v) => nodeV8.deserialize(Buffer.from(v)),
|
|
33
|
-
post(v) {
|
|
34
|
-
processSend(v);
|
|
35
|
-
},
|
|
36
|
-
on(fn) {
|
|
37
|
-
const handler = (message, ...extras) => {
|
|
38
|
-
if (message?.__tinypool_worker_message__) {
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
return fn(message, ...extras);
|
|
42
|
-
};
|
|
43
|
-
processOn("message", handler);
|
|
44
|
-
dispose.push(() => processOff("message", handler));
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
function unwrapSerializableConfig(config) {
|
|
49
|
-
if (config.testNamePattern && typeof config.testNamePattern === "string") {
|
|
50
|
-
const testNamePattern = config.testNamePattern;
|
|
51
|
-
if (testNamePattern.startsWith(REGEXP_WRAP_PREFIX)) {
|
|
52
|
-
config.testNamePattern = parseRegexp(
|
|
53
|
-
testNamePattern.slice(REGEXP_WRAP_PREFIX.length)
|
|
54
|
-
);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
if (config.defines && Array.isArray(config.defines.keys) && config.defines.original) {
|
|
58
|
-
const { keys, original } = config.defines;
|
|
59
|
-
const defines = {};
|
|
60
|
-
for (const key of keys) {
|
|
61
|
-
defines[key] = original[key];
|
|
62
|
-
}
|
|
63
|
-
config.defines = defines;
|
|
64
|
-
}
|
|
65
|
-
return config;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
export { createThreadsRpcOptions as a, createForksRpcOptions as c, disposeInternalListeners as d, unwrapSerializableConfig as u };
|