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.
Files changed (90) hide show
  1. package/LICENSE.md +83 -2
  2. package/dist/browser.d.ts +19 -16
  3. package/dist/browser.js +11 -7
  4. package/dist/chunks/{benchmark.CYdenmiT.js → benchmark.LXhJ0F0X.js} +7 -9
  5. package/dist/chunks/{benchmark.d.BwvBVTda.d.ts → benchmark.d.DAaHLpsq.d.ts} +4 -4
  6. package/dist/chunks/{browser.d.q8Z0P0q1.d.ts → browser.d.Dx7DO_Ce.d.ts} +5 -5
  7. package/dist/chunks/{cac.D3EzDDZd.js → cac.elvK37c9.js} +71 -153
  8. package/dist/chunks/{cli-api.Dn5gKePv.js → cli-api.C7plPyhs.js} +1376 -1693
  9. package/dist/chunks/{config.d.HJdfX-8k.d.ts → config.d.B_LthbQq.d.ts} +58 -63
  10. package/dist/chunks/{console.CtFJOzRO.js → console.CiTi59Jy.js} +35 -71
  11. package/dist/chunks/{constants.DnKduX2e.js → constants.D_Q9UYh-.js} +1 -9
  12. package/dist/chunks/{coverage.Cwa-XhJt.js → coverage.CG6Uhorw.js} +522 -792
  13. package/dist/chunks/{coverage.DVF1vEu8.js → coverage.D_JHT54q.js} +2 -2
  14. package/dist/chunks/{coverage.d.S9RMNXIe.d.ts → coverage.d.BZtK59WP.d.ts} +10 -8
  15. package/dist/chunks/{creator.GK6I-cL4.js → creator.08Gi-vCA.js} +93 -77
  16. package/dist/chunks/{date.Bq6ZW5rf.js → date.-jtEtIeV.js} +6 -17
  17. package/dist/chunks/{environment.d.CUq4cUgQ.d.ts → environment.d.BsToaxti.d.ts} +27 -6
  18. package/dist/chunks/{git.BVQ8w_Sw.js → git.BFNcloKD.js} +1 -2
  19. package/dist/chunks/{global.d.CVbXEflG.d.ts → global.d.BK3X7FW1.d.ts} +2 -5
  20. package/dist/chunks/{globals.Cxal6MLI.js → globals.BjvYA-AD.js} +11 -9
  21. package/dist/chunks/{index.BWf_gE5n.js → index.AZOjjqWP.js} +7 -6
  22. package/dist/chunks/{index.B521nVV-.js → index.Bgo3tNWt.js} +23 -4
  23. package/dist/chunks/{index.TfbsX-3I.js → index.BhY64fF0.js} +16 -26
  24. package/dist/chunks/{index.CZI_8rVt.js → index.BwBttQPf.js} +340 -663
  25. package/dist/chunks/{index.CmSc2RE5.js → index.DIWhzsUh.js} +72 -118
  26. package/dist/chunks/{inspector.C914Efll.js → inspector.CvQD-Nie.js} +10 -25
  27. package/dist/chunks/moduleRunner.d.BNa-CL9e.d.ts +201 -0
  28. package/dist/chunks/{node.fjCdwEIl.js → node.BsdMi6DV.js} +2 -2
  29. package/dist/chunks/{plugin.d.C2EcJUjo.d.ts → plugin.d.C5phQR6o.d.ts} +1 -1
  30. package/dist/chunks/{reporters.d.DxZg19fy.d.ts → reporters.d.CVzhsTvK.d.ts} +1233 -1293
  31. package/dist/chunks/resolveSnapshotEnvironment.DQVamkje.js +81 -0
  32. package/dist/chunks/rpc.jKGRSXIH.js +65 -0
  33. package/dist/chunks/{setup-common.D7ZqXFx-.js → setup-common.NAWRuMRP.js} +18 -30
  34. package/dist/chunks/startModuleRunner.oAuCu1yL.js +682 -0
  35. package/dist/chunks/{suite.d.FvehnV49.d.ts → suite.d.BJWk38HB.d.ts} +1 -1
  36. package/dist/chunks/test.KC5tH8hC.js +214 -0
  37. package/dist/chunks/typechecker.gXq-5P3n.js +1438 -0
  38. package/dist/chunks/{utils.XdZDrNZV.js → utils.DGKhod2J.js} +9 -28
  39. package/dist/chunks/{vi.bdSIJ99Y.js → vi.CiJ0Laa6.js} +159 -306
  40. package/dist/chunks/worker.d.B_Fd9M_w.d.ts +100 -0
  41. package/dist/chunks/worker.rPGLlbkW.js +200 -0
  42. package/dist/cli.js +8 -6
  43. package/dist/config.cjs +3 -9
  44. package/dist/config.d.ts +49 -54
  45. package/dist/config.js +1 -1
  46. package/dist/coverage.d.ts +27 -26
  47. package/dist/coverage.js +6 -8
  48. package/dist/environments.d.ts +9 -13
  49. package/dist/environments.js +1 -1
  50. package/dist/index.d.ts +38 -45
  51. package/dist/index.js +10 -10
  52. package/dist/module-evaluator.d.ts +13 -0
  53. package/dist/module-evaluator.js +276 -0
  54. package/dist/module-runner.js +15 -0
  55. package/dist/node.d.ts +44 -42
  56. package/dist/node.js +30 -36
  57. package/dist/reporters.d.ts +12 -13
  58. package/dist/reporters.js +7 -5
  59. package/dist/runners.d.ts +3 -3
  60. package/dist/runners.js +15 -232
  61. package/dist/snapshot.js +3 -3
  62. package/dist/suite.d.ts +2 -2
  63. package/dist/suite.js +4 -3
  64. package/dist/worker-base.js +203 -0
  65. package/dist/{chunks/vm.BThCzidc.js → worker-vm.js} +179 -228
  66. package/dist/workers/runVmTests.js +39 -56
  67. package/globals.d.ts +17 -17
  68. package/package.json +40 -38
  69. package/browser.d.ts +0 -1
  70. package/dist/chunks/base.Bj3pWTr1.js +0 -38
  71. package/dist/chunks/execute.B7h3T_Hc.js +0 -708
  72. package/dist/chunks/index.D-VkfKhf.js +0 -105
  73. package/dist/chunks/rpc.CsFtxqeq.js +0 -83
  74. package/dist/chunks/runBaseTests.BC7ZIH5L.js +0 -129
  75. package/dist/chunks/typechecker.CVytUJuF.js +0 -874
  76. package/dist/chunks/utils.CAioKnHs.js +0 -61
  77. package/dist/chunks/worker.d.CmvJfRGs.d.ts +0 -8
  78. package/dist/chunks/worker.d.DoNjFAiv.d.ts +0 -169
  79. package/dist/execute.d.ts +0 -148
  80. package/dist/execute.js +0 -13
  81. package/dist/worker.js +0 -124
  82. package/dist/workers/forks.js +0 -43
  83. package/dist/workers/threads.js +0 -31
  84. package/dist/workers/vmForks.js +0 -47
  85. package/dist/workers/vmThreads.js +0 -37
  86. package/dist/workers.d.ts +0 -37
  87. package/dist/workers.js +0 -30
  88. package/execute.d.ts +0 -1
  89. package/utils.d.ts +0 -1
  90. package/workers.d.ts +0 -1
@@ -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.D7ZqXFx-.js';
4
- import { distDir } from '../path.js';
5
- import { r as rpc } from './rpc.CsFtxqeq.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
- if (setImmediate) globalThis.setImmediate = setImmediate;
17
- if (clearImmediate) globalThis.clearImmediate = clearImmediate;
18
- if (globalThis.process && nextTick) 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) 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.D-VkfKhf.js';
4
- import { c as setupCommonEnv, s as startCoverageInsideWorker, a as stopCoverageInsideWorker } from './setup-common.D7ZqXFx-.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.BWf_gE5n.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.CsFtxqeq.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 };