vitest 3.2.4 → 4.0.0-beta.10
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 +2 -2
- package/dist/browser.d.ts +13 -16
- package/dist/browser.js +6 -5
- package/dist/chunks/base.Cjha6usc.js +129 -0
- package/dist/chunks/{benchmark.CYdenmiT.js → benchmark.CJUa-Hsa.js} +6 -8
- package/dist/chunks/{benchmark.d.BwvBVTda.d.ts → benchmark.d.DAaHLpsq.d.ts} +4 -4
- package/dist/chunks/browser.d.yFAklsD1.d.ts +18 -0
- package/dist/chunks/{cac.Cb-PYCCB.js → cac.DCxo_nSu.js} +72 -163
- package/dist/chunks/{cli-api.BkDphVBG.js → cli-api.BJJXh9BV.js} +1331 -1678
- package/dist/chunks/{config.d.D2ROskhv.d.ts → config.d.B_LthbQq.d.ts} +59 -65
- package/dist/chunks/{console.CtFJOzRO.js → console.7h5kHUIf.js} +34 -70
- package/dist/chunks/{constants.DnKduX2e.js → constants.D_Q9UYh-.js} +1 -9
- package/dist/chunks/{coverage.DL5VHqXY.js → coverage.BCU-r2QL.js} +538 -765
- package/dist/chunks/{coverage.DVF1vEu8.js → coverage.D_JHT54q.js} +2 -2
- package/dist/chunks/{coverage.d.S9RMNXIe.d.ts → coverage.d.BZtK59WP.d.ts} +10 -8
- package/dist/chunks/{creator.GK6I-cL4.js → creator.08Gi-vCA.js} +93 -77
- package/dist/chunks/{date.Bq6ZW5rf.js → date.-jtEtIeV.js} +6 -17
- package/dist/chunks/{defaults.B7q_naMc.js → defaults.CXFFjsi8.js} +2 -42
- package/dist/chunks/environment.d.BsToaxti.d.ts +65 -0
- package/dist/chunks/{git.BVQ8w_Sw.js → git.BFNcloKD.js} +1 -2
- package/dist/chunks/{global.d.MAmajcmJ.d.ts → global.d.BK3X7FW1.d.ts} +7 -32
- package/dist/chunks/{globals.DEHgCU4V.js → globals.DG-S3xFe.js} +8 -8
- package/dist/chunks/{index.VByaPkjc.js → index.BIP7prJq.js} +472 -803
- package/dist/chunks/{index.B521nVV-.js → index.Bgo3tNWt.js} +23 -4
- package/dist/chunks/{index.BCWujgDG.js → index.BjKEiSn0.js} +14 -24
- package/dist/chunks/{index.CdQS2e2Q.js → index.CMfqw92x.js} +7 -8
- package/dist/chunks/{index.CmSc2RE5.js → index.DIWhzsUh.js} +72 -118
- package/dist/chunks/{inspector.C914Efll.js → inspector.CvQD-Nie.js} +10 -25
- package/dist/chunks/moduleRunner.d.D9nBoC4p.d.ts +201 -0
- package/dist/chunks/moduleTransport.I-bgQy0S.js +19 -0
- package/dist/chunks/{node.fjCdwEIl.js → node.CyipiPvJ.js} +1 -1
- package/dist/chunks/plugin.d.BMVSnsGV.d.ts +9 -0
- package/dist/chunks/{reporters.d.BFLkQcL6.d.ts → reporters.d.BUWjmRYq.d.ts} +2086 -2146
- package/dist/chunks/resolveSnapshotEnvironment.Bkht6Yor.js +81 -0
- package/dist/chunks/resolver.Bx6lE0iq.js +119 -0
- package/dist/chunks/rpc.BKr6mtxz.js +65 -0
- package/dist/chunks/{setup-common.Dd054P77.js → setup-common.uiMcU3cv.js} +17 -29
- package/dist/chunks/startModuleRunner.p67gbNo9.js +665 -0
- package/dist/chunks/{suite.d.FvehnV49.d.ts → suite.d.BJWk38HB.d.ts} +1 -1
- package/dist/chunks/test.BiqSKISg.js +214 -0
- package/dist/chunks/{typechecker.DRKU1-1g.js → typechecker.DB-fIMaH.js} +165 -234
- package/dist/chunks/{utils.CAioKnHs.js → utils.C2YI6McM.js} +5 -14
- package/dist/chunks/{utils.XdZDrNZV.js → utils.D2R2NiOH.js} +8 -27
- package/dist/chunks/{vi.bdSIJ99Y.js → vi.ZPgvtBao.js} +156 -305
- package/dist/chunks/{vm.BThCzidc.js → vm.Ca0Y0W5f.js} +116 -226
- package/dist/chunks/{worker.d.1GmBbd7G.d.ts → worker.d.BDsXGkwh.d.ts} +31 -32
- package/dist/chunks/{worker.d.CKwWzBSj.d.ts → worker.d.BNcX_2mH.d.ts} +1 -1
- package/dist/cli.js +10 -10
- package/dist/config.cjs +5 -58
- package/dist/config.d.ts +72 -71
- package/dist/config.js +3 -9
- package/dist/coverage.d.ts +31 -24
- package/dist/coverage.js +9 -9
- package/dist/environments.d.ts +9 -14
- package/dist/environments.js +1 -1
- package/dist/index.d.ts +52 -213
- package/dist/index.js +7 -9
- package/dist/module-evaluator.d.ts +13 -0
- package/dist/module-evaluator.js +276 -0
- package/dist/module-runner.js +15 -0
- package/dist/node.d.ts +62 -51
- package/dist/node.js +26 -42
- package/dist/reporters.d.ts +11 -12
- package/dist/reporters.js +12 -12
- package/dist/runners.d.ts +3 -4
- package/dist/runners.js +13 -231
- package/dist/snapshot.js +2 -2
- package/dist/suite.d.ts +2 -2
- package/dist/suite.js +2 -2
- package/dist/worker.js +90 -47
- package/dist/workers/forks.js +34 -10
- package/dist/workers/runVmTests.js +36 -56
- package/dist/workers/threads.js +34 -10
- package/dist/workers/vmForks.js +11 -10
- package/dist/workers/vmThreads.js +11 -10
- package/dist/workers.d.ts +5 -7
- package/dist/workers.js +35 -17
- package/globals.d.ts +17 -17
- package/package.json +32 -31
- package/dist/chunks/base.DfmxU-tU.js +0 -38
- package/dist/chunks/environment.d.cL3nLXbE.d.ts +0 -119
- package/dist/chunks/execute.B7h3T_Hc.js +0 -708
- package/dist/chunks/index.CwejwG0H.js +0 -105
- package/dist/chunks/rpc.-pEldfrD.js +0 -83
- package/dist/chunks/runBaseTests.9Ij9_de-.js +0 -129
- package/dist/chunks/vite.d.CMLlLIFP.d.ts +0 -25
- package/dist/execute.d.ts +0 -150
- package/dist/execute.js +0 -13
|
@@ -1,105 +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.Dd054P77.js';
|
|
4
|
-
import { distDir } from '../path.js';
|
|
5
|
-
import { r as rpc } from './rpc.-pEldfrD.js';
|
|
6
|
-
import { g as getWorkerState } from './utils.XdZDrNZV.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.fjCdwEIl.js');
|
|
15
|
-
return new VitestNodeSnapshotEnvironment();
|
|
16
|
-
}
|
|
17
|
-
const mod = await executor.executeId(config.snapshotEnvironment);
|
|
18
|
-
if (typeof mod.default !== "object" || !mod.default) throw new Error("Snapshot environment module must have a default export object with a shape of `SnapshotEnvironment`");
|
|
19
|
-
return mod.default;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const runnersFile = resolve(distDir, "runners.js");
|
|
23
|
-
async function getTestRunnerConstructor(config, executor) {
|
|
24
|
-
if (!config.runner) {
|
|
25
|
-
const { VitestTestRunner, NodeBenchmarkRunner } = await executor.executeFile(runnersFile);
|
|
26
|
-
return config.mode === "test" ? VitestTestRunner : NodeBenchmarkRunner;
|
|
27
|
-
}
|
|
28
|
-
const mod = await executor.executeId(config.runner);
|
|
29
|
-
if (!mod.default && typeof mod.default !== "function") throw new Error(`Runner must export a default function, but got ${typeof mod.default} imported from ${config.runner}`);
|
|
30
|
-
return mod.default;
|
|
31
|
-
}
|
|
32
|
-
async function resolveTestRunner(config, executor) {
|
|
33
|
-
const TestRunner = await getTestRunnerConstructor(config, executor);
|
|
34
|
-
const testRunner = new TestRunner(config);
|
|
35
|
-
// inject private executor to every runner
|
|
36
|
-
Object.defineProperty(testRunner, "__vitest_executor", {
|
|
37
|
-
value: executor,
|
|
38
|
-
enumerable: false,
|
|
39
|
-
configurable: false
|
|
40
|
-
});
|
|
41
|
-
if (!testRunner.config) testRunner.config = config;
|
|
42
|
-
if (!testRunner.importFile) throw new Error("Runner must implement \"importFile\" method.");
|
|
43
|
-
const [diffOptions] = await Promise.all([loadDiffConfig(config, executor), loadSnapshotSerializers(config, executor)]);
|
|
44
|
-
testRunner.config.diffOptions = diffOptions;
|
|
45
|
-
// patch some methods, so custom runners don't need to call RPC
|
|
46
|
-
const originalOnTaskUpdate = testRunner.onTaskUpdate;
|
|
47
|
-
testRunner.onTaskUpdate = async (task, events) => {
|
|
48
|
-
const p = rpc().onTaskUpdate(task, events);
|
|
49
|
-
await originalOnTaskUpdate?.call(testRunner, task, events);
|
|
50
|
-
return p;
|
|
51
|
-
};
|
|
52
|
-
// patch some methods, so custom runners don't need to call RPC
|
|
53
|
-
const originalOnTestAnnotate = testRunner.onTestAnnotate;
|
|
54
|
-
testRunner.onTestAnnotate = async (test, annotation) => {
|
|
55
|
-
const p = rpc().onTaskAnnotate(test.id, annotation);
|
|
56
|
-
const overridenResult = await originalOnTestAnnotate?.call(testRunner, test, annotation);
|
|
57
|
-
const vitestResult = await p;
|
|
58
|
-
return overridenResult || vitestResult;
|
|
59
|
-
};
|
|
60
|
-
const originalOnCollectStart = testRunner.onCollectStart;
|
|
61
|
-
testRunner.onCollectStart = async (file) => {
|
|
62
|
-
await rpc().onQueued(file);
|
|
63
|
-
await originalOnCollectStart?.call(testRunner, file);
|
|
64
|
-
};
|
|
65
|
-
const originalOnCollected = testRunner.onCollected;
|
|
66
|
-
testRunner.onCollected = async (files) => {
|
|
67
|
-
const state = getWorkerState();
|
|
68
|
-
files.forEach((file) => {
|
|
69
|
-
file.prepareDuration = state.durations.prepare;
|
|
70
|
-
file.environmentLoad = state.durations.environment;
|
|
71
|
-
// should be collected only for a single test file in a batch
|
|
72
|
-
state.durations.prepare = 0;
|
|
73
|
-
state.durations.environment = 0;
|
|
74
|
-
});
|
|
75
|
-
rpc().onCollected(files);
|
|
76
|
-
await originalOnCollected?.call(testRunner, files);
|
|
77
|
-
};
|
|
78
|
-
const originalOnAfterRun = testRunner.onAfterRunFiles;
|
|
79
|
-
testRunner.onAfterRunFiles = async (files) => {
|
|
80
|
-
const state = getWorkerState();
|
|
81
|
-
const coverage = await takeCoverageInsideWorker(config.coverage, executor);
|
|
82
|
-
if (coverage) rpc().onAfterSuiteRun({
|
|
83
|
-
coverage,
|
|
84
|
-
testFiles: files.map((file) => file.name).sort(),
|
|
85
|
-
transformMode: state.environment.transformMode,
|
|
86
|
-
projectName: state.ctx.projectName
|
|
87
|
-
});
|
|
88
|
-
await originalOnAfterRun?.call(testRunner, files);
|
|
89
|
-
};
|
|
90
|
-
const originalOnAfterRunTask = testRunner.onAfterRunTask;
|
|
91
|
-
testRunner.onAfterRunTask = async (test) => {
|
|
92
|
-
if (config.bail && test.result?.state === "fail") {
|
|
93
|
-
const previousFailures = await rpc().getCountOfFailedTests();
|
|
94
|
-
const currentFailures = 1 + previousFailures;
|
|
95
|
-
if (currentFailures >= config.bail) {
|
|
96
|
-
rpc().onCancel("test-failure");
|
|
97
|
-
testRunner.cancel?.("test-failure");
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
await originalOnAfterRunTask?.call(testRunner, test);
|
|
101
|
-
};
|
|
102
|
-
return testRunner;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
export { resolveSnapshotEnvironment as a, resolveTestRunner as r, setupChaiConfig as s };
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import { getSafeTimers } from '@vitest/utils';
|
|
2
|
-
import { c as createBirpc } from './index.B521nVV-.js';
|
|
3
|
-
import { g as getWorkerState } from './utils.XdZDrNZV.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) globalThis.process.nextTick = nextTick;
|
|
19
|
-
const result = fn();
|
|
20
|
-
return result;
|
|
21
|
-
} finally {
|
|
22
|
-
globalThis.setTimeout = currentSetTimeout;
|
|
23
|
-
globalThis.clearTimeout = currentClearTimeout;
|
|
24
|
-
globalThis.setImmediate = currentSetImmediate;
|
|
25
|
-
globalThis.clearImmediate = currentClearImmediate;
|
|
26
|
-
if (globalThis.process) nextTick(() => {
|
|
27
|
-
globalThis.process.nextTick = currentNextTick;
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
const promises = /* @__PURE__ */ new Set();
|
|
32
|
-
async function rpcDone() {
|
|
33
|
-
if (!promises.size) return;
|
|
34
|
-
const awaitable = Array.from(promises);
|
|
35
|
-
return Promise.all(awaitable);
|
|
36
|
-
}
|
|
37
|
-
function createRuntimeRpc(options) {
|
|
38
|
-
let setCancel = (_reason) => {};
|
|
39
|
-
const onCancel = new Promise((resolve) => {
|
|
40
|
-
setCancel = resolve;
|
|
41
|
-
});
|
|
42
|
-
const rpc = createSafeRpc(createBirpc({ onCancel: setCancel }, {
|
|
43
|
-
eventNames: [
|
|
44
|
-
"onUserConsoleLog",
|
|
45
|
-
"onCollected",
|
|
46
|
-
"onCancel"
|
|
47
|
-
],
|
|
48
|
-
onTimeoutError(functionName, args) {
|
|
49
|
-
let message = `[vitest-worker]: Timeout calling "${functionName}"`;
|
|
50
|
-
if (functionName === "fetch" || functionName === "transform" || functionName === "resolveId") message += ` with "${JSON.stringify(args)}"`;
|
|
51
|
-
// JSON.stringify cannot serialize Error instances
|
|
52
|
-
if (functionName === "onUnhandledError") message += ` with "${args[0]?.message || args[0]}"`;
|
|
53
|
-
throw new Error(message);
|
|
54
|
-
},
|
|
55
|
-
...options
|
|
56
|
-
}));
|
|
57
|
-
return {
|
|
58
|
-
rpc,
|
|
59
|
-
onCancel
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
function createSafeRpc(rpc) {
|
|
63
|
-
return new Proxy(rpc, { get(target, p, handler) {
|
|
64
|
-
const sendCall = get(target, p, handler);
|
|
65
|
-
const safeSendCall = (...args) => withSafeTimers(async () => {
|
|
66
|
-
const result = sendCall(...args);
|
|
67
|
-
promises.add(result);
|
|
68
|
-
try {
|
|
69
|
-
return await result;
|
|
70
|
-
} finally {
|
|
71
|
-
promises.delete(result);
|
|
72
|
-
}
|
|
73
|
-
});
|
|
74
|
-
safeSendCall.asEvent = sendCall.asEvent;
|
|
75
|
-
return safeSendCall;
|
|
76
|
-
} });
|
|
77
|
-
}
|
|
78
|
-
function rpc() {
|
|
79
|
-
const { rpc } = getWorkerState();
|
|
80
|
-
return rpc;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
export { rpcDone as a, createRuntimeRpc as c, rpc as r };
|
|
@@ -1,129 +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.CwejwG0H.js';
|
|
4
|
-
import { c as setupCommonEnv, s as startCoverageInsideWorker, a as stopCoverageInsideWorker } from './setup-common.Dd054P77.js';
|
|
5
|
-
import { a as globalExpect, v as vi } from './vi.bdSIJ99Y.js';
|
|
6
|
-
import { c as closeInspector } from './inspector.C914Efll.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.CdQS2e2Q.js';
|
|
15
|
-
import { g as getWorkerState, r as resetModules } from './utils.XdZDrNZV.js';
|
|
16
|
-
import 'chai';
|
|
17
|
-
import 'node:path';
|
|
18
|
-
import '../path.js';
|
|
19
|
-
import 'node:url';
|
|
20
|
-
import './rpc.-pEldfrD.js';
|
|
21
|
-
import './index.B521nVV-.js';
|
|
22
|
-
import './coverage.DVF1vEu8.js';
|
|
23
|
-
import '@vitest/snapshot';
|
|
24
|
-
import '@vitest/expect';
|
|
25
|
-
import '@vitest/runner/utils';
|
|
26
|
-
import './_commonjsHelpers.BFTU3MAI.js';
|
|
27
|
-
import '@vitest/utils/error';
|
|
28
|
-
import '@vitest/spy';
|
|
29
|
-
import '@vitest/utils/source-map';
|
|
30
|
-
import './date.Bq6ZW5rf.js';
|
|
31
|
-
import './benchmark.CYdenmiT.js';
|
|
32
|
-
import 'expect-type';
|
|
33
|
-
|
|
34
|
-
// this should only be used in Node
|
|
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) state.config.snapshotOptions.snapshotEnvironment = await resolveSnapshotEnvironment(config, executor);
|
|
44
|
-
if (globalSetup) return;
|
|
45
|
-
globalSetup = true;
|
|
46
|
-
if (environment.transformMode === "web") {
|
|
47
|
-
const _require = createRequire(import.meta.url);
|
|
48
|
-
// always mock "required" `css` files, because we cannot process them
|
|
49
|
-
_require.extensions[".css"] = resolveCss;
|
|
50
|
-
_require.extensions[".scss"] = resolveCss;
|
|
51
|
-
_require.extensions[".sass"] = resolveCss;
|
|
52
|
-
_require.extensions[".less"] = resolveCss;
|
|
53
|
-
// since we are using Vite, we can assume how these will be resolved
|
|
54
|
-
KNOWN_ASSET_TYPES.forEach((type) => {
|
|
55
|
-
_require.extensions[`.${type}`] = resolveAsset;
|
|
56
|
-
});
|
|
57
|
-
process.env.SSR = "";
|
|
58
|
-
} else process.env.SSR = "1";
|
|
59
|
-
// @ts-expect-error not typed global for patched timers
|
|
60
|
-
globalThis.__vitest_required__ = {
|
|
61
|
-
util,
|
|
62
|
-
timers,
|
|
63
|
-
timersPromises
|
|
64
|
-
};
|
|
65
|
-
installSourcemapsSupport({ getSourceMap: (source) => state.moduleCache.getSourceMap(source) });
|
|
66
|
-
if (!config.disableConsoleIntercept) await setupConsoleLogSpy();
|
|
67
|
-
}
|
|
68
|
-
function resolveCss(mod) {
|
|
69
|
-
mod.exports = "";
|
|
70
|
-
}
|
|
71
|
-
function resolveAsset(mod, url) {
|
|
72
|
-
mod.exports = url;
|
|
73
|
-
}
|
|
74
|
-
async function setupConsoleLogSpy() {
|
|
75
|
-
const { createCustomConsole } = await import('./console.CtFJOzRO.js');
|
|
76
|
-
globalThis.console = createCustomConsole();
|
|
77
|
-
}
|
|
78
|
-
async function withEnv({ environment }, options, fn) {
|
|
79
|
-
// @ts-expect-error untyped global
|
|
80
|
-
globalThis.__vitest_environment__ = environment.name;
|
|
81
|
-
globalExpect.setState({ environment: environment.name });
|
|
82
|
-
const env = await environment.setup(globalThis, options);
|
|
83
|
-
try {
|
|
84
|
-
await fn();
|
|
85
|
-
} finally {
|
|
86
|
-
// Run possible setTimeouts, e.g. the onces used by ConsoleLogSpy
|
|
87
|
-
const { setTimeout } = getSafeTimers();
|
|
88
|
-
await new Promise((resolve) => setTimeout(resolve));
|
|
89
|
-
await env.teardown(globalThis);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
// browser shouldn't call this!
|
|
94
|
-
async function run(method, files, config, environment, executor) {
|
|
95
|
-
const workerState = getWorkerState();
|
|
96
|
-
const isIsolatedThreads = config.pool === "threads" && (config.poolOptions?.threads?.isolate ?? true);
|
|
97
|
-
const isIsolatedForks = config.pool === "forks" && (config.poolOptions?.forks?.isolate ?? true);
|
|
98
|
-
const isolate = isIsolatedThreads || isIsolatedForks;
|
|
99
|
-
await setupGlobalEnv(config, environment, executor);
|
|
100
|
-
await startCoverageInsideWorker(config.coverage, executor, { isolate });
|
|
101
|
-
if (config.chaiConfig) setupChaiConfig(config.chaiConfig);
|
|
102
|
-
const runner = await resolveTestRunner(config, executor);
|
|
103
|
-
workerState.onCancel.then((reason) => {
|
|
104
|
-
closeInspector(config);
|
|
105
|
-
runner.cancel?.(reason);
|
|
106
|
-
});
|
|
107
|
-
workerState.durations.prepare = performance.now() - workerState.durations.prepare;
|
|
108
|
-
workerState.durations.environment = performance.now();
|
|
109
|
-
await withEnv(environment, environment.options || config.environmentOptions || {}, async () => {
|
|
110
|
-
workerState.durations.environment = performance.now() - workerState.durations.environment;
|
|
111
|
-
for (const file of files) {
|
|
112
|
-
if (isolate) {
|
|
113
|
-
executor.mocker.reset();
|
|
114
|
-
resetModules(workerState.moduleCache, true);
|
|
115
|
-
}
|
|
116
|
-
workerState.filepath = file.filepath;
|
|
117
|
-
if (method === "run") await startTests([file], runner);
|
|
118
|
-
else await collectTests([file], runner);
|
|
119
|
-
// reset after tests, because user might call `vi.setConfig` in setupFile
|
|
120
|
-
vi.resetConfig();
|
|
121
|
-
// mocks should not affect different files
|
|
122
|
-
vi.restoreAllMocks();
|
|
123
|
-
}
|
|
124
|
-
await stopCoverageInsideWorker(config.coverage, executor, { isolate });
|
|
125
|
-
});
|
|
126
|
-
workerState.environmentTeardownRun = true;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
export { run };
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { HookHandler } from 'vite';
|
|
2
|
-
import { V as Vitest, T as TestProject, b as TestProjectConfiguration, I as InlineConfig } from './reporters.d.BFLkQcL6.js';
|
|
3
|
-
|
|
4
|
-
interface VitestPluginContext {
|
|
5
|
-
vitest: Vitest;
|
|
6
|
-
project: TestProject;
|
|
7
|
-
injectTestProjects: (config: TestProjectConfiguration | TestProjectConfiguration[]) => Promise<TestProject[]>;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
/* eslint-disable unused-imports/no-unused-vars */
|
|
11
|
-
|
|
12
|
-
type VitestInlineConfig = InlineConfig;
|
|
13
|
-
declare module "vite" {
|
|
14
|
-
interface UserConfig {
|
|
15
|
-
/**
|
|
16
|
-
* Options for Vitest
|
|
17
|
-
*/
|
|
18
|
-
test?: VitestInlineConfig;
|
|
19
|
-
}
|
|
20
|
-
interface Plugin<A = any> {
|
|
21
|
-
configureVitest?: HookHandler<(context: VitestPluginContext) => void>;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export type { VitestPluginContext as V };
|
package/dist/execute.d.ts
DELETED
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
import { ViteNodeRunnerOptions } from 'vite-node';
|
|
2
|
-
import { ViteNodeRunner, ModuleExecutionInfo } from 'vite-node/client';
|
|
3
|
-
import { R as RuntimeRPC, W as WorkerGlobalState } from './chunks/worker.d.1GmBbd7G.js';
|
|
4
|
-
import vm from 'node:vm';
|
|
5
|
-
import { MockedModule, MockedModuleType } from '@vitest/mocker';
|
|
6
|
-
import { P as PendingSuiteMock, b as MockFactory, a as MockOptions } from './chunks/mocker.d.BE_2ls6u.js';
|
|
7
|
-
import '@vitest/runner';
|
|
8
|
-
import './chunks/config.d.D2ROskhv.js';
|
|
9
|
-
import '@vitest/pretty-format';
|
|
10
|
-
import '@vitest/snapshot';
|
|
11
|
-
import '@vitest/snapshot/environment';
|
|
12
|
-
import '@vitest/utils/diff';
|
|
13
|
-
import './chunks/environment.d.cL3nLXbE.js';
|
|
14
|
-
import 'vitest/optional-types.js';
|
|
15
|
-
|
|
16
|
-
declare class FileMap {
|
|
17
|
-
private fsCache;
|
|
18
|
-
private fsBufferCache;
|
|
19
|
-
readFileAsync(path: string): Promise<string>;
|
|
20
|
-
readFile(path: string): string;
|
|
21
|
-
readBuffer(path: string): Buffer;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
// need to copy paste types for vm
|
|
25
|
-
// because they require latest @types/node which we don't bundle
|
|
26
|
-
interface ModuleEvaluateOptions {
|
|
27
|
-
timeout?: vm.RunningScriptOptions["timeout"] | undefined;
|
|
28
|
-
breakOnSigint?: vm.RunningScriptOptions["breakOnSigint"] | undefined;
|
|
29
|
-
}
|
|
30
|
-
type ModuleLinker = (specifier: string, referencingModule: VMModule, extra: {
|
|
31
|
-
assert: object
|
|
32
|
-
}) => VMModule | Promise<VMModule>;
|
|
33
|
-
type ModuleStatus = "unlinked" | "linking" | "linked" | "evaluating" | "evaluated" | "errored";
|
|
34
|
-
declare class VMModule {
|
|
35
|
-
dependencySpecifiers: readonly string[];
|
|
36
|
-
error: any;
|
|
37
|
-
identifier: string;
|
|
38
|
-
context: vm.Context;
|
|
39
|
-
namespace: object;
|
|
40
|
-
status: ModuleStatus;
|
|
41
|
-
evaluate(options?: ModuleEvaluateOptions): Promise<void>;
|
|
42
|
-
link(linker: ModuleLinker): Promise<void>;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
interface ExternalModulesExecutorOptions {
|
|
46
|
-
context: vm.Context;
|
|
47
|
-
fileMap: FileMap;
|
|
48
|
-
packageCache: Map<string, any>;
|
|
49
|
-
transform: RuntimeRPC["transform"];
|
|
50
|
-
interopDefault?: boolean;
|
|
51
|
-
viteClientModule: Record<string, unknown>;
|
|
52
|
-
}
|
|
53
|
-
// TODO: improve Node.js strict mode support in #2854
|
|
54
|
-
declare class ExternalModulesExecutor {
|
|
55
|
-
#private;
|
|
56
|
-
private options;
|
|
57
|
-
private cjs;
|
|
58
|
-
private esm;
|
|
59
|
-
private vite;
|
|
60
|
-
private context;
|
|
61
|
-
private fs;
|
|
62
|
-
private resolvers;
|
|
63
|
-
constructor(options: ExternalModulesExecutorOptions);
|
|
64
|
-
import(identifier: string): Promise<object>;
|
|
65
|
-
require(identifier: string): any;
|
|
66
|
-
createRequire(identifier: string): NodeJS.Require;
|
|
67
|
-
// dynamic import can be used in both ESM and CJS, so we have it in the executor
|
|
68
|
-
importModuleDynamically: (specifier: string, referencer: VMModule) => Promise<VMModule>;
|
|
69
|
-
resolveModule: (specifier: string, referencer: string) => Promise<VMModule>;
|
|
70
|
-
resolve(specifier: string, parent: string): string;
|
|
71
|
-
private findNearestPackageData;
|
|
72
|
-
private getModuleInformation;
|
|
73
|
-
private createModule;
|
|
74
|
-
private get isNetworkSupported();
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
interface MockContext {
|
|
78
|
-
/**
|
|
79
|
-
* When mocking with a factory, this refers to the module that imported the mock.
|
|
80
|
-
*/
|
|
81
|
-
callstack: null | string[];
|
|
82
|
-
}
|
|
83
|
-
declare class VitestMocker {
|
|
84
|
-
executor: VitestExecutor;
|
|
85
|
-
static pendingIds: PendingSuiteMock[];
|
|
86
|
-
private spyModule?;
|
|
87
|
-
private primitives;
|
|
88
|
-
private filterPublicKeys;
|
|
89
|
-
private registries;
|
|
90
|
-
private mockContext;
|
|
91
|
-
constructor(executor: VitestExecutor);
|
|
92
|
-
private get root();
|
|
93
|
-
private get moduleCache();
|
|
94
|
-
private get moduleDirectories();
|
|
95
|
-
initializeSpyModule(): Promise<void>;
|
|
96
|
-
private getMockerRegistry;
|
|
97
|
-
reset(): void;
|
|
98
|
-
private deleteCachedItem;
|
|
99
|
-
private isModuleDirectory;
|
|
100
|
-
getSuiteFilepath(): string;
|
|
101
|
-
private createError;
|
|
102
|
-
private resolvePath;
|
|
103
|
-
resolveMocks(): Promise<void>;
|
|
104
|
-
private callFunctionMock;
|
|
105
|
-
// public method to avoid circular dependency
|
|
106
|
-
getMockContext(): MockContext;
|
|
107
|
-
// path used to store mocked dependencies
|
|
108
|
-
getMockPath(dep: string): string;
|
|
109
|
-
getDependencyMock(id: string): MockedModule | undefined;
|
|
110
|
-
normalizePath(path: string): string;
|
|
111
|
-
resolveMockPath(mockPath: string, external: string | null): string | null;
|
|
112
|
-
mockObject(object: Record<string | symbol, any>, mockExports?: Record<string | symbol, any>, behavior?: MockedModuleType): Record<string | symbol, any>;
|
|
113
|
-
unmockPath(path: string): void;
|
|
114
|
-
mockPath(originalId: string, path: string, external: string | null, mockType: MockedModuleType | undefined, factory: MockFactory | undefined): void;
|
|
115
|
-
importActual<T>(rawId: string, importer: string, callstack?: string[] | null): Promise<T>;
|
|
116
|
-
importMock(rawId: string, importee: string): Promise<any>;
|
|
117
|
-
requestWithMock(url: string, callstack: string[]): Promise<any>;
|
|
118
|
-
queueMock(id: string, importer: string, factoryOrOptions?: MockFactory | MockOptions): void;
|
|
119
|
-
queueUnmock(id: string, importer: string): void;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
interface ExecuteOptions extends ViteNodeRunnerOptions {
|
|
123
|
-
moduleDirectories?: string[];
|
|
124
|
-
state: WorkerGlobalState;
|
|
125
|
-
context?: vm.Context;
|
|
126
|
-
externalModulesExecutor?: ExternalModulesExecutor;
|
|
127
|
-
}
|
|
128
|
-
declare class VitestExecutor extends ViteNodeRunner {
|
|
129
|
-
options: ExecuteOptions;
|
|
130
|
-
mocker: VitestMocker;
|
|
131
|
-
externalModules?: ExternalModulesExecutor;
|
|
132
|
-
private primitives;
|
|
133
|
-
constructor(options: ExecuteOptions);
|
|
134
|
-
protected getContextPrimitives(): {
|
|
135
|
-
Object: typeof Object
|
|
136
|
-
Reflect: typeof Reflect
|
|
137
|
-
Symbol: typeof Symbol
|
|
138
|
-
};
|
|
139
|
-
get state(): WorkerGlobalState;
|
|
140
|
-
get moduleExecutionInfo(): ModuleExecutionInfo | undefined;
|
|
141
|
-
shouldResolveId(id: string, _importee?: string | undefined): boolean;
|
|
142
|
-
originalResolveUrl(id: string, importer?: string): Promise<[url: string, fsPath: string]>;
|
|
143
|
-
resolveUrl(id: string, importer?: string): Promise<[url: string, fsPath: string]>;
|
|
144
|
-
protected runModule(context: Record<string, any>, transformed: string): Promise<void>;
|
|
145
|
-
importExternalModule(path: string): Promise<any>;
|
|
146
|
-
dependencyRequest(id: string, fsPath: string, callstack: string[]): Promise<any>;
|
|
147
|
-
prepareContext(context: Record<string, any>): Record<string, any>;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
export { VitestExecutor };
|
package/dist/execute.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export { V as VitestExecutor } from './chunks/execute.B7h3T_Hc.js';
|
|
2
|
-
import 'node:fs';
|
|
3
|
-
import 'node:url';
|
|
4
|
-
import 'node:vm';
|
|
5
|
-
import '@vitest/utils/error';
|
|
6
|
-
import 'pathe';
|
|
7
|
-
import 'vite-node/client';
|
|
8
|
-
import 'vite-node/utils';
|
|
9
|
-
import './path.js';
|
|
10
|
-
import 'node:path';
|
|
11
|
-
import '@vitest/mocker';
|
|
12
|
-
import 'node:module';
|
|
13
|
-
import '@vitest/utils';
|