vitest 4.0.0-beta.4 → 4.0.0-beta.6

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 (78) hide show
  1. package/LICENSE.md +1 -1
  2. package/dist/browser.d.ts +8 -9
  3. package/dist/browser.js +3 -2
  4. package/dist/chunks/base.BXI97p6t.js +39 -0
  5. package/dist/chunks/{benchmark.CYdenmiT.js → benchmark.UW6Ezvxy.js} +6 -8
  6. package/dist/chunks/{browser.d.BRP8scJf.d.ts → browser.d.Cawq_X_N.d.ts} +1 -1
  7. package/dist/chunks/{cac.CY0IAxC4.js → cac.WE-urWw5.js} +38 -115
  8. package/dist/chunks/{cli-api.B8xRY9Zt.js → cli-api.CZz3evYC.js} +931 -1439
  9. package/dist/chunks/{config.d.DZo8c7fw.d.ts → config.d.CKNVOKm0.d.ts} +3 -8
  10. package/dist/chunks/{console.DoJHFxmj.js → console.B0quX7yH.js} +32 -68
  11. package/dist/chunks/{constants.CXzqaLmq.js → constants.D_Q9UYh-.js} +1 -6
  12. package/dist/chunks/{coverage.C84l9G-M.js → coverage.BPRS6xgn.js} +395 -665
  13. package/dist/chunks/{coverage.DVF1vEu8.js → coverage.D_JHT54q.js} +2 -2
  14. package/dist/chunks/{coverage.d.CNYjU4GF.d.ts → coverage.d.BZtK59WP.d.ts} +7 -5
  15. package/dist/chunks/{creator.yfA2ExGt.js → creator.KEg6n5IC.js} +29 -75
  16. package/dist/chunks/{date.Bq6ZW5rf.js → date.-jtEtIeV.js} +6 -17
  17. package/dist/chunks/{environment.d.Bhm9oc0v.d.ts → environment.d.2fYMoz3o.d.ts} +26 -4
  18. package/dist/chunks/{git.BVQ8w_Sw.js → git.BFNcloKD.js} +1 -2
  19. package/dist/chunks/{global.d.DAhT2emn.d.ts → global.d.K6uBQHzY.d.ts} +1 -1
  20. package/dist/chunks/{globals.Dgo-vS5G.js → globals.lgsmH00r.js} +7 -6
  21. package/dist/chunks/{index.D3SKT3tv.js → index.7w0eqmYM.js} +14 -24
  22. package/dist/chunks/{index.D1_MsKEt.js → index.AR8aAkCC.js} +4 -2
  23. package/dist/chunks/{index.CmSc2RE5.js → index.BG0gqZH-.js} +43 -106
  24. package/dist/chunks/{index.CtUvr1c8.js → index.CsFXYRkW.js} +27 -46
  25. package/dist/chunks/{index.Bz6b0Ib7.js → index.VNI-1z5c.js} +276 -604
  26. package/dist/chunks/{inspector.C914Efll.js → inspector.CvQD-Nie.js} +10 -25
  27. package/dist/chunks/moduleRunner.d.8kKUsuDg.d.ts +202 -0
  28. package/dist/chunks/moduleTransport.I-bgQy0S.js +19 -0
  29. package/dist/chunks/{node.fjCdwEIl.js → node.BOqcT2jW.js} +1 -1
  30. package/dist/chunks/{plugin.d.CLhMcYdD.d.ts → plugin.d.DuiQJfUL.d.ts} +1 -1
  31. package/dist/chunks/{reporters.d.DWg40D2B.d.ts → reporters.d.CqR9-CDJ.d.ts} +52 -101
  32. package/dist/chunks/resolver.Bx6lE0iq.js +119 -0
  33. package/dist/chunks/{rpc.jnQO9F8a.js → rpc.RpPylpp0.js} +7 -21
  34. package/dist/chunks/runBaseTests.D6sfuWBM.js +99 -0
  35. package/dist/chunks/{setup-common.Ebx5x0eP.js → setup-common.hLGRxhC8.js} +15 -27
  36. package/dist/chunks/startModuleRunner.C8TW8zTN.js +655 -0
  37. package/dist/chunks/{typechecker.CMNPqJOo.js → typechecker.Cd1wvxUM.js} +97 -209
  38. package/dist/chunks/{utils.CcGm2cd1.js → utils.C2YI6McM.js} +4 -13
  39. package/dist/chunks/{utils.XdZDrNZV.js → utils.C7__0Iv5.js} +7 -17
  40. package/dist/chunks/{vi.CA0EPI9Y.js → vi.BfdOiD4j.js} +116 -269
  41. package/dist/chunks/{vm.BUnLJt_P.js → vm.BHBje7cC.js} +101 -225
  42. package/dist/chunks/{worker.d.zjyR34Pb.d.ts → worker.d.D9QWnzAe.d.ts} +16 -13
  43. package/dist/chunks/{worker.d.C-1AbnVe.d.ts → worker.d.Db-UVmXc.d.ts} +1 -1
  44. package/dist/cli.js +4 -4
  45. package/dist/config.cjs +3 -9
  46. package/dist/config.d.ts +10 -12
  47. package/dist/config.js +1 -1
  48. package/dist/coverage.d.ts +10 -11
  49. package/dist/coverage.js +5 -6
  50. package/dist/environments.d.ts +2 -2
  51. package/dist/environments.js +1 -1
  52. package/dist/index.d.ts +10 -9
  53. package/dist/index.js +6 -5
  54. package/dist/module-evaluator.d.ts +12 -0
  55. package/dist/module-evaluator.js +276 -0
  56. package/dist/module-runner.js +15 -0
  57. package/dist/node.d.ts +12 -13
  58. package/dist/node.js +19 -24
  59. package/dist/reporters.d.ts +7 -8
  60. package/dist/reporters.js +3 -3
  61. package/dist/runners.d.ts +3 -3
  62. package/dist/runners.js +35 -57
  63. package/dist/snapshot.js +2 -2
  64. package/dist/suite.js +2 -2
  65. package/dist/worker.js +82 -45
  66. package/dist/workers/forks.js +11 -10
  67. package/dist/workers/runVmTests.js +27 -46
  68. package/dist/workers/threads.js +11 -10
  69. package/dist/workers/vmForks.js +11 -10
  70. package/dist/workers/vmThreads.js +11 -10
  71. package/dist/workers.d.ts +5 -4
  72. package/dist/workers.js +17 -16
  73. package/package.json +22 -17
  74. package/dist/chunks/base.BaCDDRPG.js +0 -38
  75. package/dist/chunks/execute.Dt-pCVcL.js +0 -708
  76. package/dist/chunks/runBaseTests.DBVVLMSb.js +0 -129
  77. package/dist/execute.d.ts +0 -148
  78. package/dist/execute.js +0 -13
@@ -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.CtUvr1c8.js';
4
- import { c as setupCommonEnv, s as startCoverageInsideWorker, a as stopCoverageInsideWorker } from './setup-common.Ebx5x0eP.js';
5
- import { a as globalExpect, v as vi } from './vi.CA0EPI9Y.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.D1_MsKEt.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.jnQO9F8a.js';
21
- import './index.Bgo3tNWt.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.DoJHFxmj.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.zjyR34Pb.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.DZo8c7fw.js';
9
- import '@vitest/pretty-format';
10
- import '@vitest/snapshot';
11
- import '@vitest/utils/diff';
12
- import './chunks/environment.d.Bhm9oc0v.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.Dt-pCVcL.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';