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
package/dist/suite.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { g as getBenchFn, a as getBenchOptions } from './chunks/suite.d.
|
|
1
|
+
export { g as getBenchFn, a as getBenchOptions } from './chunks/suite.d.BJWk38HB.js';
|
|
2
2
|
export { VitestRunner, VitestRunnerConfig, createTaskCollector, getCurrentSuite, getCurrentTest, getFn, getHooks, setFn, setHooks } from '@vitest/runner';
|
|
3
3
|
export { createChainable } from '@vitest/runner/utils';
|
|
4
|
-
import './chunks/benchmark.d.
|
|
4
|
+
import './chunks/benchmark.d.DAaHLpsq.js';
|
|
5
5
|
import 'tinybench';
|
package/dist/suite.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
export { g as getBenchFn, a as getBenchOptions } from './chunks/benchmark.
|
|
1
|
+
export { g as getBenchFn, a as getBenchOptions } from './chunks/benchmark.LXhJ0F0X.js';
|
|
2
2
|
export { createTaskCollector, getCurrentSuite, getCurrentTest, getFn, getHooks, setFn, setHooks } from '@vitest/runner';
|
|
3
3
|
export { createChainable } from '@vitest/runner/utils';
|
|
4
|
-
import '@vitest/utils';
|
|
5
|
-
import './chunks/utils.
|
|
4
|
+
import '@vitest/utils/helpers';
|
|
5
|
+
import './chunks/utils.DGKhod2J.js';
|
|
6
|
+
import '@vitest/utils/timers';
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
import { c as createForksRpcOptions, u as unwrapSerializableConfig, a as createThreadsRpcOptions, e as execute, t as teardown$1 } from './chunks/worker.rPGLlbkW.js';
|
|
2
|
+
import v8 from 'node:v8';
|
|
3
|
+
import { runInThisContext } from 'node:vm';
|
|
4
|
+
import * as spyModule from '@vitest/spy';
|
|
5
|
+
import { EvaluatedModules } from 'vite/module-runner';
|
|
6
|
+
import { s as startVitestModuleRunner, c as createNodeImportMeta } from './chunks/startModuleRunner.oAuCu1yL.js';
|
|
7
|
+
import { performance } from 'node:perf_hooks';
|
|
8
|
+
import { startTests, collectTests } from '@vitest/runner';
|
|
9
|
+
import { a as resolveSnapshotEnvironment, s as setupChaiConfig, r as resolveTestRunner } from './chunks/resolveSnapshotEnvironment.DQVamkje.js';
|
|
10
|
+
import { c as setupCommonEnv, s as startCoverageInsideWorker, a as stopCoverageInsideWorker } from './chunks/setup-common.NAWRuMRP.js';
|
|
11
|
+
import { g as globalExpect, v as vi } from './chunks/vi.CiJ0Laa6.js';
|
|
12
|
+
import { c as closeInspector } from './chunks/inspector.CvQD-Nie.js';
|
|
13
|
+
import { createRequire } from 'node:module';
|
|
14
|
+
import timers from 'node:timers';
|
|
15
|
+
import timersPromises from 'node:timers/promises';
|
|
16
|
+
import util from 'node:util';
|
|
17
|
+
import { KNOWN_ASSET_TYPES } from '@vitest/utils/constants';
|
|
18
|
+
import { getSafeTimers } from '@vitest/utils/timers';
|
|
19
|
+
import { i as index } from './chunks/index.AZOjjqWP.js';
|
|
20
|
+
import { g as getWorkerState, r as resetModules, p as provideWorkerState } from './chunks/utils.DGKhod2J.js';
|
|
21
|
+
import '@vitest/utils/source-map';
|
|
22
|
+
import 'node:fs';
|
|
23
|
+
import 'node:url';
|
|
24
|
+
import 'pathe';
|
|
25
|
+
import './chunks/index.DIWhzsUh.js';
|
|
26
|
+
import 'node:console';
|
|
27
|
+
import './chunks/rpc.jKGRSXIH.js';
|
|
28
|
+
import './chunks/index.Bgo3tNWt.js';
|
|
29
|
+
import '@vitest/utils/helpers';
|
|
30
|
+
import './path.js';
|
|
31
|
+
import 'node:path';
|
|
32
|
+
import '@vitest/utils/serialize';
|
|
33
|
+
import './module-evaluator.js';
|
|
34
|
+
import '@vitest/mocker';
|
|
35
|
+
import '@vitest/expect';
|
|
36
|
+
import './chunks/test.KC5tH8hC.js';
|
|
37
|
+
import './chunks/benchmark.LXhJ0F0X.js';
|
|
38
|
+
import '@vitest/runner/utils';
|
|
39
|
+
import '@vitest/utils/error';
|
|
40
|
+
import './chunks/coverage.D_JHT54q.js';
|
|
41
|
+
import '@vitest/snapshot';
|
|
42
|
+
import './chunks/_commonjsHelpers.BFTU3MAI.js';
|
|
43
|
+
import '@vitest/utils/offset';
|
|
44
|
+
import './chunks/date.-jtEtIeV.js';
|
|
45
|
+
import 'expect-type';
|
|
46
|
+
|
|
47
|
+
// this should only be used in Node
|
|
48
|
+
let globalSetup = false;
|
|
49
|
+
async function setupGlobalEnv(config, { environment }, moduleRunner) {
|
|
50
|
+
await setupCommonEnv(config), Object.defineProperty(globalThis, "__vitest_index__", {
|
|
51
|
+
value: index,
|
|
52
|
+
enumerable: false
|
|
53
|
+
});
|
|
54
|
+
const state = getWorkerState();
|
|
55
|
+
if (!state.config.snapshotOptions.snapshotEnvironment) state.config.snapshotOptions.snapshotEnvironment = await resolveSnapshotEnvironment(config, moduleRunner);
|
|
56
|
+
if (globalSetup) return;
|
|
57
|
+
globalSetup = true;
|
|
58
|
+
const viteEnvironment = environment.viteEnvironment || environment.name;
|
|
59
|
+
if (viteEnvironment === "client") {
|
|
60
|
+
const _require = createRequire(import.meta.url);
|
|
61
|
+
_require.extensions[".css"] = resolveCss, _require.extensions[".scss"] = resolveCss, _require.extensions[".sass"] = resolveCss, _require.extensions[".less"] = resolveCss, KNOWN_ASSET_TYPES.forEach((type) => {
|
|
62
|
+
_require.extensions[`.${type}`] = resolveAsset;
|
|
63
|
+
}), process.env.SSR = "";
|
|
64
|
+
} else process.env.SSR = "1";
|
|
65
|
+
if (globalThis.__vitest_required__ = {
|
|
66
|
+
util,
|
|
67
|
+
timers,
|
|
68
|
+
timersPromises
|
|
69
|
+
}, !config.disableConsoleIntercept) await setupConsoleLogSpy();
|
|
70
|
+
}
|
|
71
|
+
function resolveCss(mod) {
|
|
72
|
+
mod.exports = "";
|
|
73
|
+
}
|
|
74
|
+
function resolveAsset(mod, url) {
|
|
75
|
+
mod.exports = url;
|
|
76
|
+
}
|
|
77
|
+
async function setupConsoleLogSpy() {
|
|
78
|
+
const { createCustomConsole } = await import('./chunks/console.CiTi59Jy.js');
|
|
79
|
+
globalThis.console = createCustomConsole();
|
|
80
|
+
}
|
|
81
|
+
async function withEnv({ environment }, options, fn) {
|
|
82
|
+
globalThis.__vitest_environment__ = environment.name, globalExpect.setState({ environment: environment.name });
|
|
83
|
+
const env = await environment.setup(globalThis, options);
|
|
84
|
+
try {
|
|
85
|
+
await fn();
|
|
86
|
+
} finally {
|
|
87
|
+
// Run possible setTimeouts, e.g. the onces used by ConsoleLogSpy
|
|
88
|
+
const { setTimeout } = getSafeTimers();
|
|
89
|
+
await new Promise((resolve) => setTimeout(resolve)), await env.teardown(globalThis);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// browser shouldn't call this!
|
|
94
|
+
async function run$1(method, files, config, environment, moduleRunner) {
|
|
95
|
+
const workerState = getWorkerState(), isIsolatedThreads = config.pool === "threads" && (config.poolOptions?.threads?.isolate ?? true), isIsolatedForks = config.pool === "forks" && (config.poolOptions?.forks?.isolate ?? true), isolate = isIsolatedThreads || isIsolatedForks;
|
|
96
|
+
if (await setupGlobalEnv(config, environment, moduleRunner), await startCoverageInsideWorker(config.coverage, moduleRunner, { isolate }), config.chaiConfig) setupChaiConfig(config.chaiConfig);
|
|
97
|
+
const runner = await resolveTestRunner(config, moduleRunner);
|
|
98
|
+
workerState.onCancel.then((reason) => {
|
|
99
|
+
closeInspector(config), runner.cancel?.(reason);
|
|
100
|
+
}), workerState.durations.prepare = performance.now() - workerState.durations.prepare, workerState.durations.environment = performance.now(), await withEnv(environment, environment.options || config.environmentOptions || {}, async () => {
|
|
101
|
+
workerState.durations.environment = performance.now() - workerState.durations.environment;
|
|
102
|
+
for (const file of files) {
|
|
103
|
+
if (isolate) moduleRunner.mocker.reset(), resetModules(workerState.evaluatedModules, true);
|
|
104
|
+
if (workerState.filepath = file.filepath, method === "run") await startTests([file], runner);
|
|
105
|
+
else await collectTests([file], runner);
|
|
106
|
+
// mocks should not affect different files
|
|
107
|
+
vi.resetConfig(), vi.restoreAllMocks();
|
|
108
|
+
}
|
|
109
|
+
await stopCoverageInsideWorker(config.coverage, moduleRunner, { isolate });
|
|
110
|
+
}), workerState.environmentTeardownRun = true;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
let _moduleRunner;
|
|
114
|
+
const evaluatedModules = new EvaluatedModules(), moduleExecutionInfo = /* @__PURE__ */ new Map();
|
|
115
|
+
function startModuleRunner(options) {
|
|
116
|
+
return _moduleRunner || (_moduleRunner = startVitestModuleRunner(options), _moduleRunner);
|
|
117
|
+
}
|
|
118
|
+
async function runBaseTests(method, state) {
|
|
119
|
+
const { ctx } = state;
|
|
120
|
+
if (state.evaluatedModules = evaluatedModules, state.moduleExecutionInfo = moduleExecutionInfo, provideWorkerState(globalThis, state), ctx.invalidates) ctx.invalidates.forEach((filepath) => {
|
|
121
|
+
const modules = state.evaluatedModules.fileToModulesMap.get(filepath) || [];
|
|
122
|
+
modules.forEach((module) => {
|
|
123
|
+
state.evaluatedModules.invalidateModule(module);
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
ctx.files.forEach((i) => {
|
|
127
|
+
const filepath = typeof i === "string" ? i : i.filepath, modules = state.evaluatedModules.fileToModulesMap.get(filepath) || [];
|
|
128
|
+
modules.forEach((module) => {
|
|
129
|
+
state.evaluatedModules.invalidateModule(module);
|
|
130
|
+
});
|
|
131
|
+
});
|
|
132
|
+
const executor = startModuleRunner({
|
|
133
|
+
state,
|
|
134
|
+
evaluatedModules: state.evaluatedModules,
|
|
135
|
+
spyModule,
|
|
136
|
+
createImportMeta: createNodeImportMeta
|
|
137
|
+
}), fileSpecs = ctx.files.map((f) => typeof f === "string" ? {
|
|
138
|
+
filepath: f,
|
|
139
|
+
testLocations: void 0
|
|
140
|
+
} : f);
|
|
141
|
+
// we could load @vite/env, but it would take ~8ms, while this takes ~0,02ms
|
|
142
|
+
if (ctx.config.serializedDefines) try {
|
|
143
|
+
runInThisContext(`(() =>{\n${ctx.config.serializedDefines}})()`, {
|
|
144
|
+
lineOffset: 1,
|
|
145
|
+
filename: "virtual:load-defines.js"
|
|
146
|
+
});
|
|
147
|
+
} catch (error) {
|
|
148
|
+
throw new Error(`Failed to load custom "defines": ${error.message}`);
|
|
149
|
+
}
|
|
150
|
+
await run$1(method, fileSpecs, ctx.config, {
|
|
151
|
+
environment: state.environment,
|
|
152
|
+
options: ctx.environment.options
|
|
153
|
+
}, executor);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
class ForksBaseWorker {
|
|
157
|
+
getRpcOptions() {
|
|
158
|
+
return createForksRpcOptions(v8);
|
|
159
|
+
}
|
|
160
|
+
async executeTests(method, state) {
|
|
161
|
+
// TODO: don't rely on reassigning process.exit
|
|
162
|
+
// https://github.com/vitest-dev/vitest/pull/4441#discussion_r1443771486
|
|
163
|
+
const exit = process.exit;
|
|
164
|
+
state.ctx.config = unwrapSerializableConfig(state.ctx.config);
|
|
165
|
+
try {
|
|
166
|
+
await runBaseTests(method, state);
|
|
167
|
+
} finally {
|
|
168
|
+
process.exit = exit;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
runTests(state) {
|
|
172
|
+
return this.executeTests("run", state);
|
|
173
|
+
}
|
|
174
|
+
collectTests(state) {
|
|
175
|
+
return this.executeTests("collect", state);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
const worker$1 = new ForksBaseWorker();
|
|
179
|
+
|
|
180
|
+
class ThreadsBaseWorker {
|
|
181
|
+
getRpcOptions(ctx) {
|
|
182
|
+
return createThreadsRpcOptions(ctx);
|
|
183
|
+
}
|
|
184
|
+
runTests(state) {
|
|
185
|
+
return runBaseTests("run", state);
|
|
186
|
+
}
|
|
187
|
+
collectTests(state) {
|
|
188
|
+
return runBaseTests("collect", state);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
const worker = new ThreadsBaseWorker();
|
|
192
|
+
|
|
193
|
+
async function run(ctx) {
|
|
194
|
+
await execute("run", ctx, ctx.pool === "forks" ? worker$1 : worker);
|
|
195
|
+
}
|
|
196
|
+
async function collect(ctx) {
|
|
197
|
+
await execute("collect", ctx, ctx.pool === "forks" ? worker$1 : worker);
|
|
198
|
+
}
|
|
199
|
+
async function teardown() {
|
|
200
|
+
await teardown$1();
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
export { collect, run, teardown };
|