vitest 4.0.6 → 4.0.8

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.
Files changed (65) hide show
  1. package/LICENSE.md +1 -1
  2. package/dist/browser.d.ts +2 -2
  3. package/dist/browser.js +2 -2
  4. package/dist/chunks/base.BgTO2qAg.js +156 -0
  5. package/dist/chunks/{benchmark.DHKMYAts.js → benchmark.B3N2zMcH.js} +9 -4
  6. package/dist/chunks/{browser.d.ScGeWTou.d.ts → browser.d.DTTM2PTh.d.ts} +1 -1
  7. package/dist/chunks/{cac.BBqWH4nd.js → cac.CfkWq8Qy.js} +117 -43
  8. package/dist/chunks/{cli-api.UL3SwFUb.js → cli-api.BQ-bjcRi.js} +1870 -847
  9. package/dist/chunks/console.Cf-YriPC.js +146 -0
  10. package/dist/chunks/{coverage.DuCn_Tmx.js → coverage.NVjCOln1.js} +281 -103
  11. package/dist/chunks/{creator.cqqifzG7.js → creator.fzVyoMf3.js} +74 -30
  12. package/dist/chunks/{date.-jtEtIeV.js → date.Bq6ZW5rf.js} +17 -6
  13. package/dist/chunks/{git.BFNcloKD.js → git.Bm2pzPAa.js} +3 -3
  14. package/dist/chunks/{global.d.DdOkMiVb.d.ts → global.d.DVdCfKp5.d.ts} +1 -1
  15. package/dist/chunks/{globals.BGT_RUsD.js → globals.DOh96BiR.js} +5 -5
  16. package/dist/chunks/{resolveSnapshotEnvironment.BZzLjzkh.js → index.BY4-tcno.js} +42 -25
  17. package/dist/chunks/{index.Bgo3tNWt.js → index.DAL392Ss.js} +40 -15
  18. package/dist/chunks/{index.RwjEGCQ0.js → index.DIFZf73e.js} +2 -2
  19. package/dist/chunks/{index.DV0mQLEO.js → index.DfKyPFVi.js} +195 -64
  20. package/dist/chunks/{index.BL8Hg4Uk.js → index.kotH7DY7.js} +837 -380
  21. package/dist/chunks/{index.CpdwpN7L.js → index.op2Re5rn.js} +22 -12
  22. package/dist/chunks/{init-forks.CSGFj9zN.js → init-forks.2hx7cf78.js} +16 -5
  23. package/dist/chunks/{init-threads.CIJLeFO8.js → init-threads.Cm4OCIWA.js} +3 -2
  24. package/dist/chunks/{init.DUeOfNO9.js → init.DMDG-idf.js} +124 -54
  25. package/dist/chunks/{inspector.DLZxSeU3.js → inspector.CvyFGlXm.js} +25 -10
  26. package/dist/chunks/{moduleRunner.d.TP-w6tIQ.d.ts → moduleRunner.d.CzOZ_4wC.d.ts} +1 -1
  27. package/dist/chunks/{node.BwAWWjHZ.js → node.Ce0vMQM7.js} +1 -1
  28. package/dist/chunks/{plugin.d.lctzD3Wk.d.ts → plugin.d.D4RrtywJ.d.ts} +1 -1
  29. package/dist/chunks/{reporters.d.PEs0tXod.d.ts → reporters.d.Da1D1VbQ.d.ts} +19 -9
  30. package/dist/chunks/rpc.BUV7uWKJ.js +76 -0
  31. package/dist/chunks/{setup-common.DR1sucx6.js → setup-common.LGjNSzXp.js} +20 -8
  32. package/dist/chunks/{startModuleRunner.Di-EZqh0.js → startModuleRunner.BOmUtLIO.js} +228 -105
  33. package/dist/chunks/{test.CnspO-X4.js → test.ClrAtjMv.js} +48 -22
  34. package/dist/chunks/{utils.CG9h5ccR.js → utils.DvEY5TfP.js} +14 -5
  35. package/dist/chunks/{vi.BZvkKVkM.js → vi.Bgcdy3bQ.js} +261 -111
  36. package/dist/chunks/{vm.Co_lR2NL.js → vm.BIkCDs68.js} +177 -70
  37. package/dist/chunks/{worker.d.B4Hthdvt.d.ts → worker.d.DadbA89M.d.ts} +52 -6
  38. package/dist/cli.js +2 -2
  39. package/dist/config.d.ts +5 -5
  40. package/dist/coverage.d.ts +3 -3
  41. package/dist/coverage.js +1 -1
  42. package/dist/environments.js +2 -1
  43. package/dist/index.d.ts +5 -5
  44. package/dist/index.js +5 -5
  45. package/dist/module-evaluator.d.ts +2 -2
  46. package/dist/module-evaluator.js +85 -35
  47. package/dist/module-runner.js +2 -2
  48. package/dist/node.d.ts +7 -7
  49. package/dist/node.js +16 -12
  50. package/dist/reporters.d.ts +3 -3
  51. package/dist/reporters.js +2 -2
  52. package/dist/runners.js +7 -7
  53. package/dist/snapshot.js +2 -2
  54. package/dist/suite.js +2 -2
  55. package/dist/worker.d.ts +2 -1
  56. package/dist/worker.js +27 -27
  57. package/dist/workers/forks.js +34 -31
  58. package/dist/workers/runVmTests.js +41 -22
  59. package/dist/workers/threads.js +34 -31
  60. package/dist/workers/vmForks.js +14 -14
  61. package/dist/workers/vmThreads.js +14 -14
  62. package/package.json +20 -20
  63. package/dist/chunks/base.BAf_bYeI.js +0 -128
  64. package/dist/chunks/console.CTJL2nuH.js +0 -115
  65. package/dist/chunks/rpc.Dv1Jt3i2.js +0 -66
@@ -1,128 +0,0 @@
1
- import { runInThisContext } from 'node:vm';
2
- import * as spyModule from '@vitest/spy';
3
- import { V as VitestEvaluatedModules } from './evaluatedModules.Dg1zASAC.js';
4
- import { s as startVitestModuleRunner, c as createNodeImportMeta } from './startModuleRunner.Di-EZqh0.js';
5
- import { performance } from 'node:perf_hooks';
6
- import { startTests, collectTests } from '@vitest/runner';
7
- import { a as resolveSnapshotEnvironment, s as setupChaiConfig, r as resolveTestRunner } from './resolveSnapshotEnvironment.BZzLjzkh.js';
8
- import { c as setupCommonEnv, s as startCoverageInsideWorker, a as stopCoverageInsideWorker } from './setup-common.DR1sucx6.js';
9
- import { g as globalExpect, v as vi } from './vi.BZvkKVkM.js';
10
- import { c as closeInspector } from './inspector.DLZxSeU3.js';
11
- import { createRequire } from 'node:module';
12
- import timers from 'node:timers';
13
- import timersPromises from 'node:timers/promises';
14
- import util from 'node:util';
15
- import { KNOWN_ASSET_TYPES } from '@vitest/utils/constants';
16
- import { getSafeTimers } from '@vitest/utils/timers';
17
- import { i as index } from './index.RwjEGCQ0.js';
18
- import { g as getWorkerState, r as resetModules, p as provideWorkerState } from './utils.CG9h5ccR.js';
19
-
20
- // this should only be used in Node
21
- let globalSetup = false;
22
- async function setupGlobalEnv(config, { environment }, moduleRunner) {
23
- await setupCommonEnv(config), Object.defineProperty(globalThis, "__vitest_index__", {
24
- value: index,
25
- enumerable: false
26
- });
27
- const state = getWorkerState();
28
- if (!state.config.snapshotOptions.snapshotEnvironment) state.config.snapshotOptions.snapshotEnvironment = await resolveSnapshotEnvironment(config, moduleRunner);
29
- if (!globalSetup) {
30
- if (globalSetup = true, (environment.viteEnvironment || environment.name) === "client") {
31
- const _require = createRequire(import.meta.url);
32
- _require.extensions[".css"] = resolveCss, _require.extensions[".scss"] = resolveCss, _require.extensions[".sass"] = resolveCss, _require.extensions[".less"] = resolveCss, KNOWN_ASSET_TYPES.forEach((type) => {
33
- _require.extensions[`.${type}`] = resolveAsset;
34
- }), process.env.SSR = "";
35
- } else process.env.SSR = "1";
36
- if (globalThis.__vitest_required__ = {
37
- util,
38
- timers,
39
- timersPromises
40
- }, !config.disableConsoleIntercept) await setupConsoleLogSpy();
41
- }
42
- }
43
- function resolveCss(mod) {
44
- mod.exports = "";
45
- }
46
- function resolveAsset(mod, url) {
47
- mod.exports = url;
48
- }
49
- async function setupConsoleLogSpy() {
50
- const { createCustomConsole } = await import('./console.CTJL2nuH.js');
51
- globalThis.console = createCustomConsole();
52
- }
53
- async function withEnv({ environment }, options, fn) {
54
- globalThis.__vitest_environment__ = environment.name, globalExpect.setState({ environment: environment.name });
55
- const env = await environment.setup(globalThis, options);
56
- try {
57
- await fn();
58
- } finally {
59
- // Run possible setTimeouts, e.g. the onces used by ConsoleLogSpy
60
- const { setTimeout } = getSafeTimers();
61
- await new Promise((resolve) => setTimeout(resolve)), await env.teardown(globalThis);
62
- }
63
- }
64
-
65
- // browser shouldn't call this!
66
- async function run(method, files, config, environment, moduleRunner) {
67
- const workerState = getWorkerState();
68
- if (await setupGlobalEnv(config, environment, moduleRunner), await startCoverageInsideWorker(config.coverage, moduleRunner, { isolate: config.isolate }), config.chaiConfig) setupChaiConfig(config.chaiConfig);
69
- const runner = await resolveTestRunner(config, moduleRunner);
70
- workerState.onCancel.then((reason) => {
71
- closeInspector(config), runner.cancel?.(reason);
72
- }), workerState.durations.prepare = performance.now() - workerState.durations.prepare, workerState.durations.environment = performance.now(), await withEnv(environment, environment.options || config.environmentOptions || {}, async () => {
73
- workerState.durations.environment = performance.now() - workerState.durations.environment;
74
- for (const file of files) {
75
- if (config.isolate) moduleRunner.mocker.reset(), resetModules(workerState.evaluatedModules, true);
76
- if (workerState.filepath = file.filepath, method === "run") await startTests([file], runner);
77
- else await collectTests([file], runner);
78
- // mocks should not affect different files
79
- vi.resetConfig(), vi.restoreAllMocks();
80
- }
81
- await stopCoverageInsideWorker(config.coverage, moduleRunner, { isolate: config.isolate });
82
- }), workerState.environmentTeardownRun = true;
83
- }
84
-
85
- let _moduleRunner;
86
- const evaluatedModules = new VitestEvaluatedModules(), moduleExecutionInfo = /* @__PURE__ */ new Map();
87
- function startModuleRunner(options) {
88
- return _moduleRunner || (_moduleRunner = startVitestModuleRunner(options), _moduleRunner);
89
- }
90
- /** @experimental */
91
- async function runBaseTests(method, state) {
92
- const { ctx } = state;
93
- if (state.evaluatedModules = evaluatedModules, state.moduleExecutionInfo = moduleExecutionInfo, provideWorkerState(globalThis, state), ctx.invalidates) ctx.invalidates.forEach((filepath) => {
94
- (state.evaluatedModules.fileToModulesMap.get(filepath) || []).forEach((module) => {
95
- state.evaluatedModules.invalidateModule(module);
96
- });
97
- });
98
- ctx.files.forEach((i) => {
99
- const filepath = typeof i === "string" ? i : i.filepath;
100
- (state.evaluatedModules.fileToModulesMap.get(filepath) || []).forEach((module) => {
101
- state.evaluatedModules.invalidateModule(module);
102
- });
103
- });
104
- const executor = startModuleRunner({
105
- state,
106
- evaluatedModules: state.evaluatedModules,
107
- spyModule,
108
- createImportMeta: createNodeImportMeta
109
- }), fileSpecs = ctx.files.map((f) => typeof f === "string" ? {
110
- filepath: f,
111
- testLocations: void 0
112
- } : f);
113
- // we could load @vite/env, but it would take ~8ms, while this takes ~0,02ms
114
- if (ctx.config.serializedDefines) try {
115
- runInThisContext(`(() =>{\n${ctx.config.serializedDefines}})()`, {
116
- lineOffset: 1,
117
- filename: "virtual:load-defines.js"
118
- });
119
- } catch (error) {
120
- throw new Error(`Failed to load custom "defines": ${error.message}`);
121
- }
122
- await run(method, fileSpecs, ctx.config, {
123
- environment: state.environment,
124
- options: ctx.environment.options
125
- }, executor);
126
- }
127
-
128
- export { runBaseTests as r };
@@ -1,115 +0,0 @@
1
- import { Console } from 'node:console';
2
- import { relative } from 'node:path';
3
- import { Writable } from 'node:stream';
4
- import { getSafeTimers } from '@vitest/utils/timers';
5
- import c from 'tinyrainbow';
6
- import { R as RealDate } from './date.-jtEtIeV.js';
7
- import { g as getWorkerState } from './utils.CG9h5ccR.js';
8
-
9
- const UNKNOWN_TEST_ID = "__vitest__unknown_test__";
10
- function getTaskIdByStack(root) {
11
- const stack = (/* @__PURE__ */ new Error("STACK_TRACE_ERROR")).stack?.split("\n");
12
- if (!stack) return UNKNOWN_TEST_ID;
13
- const index = stack.findIndex((line) => line.includes("at Console.value")), line = index === -1 ? null : stack[index + 2];
14
- if (!line) return UNKNOWN_TEST_ID;
15
- const filepath = line.match(/at\s(.*)\s?/)?.[1];
16
- return filepath ? relative(root, filepath) : UNKNOWN_TEST_ID;
17
- }
18
- function createCustomConsole(defaultState) {
19
- const stdoutBuffer = /* @__PURE__ */ new Map(), stderrBuffer = /* @__PURE__ */ new Map(), timers = /* @__PURE__ */ new Map(), { queueMicrotask } = getSafeTimers();
20
- function queueCancelableMicrotask(callback) {
21
- let canceled = false;
22
- return queueMicrotask(() => {
23
- if (!canceled) callback();
24
- }), () => {
25
- canceled = true;
26
- };
27
- }
28
- const state = () => defaultState || getWorkerState();
29
- // group sync console.log calls with micro task
30
- function schedule(taskId) {
31
- const timer = timers.get(taskId), { stdoutTime, stderrTime } = timer;
32
- timer.cancel?.(), timer.cancel = queueCancelableMicrotask(() => {
33
- if (stderrTime < stdoutTime) sendStderr(taskId), sendStdout(taskId);
34
- else sendStdout(taskId), sendStderr(taskId);
35
- });
36
- }
37
- function sendStdout(taskId) {
38
- sendBuffer("stdout", taskId);
39
- }
40
- function sendStderr(taskId) {
41
- sendBuffer("stderr", taskId);
42
- }
43
- function sendBuffer(type, taskId) {
44
- const buffers = type === "stdout" ? stdoutBuffer : stderrBuffer, buffer = buffers.get(taskId);
45
- if (!buffer) return;
46
- if (state().config.printConsoleTrace) buffer.forEach(([buffer, origin]) => {
47
- sendLog(type, taskId, String(buffer), buffer.length, origin);
48
- });
49
- else {
50
- const content = buffer.map((i) => String(i[0])).join("");
51
- sendLog(type, taskId, content, buffer.length);
52
- }
53
- const timer = timers.get(taskId);
54
- if (buffers.delete(taskId), type === "stderr") timer.stderrTime = 0;
55
- else timer.stdoutTime = 0;
56
- }
57
- function sendLog(type, taskId, content, size, origin) {
58
- const timer = timers.get(taskId), time = type === "stderr" ? timer.stderrTime : timer.stdoutTime;
59
- state().rpc.onUserConsoleLog({
60
- type,
61
- content: content || "<empty line>",
62
- taskId,
63
- time: time || RealDate.now(),
64
- size,
65
- origin
66
- });
67
- }
68
- const stdout = new Writable({ write(data, encoding, callback) {
69
- const s = state(), id = s?.current?.id || s?.current?.suite?.id || s.current?.file.id || getTaskIdByStack(s.config.root);
70
- let timer = timers.get(id);
71
- if (timer) timer.stdoutTime = timer.stdoutTime || RealDate.now();
72
- else timer = {
73
- stdoutTime: RealDate.now(),
74
- stderrTime: RealDate.now()
75
- }, timers.set(id, timer);
76
- let buffer = stdoutBuffer.get(id);
77
- if (!buffer) buffer = [], stdoutBuffer.set(id, buffer);
78
- if (state().config.printConsoleTrace) {
79
- const limit = Error.stackTraceLimit;
80
- Error.stackTraceLimit = limit + 6;
81
- const trace = (/* @__PURE__ */ new Error("STACK_TRACE")).stack?.split("\n").slice(7).join("\n");
82
- Error.stackTraceLimit = limit, buffer.push([data, trace]);
83
- } else buffer.push([data, void 0]);
84
- schedule(id), callback();
85
- } }), stderr = new Writable({ write(data, encoding, callback) {
86
- const s = state(), id = s?.current?.id || s?.current?.suite?.id || s.current?.file.id || getTaskIdByStack(s.config.root);
87
- let timer = timers.get(id);
88
- if (timer) timer.stderrTime = timer.stderrTime || RealDate.now();
89
- else timer = {
90
- stderrTime: RealDate.now(),
91
- stdoutTime: RealDate.now()
92
- }, timers.set(id, timer);
93
- let buffer = stderrBuffer.get(id);
94
- if (!buffer) buffer = [], stderrBuffer.set(id, buffer);
95
- if (state().config.printConsoleTrace) {
96
- const limit = Error.stackTraceLimit;
97
- Error.stackTraceLimit = limit + 6;
98
- const stack = (/* @__PURE__ */ new Error("STACK_TRACE")).stack?.split("\n");
99
- if (Error.stackTraceLimit = limit, stack?.some((line) => line.includes("at Console.trace"))) buffer.push([data, void 0]);
100
- else {
101
- const trace = stack?.slice(7).join("\n");
102
- Error.stackTraceLimit = limit, buffer.push([data, trace]);
103
- }
104
- } else buffer.push([data, void 0]);
105
- schedule(id), callback();
106
- } });
107
- return new Console({
108
- stdout,
109
- stderr,
110
- colorMode: c.isColorSupported,
111
- groupIndentation: 2
112
- });
113
- }
114
-
115
- export { UNKNOWN_TEST_ID, createCustomConsole };
@@ -1,66 +0,0 @@
1
- import { getSafeTimers } from '@vitest/utils/timers';
2
- import { c as createBirpc } from './index.Bgo3tNWt.js';
3
- import { g as getWorkerState } from './utils.CG9h5ccR.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
- return fn();
13
- } finally {
14
- if (globalThis.setTimeout = currentSetTimeout, globalThis.clearTimeout = currentClearTimeout, globalThis.setImmediate = currentSetImmediate, globalThis.clearImmediate = currentClearImmediate, globalThis.process && nextTick) nextTick(() => {
15
- globalThis.process.nextTick = currentNextTick;
16
- });
17
- }
18
- }
19
- const promises = /* @__PURE__ */ new Set();
20
- async function rpcDone() {
21
- if (!promises.size) return;
22
- const awaitable = Array.from(promises);
23
- return Promise.all(awaitable);
24
- }
25
- let previousRpc;
26
- function createRuntimeRpc(options) {
27
- if (previousRpc) previousRpc.$close(), previousRpc = void 0;
28
- let setCancel = (_reason) => {};
29
- const onCancel = new Promise((resolve) => {
30
- setCancel = resolve;
31
- }), rpc = createSafeRpc(createBirpc({ onCancel: setCancel }, {
32
- eventNames: [
33
- "onUserConsoleLog",
34
- "onCollected",
35
- "onCancel"
36
- ],
37
- timeout: -1,
38
- ...options
39
- }));
40
- return previousRpc = rpc, {
41
- rpc,
42
- onCancel
43
- };
44
- }
45
- function createSafeRpc(rpc) {
46
- return new Proxy(rpc, { get(target, p, handler) {
47
- // keep $rejectPendingCalls as sync function
48
- if (p === "$rejectPendingCalls") return rpc.$rejectPendingCalls;
49
- const sendCall = get(target, p, handler), safeSendCall = (...args) => withSafeTimers(async () => {
50
- const result = sendCall(...args);
51
- promises.add(result);
52
- try {
53
- return await result;
54
- } finally {
55
- promises.delete(result);
56
- }
57
- });
58
- return safeSendCall.asEvent = sendCall.asEvent, safeSendCall;
59
- } });
60
- }
61
- function rpc() {
62
- const { rpc } = getWorkerState();
63
- return rpc;
64
- }
65
-
66
- export { rpcDone as a, createRuntimeRpc as c, rpc as r };