vitest 4.0.0-beta.1 → 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.
Files changed (85) hide show
  1. package/LICENSE.md +2 -2
  2. package/dist/browser.d.ts +13 -14
  3. package/dist/browser.js +6 -5
  4. package/dist/chunks/base.Cjha6usc.js +129 -0
  5. package/dist/chunks/{benchmark.CYdenmiT.js → benchmark.CJUa-Hsa.js} +6 -8
  6. package/dist/chunks/{benchmark.d.BwvBVTda.d.ts → benchmark.d.DAaHLpsq.d.ts} +4 -4
  7. package/dist/chunks/{browser.d.q8Z0P0q1.d.ts → browser.d.yFAklsD1.d.ts} +5 -5
  8. package/dist/chunks/{cac.D3EzDDZd.js → cac.DCxo_nSu.js} +70 -152
  9. package/dist/chunks/{cli-api.Dn5gKePv.js → cli-api.BJJXh9BV.js} +1330 -1677
  10. package/dist/chunks/{config.d.HJdfX-8k.d.ts → config.d.B_LthbQq.d.ts} +58 -63
  11. package/dist/chunks/{console.CtFJOzRO.js → console.7h5kHUIf.js} +34 -70
  12. package/dist/chunks/{constants.DnKduX2e.js → constants.D_Q9UYh-.js} +1 -9
  13. package/dist/chunks/{coverage.Cwa-XhJt.js → coverage.BCU-r2QL.js} +515 -781
  14. package/dist/chunks/{coverage.DVF1vEu8.js → coverage.D_JHT54q.js} +2 -2
  15. package/dist/chunks/{coverage.d.S9RMNXIe.d.ts → coverage.d.BZtK59WP.d.ts} +10 -8
  16. package/dist/chunks/{creator.GK6I-cL4.js → creator.08Gi-vCA.js} +93 -77
  17. package/dist/chunks/{date.Bq6ZW5rf.js → date.-jtEtIeV.js} +6 -17
  18. package/dist/chunks/{environment.d.CUq4cUgQ.d.ts → environment.d.BsToaxti.d.ts} +27 -6
  19. package/dist/chunks/{git.BVQ8w_Sw.js → git.BFNcloKD.js} +1 -2
  20. package/dist/chunks/{global.d.CVbXEflG.d.ts → global.d.BK3X7FW1.d.ts} +2 -5
  21. package/dist/chunks/{globals.Cxal6MLI.js → globals.DG-S3xFe.js} +8 -8
  22. package/dist/chunks/{index.CZI_8rVt.js → index.BIP7prJq.js} +289 -608
  23. package/dist/chunks/{index.B521nVV-.js → index.Bgo3tNWt.js} +23 -4
  24. package/dist/chunks/{index.TfbsX-3I.js → index.BjKEiSn0.js} +14 -24
  25. package/dist/chunks/{index.BWf_gE5n.js → index.CMfqw92x.js} +7 -6
  26. package/dist/chunks/{index.CmSc2RE5.js → index.DIWhzsUh.js} +72 -118
  27. package/dist/chunks/{inspector.C914Efll.js → inspector.CvQD-Nie.js} +10 -25
  28. package/dist/chunks/moduleRunner.d.D9nBoC4p.d.ts +201 -0
  29. package/dist/chunks/moduleTransport.I-bgQy0S.js +19 -0
  30. package/dist/chunks/{node.fjCdwEIl.js → node.CyipiPvJ.js} +1 -1
  31. package/dist/chunks/{plugin.d.C2EcJUjo.d.ts → plugin.d.BMVSnsGV.d.ts} +1 -1
  32. package/dist/chunks/{reporters.d.DxZg19fy.d.ts → reporters.d.BUWjmRYq.d.ts} +1226 -1291
  33. package/dist/chunks/resolveSnapshotEnvironment.Bkht6Yor.js +81 -0
  34. package/dist/chunks/resolver.Bx6lE0iq.js +119 -0
  35. package/dist/chunks/rpc.BKr6mtxz.js +65 -0
  36. package/dist/chunks/{setup-common.D7ZqXFx-.js → setup-common.uiMcU3cv.js} +17 -29
  37. package/dist/chunks/startModuleRunner.p67gbNo9.js +665 -0
  38. package/dist/chunks/{suite.d.FvehnV49.d.ts → suite.d.BJWk38HB.d.ts} +1 -1
  39. package/dist/chunks/test.BiqSKISg.js +214 -0
  40. package/dist/chunks/{typechecker.CVytUJuF.js → typechecker.DB-fIMaH.js} +144 -213
  41. package/dist/chunks/{utils.CAioKnHs.js → utils.C2YI6McM.js} +5 -14
  42. package/dist/chunks/{utils.XdZDrNZV.js → utils.D2R2NiOH.js} +8 -27
  43. package/dist/chunks/{vi.bdSIJ99Y.js → vi.ZPgvtBao.js} +156 -305
  44. package/dist/chunks/{vm.BThCzidc.js → vm.Ca0Y0W5f.js} +116 -226
  45. package/dist/chunks/{worker.d.DoNjFAiv.d.ts → worker.d.BDsXGkwh.d.ts} +28 -22
  46. package/dist/chunks/{worker.d.CmvJfRGs.d.ts → worker.d.BNcX_2mH.d.ts} +1 -1
  47. package/dist/cli.js +4 -4
  48. package/dist/config.cjs +3 -9
  49. package/dist/config.d.ts +49 -54
  50. package/dist/config.js +1 -1
  51. package/dist/coverage.d.ts +27 -26
  52. package/dist/coverage.js +6 -7
  53. package/dist/environments.d.ts +9 -13
  54. package/dist/environments.js +1 -1
  55. package/dist/index.d.ts +38 -45
  56. package/dist/index.js +7 -9
  57. package/dist/module-evaluator.d.ts +13 -0
  58. package/dist/module-evaluator.js +276 -0
  59. package/dist/module-runner.js +15 -0
  60. package/dist/node.d.ts +40 -41
  61. package/dist/node.js +23 -33
  62. package/dist/reporters.d.ts +12 -13
  63. package/dist/reporters.js +3 -3
  64. package/dist/runners.d.ts +3 -3
  65. package/dist/runners.js +13 -232
  66. package/dist/snapshot.js +2 -2
  67. package/dist/suite.d.ts +2 -2
  68. package/dist/suite.js +2 -2
  69. package/dist/worker.js +90 -47
  70. package/dist/workers/forks.js +34 -10
  71. package/dist/workers/runVmTests.js +36 -56
  72. package/dist/workers/threads.js +34 -10
  73. package/dist/workers/vmForks.js +11 -10
  74. package/dist/workers/vmThreads.js +11 -10
  75. package/dist/workers.d.ts +5 -4
  76. package/dist/workers.js +35 -17
  77. package/globals.d.ts +17 -17
  78. package/package.json +32 -31
  79. package/dist/chunks/base.Bj3pWTr1.js +0 -38
  80. package/dist/chunks/execute.B7h3T_Hc.js +0 -708
  81. package/dist/chunks/index.D-VkfKhf.js +0 -105
  82. package/dist/chunks/rpc.CsFtxqeq.js +0 -83
  83. package/dist/chunks/runBaseTests.BC7ZIH5L.js +0 -129
  84. package/dist/execute.d.ts +0 -148
  85. 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.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 };
package/dist/execute.d.ts DELETED
@@ -1,148 +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.DoNjFAiv.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.HJdfX-8k.js';
9
- import '@vitest/pretty-format';
10
- import '@vitest/snapshot';
11
- import '@vitest/utils/diff';
12
- import './chunks/environment.d.CUq4cUgQ.js';
13
-
14
- declare class FileMap {
15
- private fsCache;
16
- private fsBufferCache;
17
- readFileAsync(path: string): Promise<string>;
18
- readFile(path: string): string;
19
- readBuffer(path: string): Buffer;
20
- }
21
-
22
- // need to copy paste types for vm
23
- // because they require latest @types/node which we don't bundle
24
- interface ModuleEvaluateOptions {
25
- timeout?: vm.RunningScriptOptions["timeout"] | undefined;
26
- breakOnSigint?: vm.RunningScriptOptions["breakOnSigint"] | undefined;
27
- }
28
- type ModuleLinker = (specifier: string, referencingModule: VMModule, extra: {
29
- assert: object
30
- }) => VMModule | Promise<VMModule>;
31
- type ModuleStatus = "unlinked" | "linking" | "linked" | "evaluating" | "evaluated" | "errored";
32
- declare class VMModule {
33
- dependencySpecifiers: readonly string[];
34
- error: any;
35
- identifier: string;
36
- context: vm.Context;
37
- namespace: object;
38
- status: ModuleStatus;
39
- evaluate(options?: ModuleEvaluateOptions): Promise<void>;
40
- link(linker: ModuleLinker): Promise<void>;
41
- }
42
-
43
- interface ExternalModulesExecutorOptions {
44
- context: vm.Context;
45
- fileMap: FileMap;
46
- packageCache: Map<string, any>;
47
- transform: RuntimeRPC["transform"];
48
- interopDefault?: boolean;
49
- viteClientModule: Record<string, unknown>;
50
- }
51
- // TODO: improve Node.js strict mode support in #2854
52
- declare class ExternalModulesExecutor {
53
- #private;
54
- private options;
55
- private cjs;
56
- private esm;
57
- private vite;
58
- private context;
59
- private fs;
60
- private resolvers;
61
- constructor(options: ExternalModulesExecutorOptions);
62
- import(identifier: string): Promise<object>;
63
- require(identifier: string): any;
64
- createRequire(identifier: string): NodeJS.Require;
65
- // dynamic import can be used in both ESM and CJS, so we have it in the executor
66
- importModuleDynamically: (specifier: string, referencer: VMModule) => Promise<VMModule>;
67
- resolveModule: (specifier: string, referencer: string) => Promise<VMModule>;
68
- resolve(specifier: string, parent: string): string;
69
- private findNearestPackageData;
70
- private getModuleInformation;
71
- private createModule;
72
- private get isNetworkSupported();
73
- }
74
-
75
- interface MockContext {
76
- /**
77
- * When mocking with a factory, this refers to the module that imported the mock.
78
- */
79
- callstack: null | string[];
80
- }
81
- declare class VitestMocker {
82
- executor: VitestExecutor;
83
- static pendingIds: PendingSuiteMock[];
84
- private spyModule?;
85
- private primitives;
86
- private filterPublicKeys;
87
- private registries;
88
- private mockContext;
89
- constructor(executor: VitestExecutor);
90
- private get root();
91
- private get moduleCache();
92
- private get moduleDirectories();
93
- initializeSpyModule(): Promise<void>;
94
- private getMockerRegistry;
95
- reset(): void;
96
- private deleteCachedItem;
97
- private isModuleDirectory;
98
- getSuiteFilepath(): string;
99
- private createError;
100
- private resolvePath;
101
- resolveMocks(): Promise<void>;
102
- private callFunctionMock;
103
- // public method to avoid circular dependency
104
- getMockContext(): MockContext;
105
- // path used to store mocked dependencies
106
- getMockPath(dep: string): string;
107
- getDependencyMock(id: string): MockedModule | undefined;
108
- normalizePath(path: string): string;
109
- resolveMockPath(mockPath: string, external: string | null): string | null;
110
- mockObject(object: Record<string | symbol, any>, mockExports?: Record<string | symbol, any>, behavior?: MockedModuleType): Record<string | symbol, any>;
111
- unmockPath(path: string): void;
112
- mockPath(originalId: string, path: string, external: string | null, mockType: MockedModuleType | undefined, factory: MockFactory | undefined): void;
113
- importActual<T>(rawId: string, importer: string, callstack?: string[] | null): Promise<T>;
114
- importMock(rawId: string, importee: string): Promise<any>;
115
- requestWithMock(url: string, callstack: string[]): Promise<any>;
116
- queueMock(id: string, importer: string, factoryOrOptions?: MockFactory | MockOptions): void;
117
- queueUnmock(id: string, importer: string): void;
118
- }
119
-
120
- interface ExecuteOptions extends ViteNodeRunnerOptions {
121
- moduleDirectories?: string[];
122
- state: WorkerGlobalState;
123
- context?: vm.Context;
124
- externalModulesExecutor?: ExternalModulesExecutor;
125
- }
126
- declare class VitestExecutor extends ViteNodeRunner {
127
- options: ExecuteOptions;
128
- mocker: VitestMocker;
129
- externalModules?: ExternalModulesExecutor;
130
- private primitives;
131
- constructor(options: ExecuteOptions);
132
- protected getContextPrimitives(): {
133
- Object: typeof Object
134
- Reflect: typeof Reflect
135
- Symbol: typeof Symbol
136
- };
137
- get state(): WorkerGlobalState;
138
- get moduleExecutionInfo(): ModuleExecutionInfo | undefined;
139
- shouldResolveId(id: string, _importee?: string | undefined): boolean;
140
- originalResolveUrl(id: string, importer?: string): Promise<[url: string, fsPath: string]>;
141
- resolveUrl(id: string, importer?: string): Promise<[url: string, fsPath: string]>;
142
- protected runModule(context: Record<string, any>, transformed: string): Promise<void>;
143
- importExternalModule(path: string): Promise<any>;
144
- dependencyRequest(id: string, fsPath: string, callstack: string[]): Promise<any>;
145
- prepareContext(context: Record<string, any>): Record<string, any>;
146
- }
147
-
148
- 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';