vitest 4.0.0-beta.1 → 4.0.0-beta.11
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 +83 -2
- package/dist/browser.d.ts +19 -16
- package/dist/browser.js +11 -7
- package/dist/chunks/{benchmark.CYdenmiT.js → benchmark.LXhJ0F0X.js} +7 -9
- package/dist/chunks/{benchmark.d.BwvBVTda.d.ts → benchmark.d.DAaHLpsq.d.ts} +4 -4
- package/dist/chunks/{browser.d.q8Z0P0q1.d.ts → browser.d.Dx7DO_Ce.d.ts} +5 -5
- package/dist/chunks/{cac.D3EzDDZd.js → cac.elvK37c9.js} +71 -153
- package/dist/chunks/{cli-api.Dn5gKePv.js → cli-api.C7plPyhs.js} +1376 -1693
- package/dist/chunks/{config.d.HJdfX-8k.d.ts → config.d.B_LthbQq.d.ts} +58 -63
- package/dist/chunks/{console.CtFJOzRO.js → console.CiTi59Jy.js} +35 -71
- package/dist/chunks/{constants.DnKduX2e.js → constants.D_Q9UYh-.js} +1 -9
- package/dist/chunks/{coverage.Cwa-XhJt.js → coverage.CG6Uhorw.js} +522 -792
- 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/{environment.d.CUq4cUgQ.d.ts → environment.d.BsToaxti.d.ts} +27 -6
- package/dist/chunks/{git.BVQ8w_Sw.js → git.BFNcloKD.js} +1 -2
- package/dist/chunks/{global.d.CVbXEflG.d.ts → global.d.BK3X7FW1.d.ts} +2 -5
- package/dist/chunks/{globals.Cxal6MLI.js → globals.BjvYA-AD.js} +11 -9
- package/dist/chunks/{index.BWf_gE5n.js → index.AZOjjqWP.js} +7 -6
- package/dist/chunks/{index.B521nVV-.js → index.Bgo3tNWt.js} +23 -4
- package/dist/chunks/{index.TfbsX-3I.js → index.BhY64fF0.js} +16 -26
- package/dist/chunks/{index.CZI_8rVt.js → index.BwBttQPf.js} +340 -663
- 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.BNa-CL9e.d.ts +201 -0
- package/dist/chunks/{node.fjCdwEIl.js → node.BsdMi6DV.js} +2 -2
- package/dist/chunks/{plugin.d.C2EcJUjo.d.ts → plugin.d.C5phQR6o.d.ts} +1 -1
- package/dist/chunks/{reporters.d.DxZg19fy.d.ts → reporters.d.CVzhsTvK.d.ts} +1233 -1293
- package/dist/chunks/resolveSnapshotEnvironment.DQVamkje.js +81 -0
- package/dist/chunks/rpc.jKGRSXIH.js +65 -0
- package/dist/chunks/{setup-common.D7ZqXFx-.js → setup-common.NAWRuMRP.js} +18 -30
- package/dist/chunks/startModuleRunner.oAuCu1yL.js +682 -0
- package/dist/chunks/{suite.d.FvehnV49.d.ts → suite.d.BJWk38HB.d.ts} +1 -1
- package/dist/chunks/test.KC5tH8hC.js +214 -0
- package/dist/chunks/typechecker.gXq-5P3n.js +1438 -0
- package/dist/chunks/{utils.XdZDrNZV.js → utils.DGKhod2J.js} +9 -28
- package/dist/chunks/{vi.bdSIJ99Y.js → vi.CiJ0Laa6.js} +159 -306
- package/dist/chunks/worker.d.B_Fd9M_w.d.ts +100 -0
- package/dist/chunks/worker.rPGLlbkW.js +200 -0
- package/dist/cli.js +8 -6
- package/dist/config.cjs +3 -9
- package/dist/config.d.ts +49 -54
- package/dist/config.js +1 -1
- package/dist/coverage.d.ts +27 -26
- package/dist/coverage.js +6 -8
- package/dist/environments.d.ts +9 -13
- package/dist/environments.js +1 -1
- package/dist/index.d.ts +38 -45
- package/dist/index.js +10 -10
- 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 +44 -42
- package/dist/node.js +30 -36
- package/dist/reporters.d.ts +12 -13
- package/dist/reporters.js +7 -5
- package/dist/runners.d.ts +3 -3
- package/dist/runners.js +15 -232
- package/dist/snapshot.js +3 -3
- package/dist/suite.d.ts +2 -2
- package/dist/suite.js +4 -3
- package/dist/worker-base.js +203 -0
- package/dist/{chunks/vm.BThCzidc.js → worker-vm.js} +179 -228
- package/dist/workers/runVmTests.js +39 -56
- package/globals.d.ts +17 -17
- package/package.json +40 -38
- package/browser.d.ts +0 -1
- package/dist/chunks/base.Bj3pWTr1.js +0 -38
- package/dist/chunks/execute.B7h3T_Hc.js +0 -708
- package/dist/chunks/index.D-VkfKhf.js +0 -105
- package/dist/chunks/rpc.CsFtxqeq.js +0 -83
- package/dist/chunks/runBaseTests.BC7ZIH5L.js +0 -129
- package/dist/chunks/typechecker.CVytUJuF.js +0 -874
- package/dist/chunks/utils.CAioKnHs.js +0 -61
- package/dist/chunks/worker.d.CmvJfRGs.d.ts +0 -8
- package/dist/chunks/worker.d.DoNjFAiv.d.ts +0 -169
- package/dist/execute.d.ts +0 -148
- package/dist/execute.js +0 -13
- package/dist/worker.js +0 -124
- package/dist/workers/forks.js +0 -43
- package/dist/workers/threads.js +0 -31
- package/dist/workers/vmForks.js +0 -47
- package/dist/workers/vmThreads.js +0 -37
- package/dist/workers.d.ts +0 -37
- package/dist/workers.js +0 -30
- package/execute.d.ts +0 -1
- package/utils.d.ts +0 -1
- package/workers.d.ts +0 -1
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { chai } from '@vitest/expect';
|
|
2
|
+
import { l as loadDiffConfig, b as loadSnapshotSerializers, t as takeCoverageInsideWorker } from './setup-common.NAWRuMRP.js';
|
|
3
|
+
import { r as rpc } from './rpc.jKGRSXIH.js';
|
|
4
|
+
import { g as getWorkerState } from './utils.DGKhod2J.js';
|
|
5
|
+
import { V as VitestTestRunner, N as NodeBenchmarkRunner } from './test.KC5tH8hC.js';
|
|
6
|
+
|
|
7
|
+
function setupChaiConfig(config) {
|
|
8
|
+
Object.assign(chai.config, config);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
async function getTestRunnerConstructor(config, moduleRunner) {
|
|
12
|
+
if (!config.runner) return config.mode === "test" ? VitestTestRunner : NodeBenchmarkRunner;
|
|
13
|
+
const mod = await moduleRunner.import(config.runner);
|
|
14
|
+
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}`);
|
|
15
|
+
return mod.default;
|
|
16
|
+
}
|
|
17
|
+
async function resolveTestRunner(config, moduleRunner) {
|
|
18
|
+
const TestRunner = await getTestRunnerConstructor(config, moduleRunner), testRunner = new TestRunner(config);
|
|
19
|
+
if (Object.defineProperty(testRunner, "moduleRunner", {
|
|
20
|
+
value: moduleRunner,
|
|
21
|
+
enumerable: false,
|
|
22
|
+
configurable: false
|
|
23
|
+
}), !testRunner.config) testRunner.config = config;
|
|
24
|
+
if (!testRunner.importFile) throw new Error("Runner must implement \"importFile\" method.");
|
|
25
|
+
const [diffOptions] = await Promise.all([loadDiffConfig(config, moduleRunner), loadSnapshotSerializers(config, moduleRunner)]);
|
|
26
|
+
testRunner.config.diffOptions = diffOptions;
|
|
27
|
+
// patch some methods, so custom runners don't need to call RPC
|
|
28
|
+
const originalOnTaskUpdate = testRunner.onTaskUpdate;
|
|
29
|
+
testRunner.onTaskUpdate = async (task, events) => {
|
|
30
|
+
const p = rpc().onTaskUpdate(task, events);
|
|
31
|
+
return await originalOnTaskUpdate?.call(testRunner, task, events), p;
|
|
32
|
+
};
|
|
33
|
+
// patch some methods, so custom runners don't need to call RPC
|
|
34
|
+
const originalOnTestAnnotate = testRunner.onTestAnnotate;
|
|
35
|
+
testRunner.onTestAnnotate = async (test, annotation) => {
|
|
36
|
+
const p = rpc().onTaskAnnotate(test.id, annotation), overriddenResult = await originalOnTestAnnotate?.call(testRunner, test, annotation), vitestResult = await p;
|
|
37
|
+
return overriddenResult || vitestResult;
|
|
38
|
+
};
|
|
39
|
+
const originalOnCollectStart = testRunner.onCollectStart;
|
|
40
|
+
testRunner.onCollectStart = async (file) => {
|
|
41
|
+
await rpc().onQueued(file), await originalOnCollectStart?.call(testRunner, file);
|
|
42
|
+
};
|
|
43
|
+
const originalOnCollected = testRunner.onCollected;
|
|
44
|
+
testRunner.onCollected = async (files) => {
|
|
45
|
+
const state = getWorkerState();
|
|
46
|
+
files.forEach((file) => {
|
|
47
|
+
file.prepareDuration = state.durations.prepare, file.environmentLoad = state.durations.environment, state.durations.prepare = 0, state.durations.environment = 0;
|
|
48
|
+
}), rpc().onCollected(files), await originalOnCollected?.call(testRunner, files);
|
|
49
|
+
};
|
|
50
|
+
const originalOnAfterRun = testRunner.onAfterRunFiles;
|
|
51
|
+
testRunner.onAfterRunFiles = async (files) => {
|
|
52
|
+
const state = getWorkerState(), coverage = await takeCoverageInsideWorker(config.coverage, moduleRunner);
|
|
53
|
+
if (coverage) rpc().onAfterSuiteRun({
|
|
54
|
+
coverage,
|
|
55
|
+
testFiles: files.map((file) => file.name).sort(),
|
|
56
|
+
environment: state.environment.viteEnvironment || state.environment.name,
|
|
57
|
+
projectName: state.ctx.projectName
|
|
58
|
+
});
|
|
59
|
+
await originalOnAfterRun?.call(testRunner, files);
|
|
60
|
+
};
|
|
61
|
+
const originalOnAfterRunTask = testRunner.onAfterRunTask;
|
|
62
|
+
return testRunner.onAfterRunTask = async (test) => {
|
|
63
|
+
if (config.bail && test.result?.state === "fail") {
|
|
64
|
+
const previousFailures = await rpc().getCountOfFailedTests(), currentFailures = 1 + previousFailures;
|
|
65
|
+
if (currentFailures >= config.bail) rpc().onCancel("test-failure"), testRunner.cancel?.("test-failure");
|
|
66
|
+
}
|
|
67
|
+
await originalOnAfterRunTask?.call(testRunner, test);
|
|
68
|
+
}, testRunner;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
async function resolveSnapshotEnvironment(config, executor) {
|
|
72
|
+
if (!config.snapshotEnvironment) {
|
|
73
|
+
const { VitestNodeSnapshotEnvironment } = await import('./node.BsdMi6DV.js');
|
|
74
|
+
return new VitestNodeSnapshotEnvironment();
|
|
75
|
+
}
|
|
76
|
+
const mod = await executor.import(config.snapshotEnvironment);
|
|
77
|
+
if (typeof mod.default !== "object" || !mod.default) throw new Error("Snapshot environment module must have a default export object with a shape of `SnapshotEnvironment`");
|
|
78
|
+
return mod.default;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export { resolveSnapshotEnvironment as a, resolveTestRunner as r, setupChaiConfig as s };
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { getSafeTimers } from '@vitest/utils/timers';
|
|
2
|
+
import { c as createBirpc } from './index.Bgo3tNWt.js';
|
|
3
|
+
import { g as getWorkerState } from './utils.DGKhod2J.js';
|
|
4
|
+
|
|
5
|
+
const { get } = Reflect;
|
|
6
|
+
function withSafeTimers(fn) {
|
|
7
|
+
const { setTimeout, clearTimeout, nextTick, setImmediate, clearImmediate } = getSafeTimers(), currentSetTimeout = globalThis.setTimeout, currentClearTimeout = globalThis.clearTimeout, currentSetImmediate = globalThis.setImmediate, currentClearImmediate = globalThis.clearImmediate, currentNextTick = globalThis.process?.nextTick;
|
|
8
|
+
try {
|
|
9
|
+
if (globalThis.setTimeout = setTimeout, globalThis.clearTimeout = clearTimeout, setImmediate) globalThis.setImmediate = setImmediate;
|
|
10
|
+
if (clearImmediate) globalThis.clearImmediate = clearImmediate;
|
|
11
|
+
if (globalThis.process && nextTick) globalThis.process.nextTick = nextTick;
|
|
12
|
+
const result = fn();
|
|
13
|
+
return result;
|
|
14
|
+
} finally {
|
|
15
|
+
if (globalThis.setTimeout = currentSetTimeout, globalThis.clearTimeout = currentClearTimeout, globalThis.setImmediate = currentSetImmediate, globalThis.clearImmediate = currentClearImmediate, globalThis.process && nextTick) nextTick(() => {
|
|
16
|
+
globalThis.process.nextTick = currentNextTick;
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
const promises = /* @__PURE__ */ new Set();
|
|
21
|
+
async function rpcDone() {
|
|
22
|
+
if (!promises.size) return;
|
|
23
|
+
const awaitable = Array.from(promises);
|
|
24
|
+
return Promise.all(awaitable);
|
|
25
|
+
}
|
|
26
|
+
function createRuntimeRpc(options) {
|
|
27
|
+
let setCancel = (_reason) => {};
|
|
28
|
+
const onCancel = new Promise((resolve) => {
|
|
29
|
+
setCancel = resolve;
|
|
30
|
+
}), rpc = createSafeRpc(createBirpc({ onCancel: setCancel }, {
|
|
31
|
+
eventNames: [
|
|
32
|
+
"onUserConsoleLog",
|
|
33
|
+
"onCollected",
|
|
34
|
+
"onCancel"
|
|
35
|
+
],
|
|
36
|
+
timeout: -1,
|
|
37
|
+
...options
|
|
38
|
+
}));
|
|
39
|
+
return {
|
|
40
|
+
rpc,
|
|
41
|
+
onCancel
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
function createSafeRpc(rpc) {
|
|
45
|
+
return new Proxy(rpc, { get(target, p, handler) {
|
|
46
|
+
// keep $rejectPendingCalls as sync function
|
|
47
|
+
if (p === "$rejectPendingCalls") return rpc.$rejectPendingCalls;
|
|
48
|
+
const sendCall = get(target, p, handler), safeSendCall = (...args) => withSafeTimers(async () => {
|
|
49
|
+
const result = sendCall(...args);
|
|
50
|
+
promises.add(result);
|
|
51
|
+
try {
|
|
52
|
+
return await result;
|
|
53
|
+
} finally {
|
|
54
|
+
promises.delete(result);
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
return safeSendCall.asEvent = sendCall.asEvent, safeSendCall;
|
|
58
|
+
} });
|
|
59
|
+
}
|
|
60
|
+
function rpc() {
|
|
61
|
+
const { rpc } = getWorkerState();
|
|
62
|
+
return rpc;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export { rpcDone as a, createRuntimeRpc as c, rpc as r };
|
|
@@ -1,54 +1,42 @@
|
|
|
1
|
-
import { r as resolveCoverageProviderModule } from './coverage.
|
|
1
|
+
import { r as resolveCoverageProviderModule } from './coverage.D_JHT54q.js';
|
|
2
2
|
import { addSerializer } from '@vitest/snapshot';
|
|
3
|
-
import { setSafeTimers } from '@vitest/utils';
|
|
3
|
+
import { setSafeTimers } from '@vitest/utils/timers';
|
|
4
|
+
import { g as getWorkerState } from './utils.DGKhod2J.js';
|
|
4
5
|
|
|
5
6
|
async function startCoverageInsideWorker(options, loader, runtimeOptions) {
|
|
6
7
|
const coverageModule = await resolveCoverageProviderModule(options, loader);
|
|
7
|
-
|
|
8
|
-
return null;
|
|
8
|
+
return coverageModule ? coverageModule.startCoverage?.(runtimeOptions) : null;
|
|
9
9
|
}
|
|
10
10
|
async function takeCoverageInsideWorker(options, loader) {
|
|
11
11
|
const coverageModule = await resolveCoverageProviderModule(options, loader);
|
|
12
|
-
|
|
13
|
-
return null;
|
|
12
|
+
return coverageModule ? coverageModule.takeCoverage?.({ moduleExecutionInfo: loader.moduleExecutionInfo }) : null;
|
|
14
13
|
}
|
|
15
14
|
async function stopCoverageInsideWorker(options, loader, runtimeOptions) {
|
|
16
15
|
const coverageModule = await resolveCoverageProviderModule(options, loader);
|
|
17
|
-
|
|
18
|
-
return null;
|
|
16
|
+
return coverageModule ? coverageModule.stopCoverage?.(runtimeOptions) : null;
|
|
19
17
|
}
|
|
20
18
|
|
|
21
19
|
let globalSetup = false;
|
|
22
20
|
async function setupCommonEnv(config) {
|
|
23
|
-
setupDefines(config.
|
|
24
|
-
setupEnv(config.env);
|
|
25
|
-
if (globalSetup) return;
|
|
26
|
-
globalSetup = true;
|
|
27
|
-
setSafeTimers();
|
|
28
|
-
if (config.globals) (await import('./globals.Cxal6MLI.js')).registerApiGlobally();
|
|
21
|
+
if (setupDefines(config), setupEnv(config.env), !globalSetup && (globalSetup = true, setSafeTimers(), config.globals)) (await import('./globals.BjvYA-AD.js')).registerApiGlobally();
|
|
29
22
|
}
|
|
30
|
-
function setupDefines(
|
|
31
|
-
for (const key in defines) globalThis[key] = defines[key];
|
|
23
|
+
function setupDefines(config) {
|
|
24
|
+
for (const key in config.defines) globalThis[key] = config.defines[key];
|
|
32
25
|
}
|
|
33
26
|
function setupEnv(env) {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
process.env.DEV = DEV ? "1" : "";
|
|
39
|
-
for (const key in restEnvs) process.env[key] = env[key];
|
|
40
|
-
}
|
|
41
|
-
async function loadDiffConfig(config, executor) {
|
|
27
|
+
const state = getWorkerState(), { PROD, DEV,...restEnvs } = env;
|
|
28
|
+
for (const key in state.metaEnv.PROD = PROD, state.metaEnv.DEV = DEV, restEnvs) state.metaEnv[key] = env[key];
|
|
29
|
+
}
|
|
30
|
+
async function loadDiffConfig(config, moduleRunner) {
|
|
42
31
|
if (typeof config.diff === "object") return config.diff;
|
|
43
32
|
if (typeof config.diff !== "string") return;
|
|
44
|
-
const diffModule = await
|
|
33
|
+
const diffModule = await moduleRunner.import(config.diff);
|
|
45
34
|
if (diffModule && typeof diffModule.default === "object" && diffModule.default != null) return diffModule.default;
|
|
46
|
-
|
|
35
|
+
throw new Error(`invalid diff config file ${config.diff}. Must have a default export with config object`);
|
|
47
36
|
}
|
|
48
|
-
async function loadSnapshotSerializers(config,
|
|
49
|
-
const files = config.snapshotSerializers
|
|
50
|
-
|
|
51
|
-
const mo = await executor.executeId(file);
|
|
37
|
+
async function loadSnapshotSerializers(config, moduleRunner) {
|
|
38
|
+
const files = config.snapshotSerializers, snapshotSerializers = await Promise.all(files.map(async (file) => {
|
|
39
|
+
const mo = await moduleRunner.import(file);
|
|
52
40
|
if (!mo || typeof mo.default !== "object" || mo.default === null) throw new Error(`invalid snapshot serializer file ${file}. Must export a default object`);
|
|
53
41
|
const config = mo.default;
|
|
54
42
|
if (typeof config.test !== "function" || typeof config.serialize !== "function" && typeof config.print !== "function") throw new TypeError(`invalid snapshot serializer in ${file}. Must have a 'test' method along with either a 'serialize' or 'print' method.`);
|