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,6 +1,7 @@
1
1
  import { CancelReason, File, TestAnnotation, TaskResultPack, TaskEventPack, FileSpecification, Task } from '@vitest/runner';
2
- import { a as SerializedConfig } from './config.d.DZo8c7fw.js';
3
- import { T as TransformMode, U as UserConsoleLog, A as AfterSuiteRunMeta, E as Environment } from './environment.d.Bhm9oc0v.js';
2
+ import { FetchFunctionOptions, FetchResult, EvaluatedModules } from 'vite/module-runner';
3
+ import { a as SerializedConfig } from './config.d.CKNVOKm0.js';
4
+ import { F as FetchCachedFileSystemResult, R as ResolveFunctionResult, U as UserConsoleLog, A as AfterSuiteRunMeta, E as Environment } from './environment.d.2fYMoz3o.js';
4
5
  import { SnapshotResult } from '@vitest/snapshot';
5
6
 
6
7
  type ArgumentsType<T> = T extends (...args: infer A) => any ? A : never;
@@ -104,17 +105,11 @@ interface PromiseEntry {
104
105
  declare const setTimeout: typeof globalThis.setTimeout;
105
106
 
106
107
  interface RuntimeRPC {
107
- fetch: (id: string, transformMode: TransformMode) => Promise<{
108
- externalize?: string;
109
- id?: string;
110
- }>;
111
- transform: (id: string, transformMode: TransformMode) => Promise<{
108
+ fetch: (id: string, importer: string | undefined, environment: string, options?: FetchFunctionOptions) => Promise<FetchResult | FetchCachedFileSystemResult>;
109
+ resolve: (id: string, importer: string | undefined, environment: string) => Promise<ResolveFunctionResult | null>;
110
+ transform: (id: string) => Promise<{
112
111
  code?: string;
113
112
  }>;
114
- resolveId: (id: string, importer: string | undefined, transformMode: TransformMode) => Promise<{
115
- external?: boolean | "absolute" | "relative";
116
- id: string;
117
- } | null>;
118
113
  onUserConsoleLog: (log: UserConsoleLog) => void;
119
114
  onUnhandledError: (err: unknown, type: string) => void;
120
115
  onQueued: (file: File) => void;
@@ -134,7 +129,6 @@ interface RunnerRPC {
134
129
  type WorkerRPC = BirpcReturn<RuntimeRPC, RunnerRPC>;
135
130
  interface ContextTestEnvironment {
136
131
  name: string;
137
- transformMode?: TransformMode;
138
132
  options: Record<string, any> | null;
139
133
  }
140
134
  type TestExecutionMethod = "run" | "collect";
@@ -155,10 +149,19 @@ interface WorkerGlobalState {
155
149
  rpc: WorkerRPC;
156
150
  current?: Task;
157
151
  filepath?: string;
152
+ metaEnv: {
153
+ [key: string]: any;
154
+ BASE_URL: string;
155
+ MODE: string;
156
+ DEV: boolean;
157
+ PROD: boolean;
158
+ SSR: boolean;
159
+ };
158
160
  environment: Environment;
159
161
  environmentTeardownRun?: boolean;
160
162
  onCancel: Promise<CancelReason>;
161
- moduleCache: Map<string, any>;
163
+ evaluatedModules: EvaluatedModules;
164
+ resolvingModules: Set<string>;
162
165
  moduleExecutionInfo: Map<string, any>;
163
166
  onCleanup: (listener: () => unknown) => void;
164
167
  providedContext: Record<string, any>;
@@ -1,5 +1,5 @@
1
1
  import { MessagePort } from 'node:worker_threads';
2
- import { C as ContextRPC } from './worker.d.zjyR34Pb.js';
2
+ import { C as ContextRPC } from './worker.d.D9QWnzAe.js';
3
3
 
4
4
  interface WorkerContext extends ContextRPC {
5
5
  port: MessagePort;
package/dist/cli.js CHANGED
@@ -1,13 +1,13 @@
1
- import { c as createCLI } from './chunks/cac.CY0IAxC4.js';
1
+ import { c as createCLI } from './chunks/cac.WE-urWw5.js';
2
2
  import '@vitest/utils';
3
3
  import 'events';
4
4
  import 'pathe';
5
5
  import 'tinyrainbow';
6
- import './chunks/constants.CXzqaLmq.js';
7
- import './chunks/index.Bz6b0Ib7.js';
6
+ import './chunks/constants.D_Q9UYh-.js';
7
+ import './chunks/index.VNI-1z5c.js';
8
8
  import 'node:fs';
9
9
  import 'node:fs/promises';
10
- import './chunks/typechecker.CMNPqJOo.js';
10
+ import './chunks/typechecker.Cd1wvxUM.js';
11
11
  import 'node:os';
12
12
  import 'node:perf_hooks';
13
13
  import '@vitest/utils/source-map';
package/dist/config.cjs CHANGED
@@ -4,19 +4,14 @@ var os = require('node:os');
4
4
  var stdEnv = require('std-env');
5
5
  var vite = require('vite');
6
6
 
7
- // if changed, update also jsdocs and docs
8
- const defaultBrowserPort = 63315;
9
- const extraInlineDeps = [
10
- /^(?!.*node_modules).*\.mjs$/,
11
- /^(?!.*node_modules).*\.cjs\.js$/,
12
- /vite\w*\/dist\/client\/env.mjs/
13
- ];
14
-
15
7
  const isNode = typeof process < "u" && typeof process.stdout < "u" && !process.versions?.deno && !globalThis.window;
16
8
  const isDeno = typeof process < "u" && typeof process.stdout < "u" && process.versions?.deno !== void 0;
17
9
  (isNode || isDeno) && process.platform === "win32";
18
10
  (isNode || isDeno) && process.stdout?.isTTY && !stdEnv.isCI;
19
11
 
12
+ // if changed, update also jsdocs and docs
13
+ const defaultBrowserPort = 63315;
14
+
20
15
  const defaultInclude = ["**/*.{test,spec}.?(c|m)[jt]s?(x)"];
21
16
  const defaultExclude = ["**/node_modules/**", "**/.git/**"];
22
17
  // These are the generic defaults for coverage. Providers may also set some provider specific defaults.
@@ -98,4 +93,3 @@ exports.defaultExclude = defaultExclude;
98
93
  exports.defaultInclude = defaultInclude;
99
94
  exports.defineConfig = defineConfig;
100
95
  exports.defineProject = defineProject;
101
- exports.extraInlineDeps = extraInlineDeps;
package/dist/config.d.ts CHANGED
@@ -1,29 +1,28 @@
1
1
  import { HookHandler, ConfigEnv, UserConfig } from 'vite';
2
2
  export { ConfigEnv, Plugin, UserConfig as ViteUserConfig, mergeConfig } from 'vite';
3
- import { I as InlineConfig, c as CoverageV8Options, R as ResolvedCoverageOptions, U as UserWorkspaceConfig, d as UserProjectConfigFn, e as UserProjectConfigExport } from './chunks/reporters.d.DWg40D2B.js';
4
- export { a as TestProjectConfiguration, g as TestProjectInlineConfiguration, f as TestUserConfig, W as WatcherTriggerPattern } from './chunks/reporters.d.DWg40D2B.js';
5
- import { V as VitestPluginContext } from './chunks/plugin.d.CLhMcYdD.js';
6
- import { F as FakeTimerInstallOpts } from './chunks/config.d.DZo8c7fw.js';
3
+ import { I as InlineConfig, c as CoverageV8Options, R as ResolvedCoverageOptions, U as UserWorkspaceConfig, d as UserProjectConfigFn, e as UserProjectConfigExport } from './chunks/reporters.d.CqR9-CDJ.js';
4
+ export { a as TestProjectConfiguration, g as TestProjectInlineConfiguration, f as TestUserConfig, W as WatcherTriggerPattern } from './chunks/reporters.d.CqR9-CDJ.js';
5
+ import { V as VitestPluginContext } from './chunks/plugin.d.DuiQJfUL.js';
6
+ import { F as FakeTimerInstallOpts } from './chunks/config.d.CKNVOKm0.js';
7
7
  import '@vitest/runner';
8
- import './chunks/environment.d.Bhm9oc0v.js';
9
8
  import '@vitest/utils';
9
+ import './chunks/environment.d.2fYMoz3o.js';
10
10
  import 'node:stream';
11
11
  import 'node:console';
12
- import './chunks/browser.d.BRP8scJf.js';
13
- import './chunks/worker.d.zjyR34Pb.js';
12
+ import './chunks/browser.d.Cawq_X_N.js';
13
+ import './chunks/worker.d.D9QWnzAe.js';
14
+ import 'vite/module-runner';
14
15
  import '@vitest/snapshot';
15
16
  import '@vitest/mocker';
16
17
  import '@vitest/utils/source-map';
17
18
  import '@vitest/pretty-format';
18
19
  import '@vitest/utils/diff';
19
- import 'vite-node';
20
20
  import 'chai';
21
21
  import 'vitest/optional-types.js';
22
22
  import './chunks/benchmark.d.DAaHLpsq.js';
23
23
  import '@vitest/runner/utils';
24
24
  import 'tinybench';
25
- import './chunks/coverage.d.CNYjU4GF.js';
26
- import 'vite-node/client';
25
+ import './chunks/coverage.d.BZtK59WP.js';
27
26
  import '@vitest/snapshot/manager';
28
27
  import 'node:fs';
29
28
 
@@ -43,7 +42,6 @@ declare module "vite" {
43
42
  }
44
43
 
45
44
  declare const defaultBrowserPort = 63315;
46
- declare const extraInlineDeps: RegExp[];
47
45
 
48
46
  declare const defaultInclude: string[];
49
47
  declare const defaultExclude: string[];
@@ -102,5 +100,5 @@ declare function defineProject(config: Promise<UserWorkspaceConfig>): Promise<Us
102
100
  declare function defineProject(config: UserProjectConfigFn): UserProjectConfigFn;
103
101
  declare function defineProject(config: UserProjectConfigExport): UserProjectConfigExport;
104
102
 
105
- export { UserProjectConfigExport, UserProjectConfigFn, UserWorkspaceConfig, configDefaults, coverageConfigDefaults, defaultBrowserPort, defaultExclude, defaultInclude, defineConfig, defineProject, extraInlineDeps };
103
+ export { UserProjectConfigExport, UserProjectConfigFn, UserWorkspaceConfig, configDefaults, coverageConfigDefaults, defaultBrowserPort, defaultExclude, defaultInclude, defineConfig, defineProject };
106
104
  export type { ViteUserConfigExport, ViteUserConfigFn, ViteUserConfigFnObject, ViteUserConfigFnPromise };
package/dist/config.js CHANGED
@@ -1,6 +1,6 @@
1
- export { d as defaultBrowserPort, e as extraInlineDeps } from './chunks/constants.CXzqaLmq.js';
2
1
  export { c as configDefaults, a as coverageConfigDefaults, d as defaultExclude, b as defaultInclude } from './chunks/defaults.CXFFjsi8.js';
3
2
  export { mergeConfig } from 'vite';
3
+ export { d as defaultBrowserPort } from './chunks/constants.D_Q9UYh-.js';
4
4
  import 'node:os';
5
5
  import './chunks/env.D4Lgay0q.js';
6
6
  import 'std-env';
@@ -1,26 +1,25 @@
1
- import { R as ResolvedCoverageOptions, V as Vitest, C as CoverageMap, b as ReportContext } from './chunks/reporters.d.DWg40D2B.js';
1
+ import { R as ResolvedCoverageOptions, V as Vitest, C as CoverageMap, b as ReportContext } from './chunks/reporters.d.CqR9-CDJ.js';
2
2
  import { TransformResult } from 'vite';
3
- import { A as AfterSuiteRunMeta } from './chunks/environment.d.Bhm9oc0v.js';
3
+ import { A as AfterSuiteRunMeta } from './chunks/environment.d.2fYMoz3o.js';
4
4
  import '@vitest/runner';
5
5
  import '@vitest/utils';
6
6
  import 'node:stream';
7
7
  import 'node:console';
8
- import './chunks/browser.d.BRP8scJf.js';
9
- import './chunks/worker.d.zjyR34Pb.js';
10
- import './chunks/config.d.DZo8c7fw.js';
8
+ import './chunks/browser.d.Cawq_X_N.js';
9
+ import './chunks/worker.d.D9QWnzAe.js';
10
+ import 'vite/module-runner';
11
+ import './chunks/config.d.CKNVOKm0.js';
11
12
  import '@vitest/pretty-format';
12
13
  import '@vitest/snapshot';
13
14
  import '@vitest/utils/diff';
14
15
  import '@vitest/mocker';
15
16
  import '@vitest/utils/source-map';
16
- import 'vite-node';
17
17
  import 'chai';
18
18
  import 'vitest/optional-types.js';
19
19
  import './chunks/benchmark.d.DAaHLpsq.js';
20
20
  import '@vitest/runner/utils';
21
21
  import 'tinybench';
22
- import './chunks/coverage.d.CNYjU4GF.js';
23
- import 'vite-node/client';
22
+ import './chunks/coverage.d.BZtK59WP.js';
24
23
  import '@vitest/snapshot/manager';
25
24
  import 'node:fs';
26
25
 
@@ -46,7 +45,7 @@ interface ResolvedThreshold {
46
45
  * "project-b": ...
47
46
  * ```
48
47
  */
49
- type CoverageFiles = Map<NonNullable<AfterSuiteRunMeta["projectName"]> | symbol, Record<AfterSuiteRunMeta["transformMode"], {
48
+ type CoverageFiles = Map<NonNullable<AfterSuiteRunMeta["projectName"]> | symbol, Record<AfterSuiteRunMeta["environment"], {
50
49
  [TestFilenames: string]: string;
51
50
  }>>;
52
51
  declare class BaseCoverageProvider<Options extends ResolvedCoverageOptions<"istanbul" | "v8">> {
@@ -75,12 +74,12 @@ declare class BaseCoverageProvider<Options extends ResolvedCoverageOptions<"ista
75
74
  }>;
76
75
  resolveOptions(): Options;
77
76
  clean(clean?: boolean): Promise<void>;
78
- onAfterSuiteRun({ coverage, transformMode, projectName, testFiles }: AfterSuiteRunMeta): void;
77
+ onAfterSuiteRun({ coverage, environment, projectName, testFiles }: AfterSuiteRunMeta): void;
79
78
  readCoverageFiles<CoverageType>({ onFileRead, onFinished, onDebug }: {
80
79
  /** Callback invoked with a single coverage result */
81
80
  onFileRead: (data: CoverageType) => void;
82
81
  /** Callback invoked once all results of a project for specific transform mode are read */
83
- onFinished: (project: Vitest["projects"][number], transformMode: AfterSuiteRunMeta["transformMode"]) => Promise<void>;
82
+ onFinished: (project: Vitest["projects"][number], environment: string) => Promise<void>;
84
83
  onDebug: ((...logs: any[]) => void) & {
85
84
  enabled: boolean;
86
85
  };
package/dist/coverage.js CHANGED
@@ -1,17 +1,16 @@
1
- export { B as BaseCoverageProvider } from './chunks/coverage.C84l9G-M.js';
1
+ export { B as BaseCoverageProvider } from './chunks/coverage.BPRS6xgn.js';
2
2
  import 'node:fs';
3
3
  import 'node:path';
4
+ import '@vitest/utils';
4
5
  import 'pathe';
5
6
  import 'picomatch';
6
7
  import 'tinyglobby';
7
8
  import 'tinyrainbow';
8
- import 'vite-node/utils';
9
9
  import './chunks/defaults.CXFFjsi8.js';
10
10
  import 'node:os';
11
11
  import './chunks/env.D4Lgay0q.js';
12
12
  import 'std-env';
13
13
  import 'node:crypto';
14
- import '@vitest/utils';
15
14
  import 'node:module';
16
15
  import 'node:process';
17
16
  import 'node:fs/promises';
@@ -20,16 +19,16 @@ import 'node:assert';
20
19
  import 'node:v8';
21
20
  import 'node:util';
22
21
  import 'vite';
23
- import './chunks/constants.CXzqaLmq.js';
22
+ import './chunks/constants.D_Q9UYh-.js';
24
23
  import 'node:tty';
25
24
  import 'node:events';
26
25
  import './chunks/index.Bgo3tNWt.js';
27
26
  import 'tinypool';
28
- import './chunks/typechecker.CMNPqJOo.js';
27
+ import './chunks/typechecker.Cd1wvxUM.js';
29
28
  import 'node:perf_hooks';
30
29
  import '@vitest/utils/source-map';
31
30
  import 'tinyexec';
32
31
  import './path.js';
33
32
  import '@vitest/runner/utils';
34
33
  import 'node:worker_threads';
35
- import './chunks/coverage.DVF1vEu8.js';
34
+ import './chunks/coverage.D_JHT54q.js';
@@ -1,5 +1,5 @@
1
- import { E as Environment } from './chunks/environment.d.Bhm9oc0v.js';
2
- export { a as EnvironmentReturn, V as VmEnvironmentReturn } from './chunks/environment.d.Bhm9oc0v.js';
1
+ import { E as Environment } from './chunks/environment.d.2fYMoz3o.js';
2
+ export { a as EnvironmentReturn, V as VmEnvironmentReturn } from './chunks/environment.d.2fYMoz3o.js';
3
3
 
4
4
  declare const environments: {
5
5
  "node": Environment;
@@ -1,2 +1,2 @@
1
- export { e as builtinEnvironments, p as populateGlobal } from './chunks/index.CmSc2RE5.js';
1
+ export { e as builtinEnvironments, p as populateGlobal } from './chunks/index.BG0gqZH-.js';
2
2
  import 'node:console';
package/dist/index.d.ts CHANGED
@@ -1,14 +1,14 @@
1
- import { S as SerializedTestSpecification } from './chunks/browser.d.BRP8scJf.js';
2
- export { B as BrowserTesterOptions } from './chunks/browser.d.BRP8scJf.js';
3
- import './chunks/global.d.DAhT2emn.js';
1
+ import { S as SerializedTestSpecification } from './chunks/browser.d.Cawq_X_N.js';
2
+ export { B as BrowserTesterOptions } from './chunks/browser.d.Cawq_X_N.js';
3
+ import './chunks/global.d.K6uBQHzY.js';
4
4
  import { File, TestAnnotation, TaskResultPack, TaskEventPack, TaskPopulated } from '@vitest/runner';
5
5
  export { CancelReason, HookCleanupCallback, HookListener, ImportDuration, OnTestFailedHandler, OnTestFinishedHandler, RunMode, Task as RunnerTask, TaskBase as RunnerTaskBase, TaskEventPack as RunnerTaskEventPack, TaskResult as RunnerTaskResult, TaskResultPack as RunnerTaskResultPack, Test as RunnerTestCase, File as RunnerTestFile, Suite as RunnerTestSuite, SuiteAPI, SuiteCollector, SuiteFactory, TaskCustomOptions, TaskMeta, TaskState, TestAPI, TestAnnotation, TestContext, TestFunction, TestOptions, afterAll, afterEach, beforeAll, beforeEach, describe, it, onTestFailed, onTestFinished, suite, test } from '@vitest/runner';
6
- import { a as BirpcReturn } from './chunks/worker.d.zjyR34Pb.js';
7
- export { C as ContextRPC, c as ContextTestEnvironment, b as RunnerRPC, R as RuntimeRPC, T as TestExecutionMethod, W as WorkerGlobalState } from './chunks/worker.d.zjyR34Pb.js';
8
- import { a as SerializedConfig, F as FakeTimerInstallOpts, R as RuntimeOptions } from './chunks/config.d.DZo8c7fw.js';
9
- export { b as RuntimeConfig, S as SerializedCoverageConfig } from './chunks/config.d.DZo8c7fw.js';
10
- import { b as Awaitable, U as UserConsoleLog, L as LabelColor, M as ModuleGraphData, P as ProvidedContext } from './chunks/environment.d.Bhm9oc0v.js';
11
- export { A as AfterSuiteRunMeta } from './chunks/environment.d.Bhm9oc0v.js';
6
+ import { a as BirpcReturn } from './chunks/worker.d.D9QWnzAe.js';
7
+ export { C as ContextRPC, c as ContextTestEnvironment, b as RunnerRPC, R as RuntimeRPC, T as TestExecutionMethod, W as WorkerGlobalState } from './chunks/worker.d.D9QWnzAe.js';
8
+ import { a as SerializedConfig, F as FakeTimerInstallOpts, R as RuntimeOptions } from './chunks/config.d.CKNVOKm0.js';
9
+ export { b as RuntimeConfig, S as SerializedCoverageConfig } from './chunks/config.d.CKNVOKm0.js';
10
+ import { b as Awaitable, U as UserConsoleLog, L as LabelColor, M as ModuleGraphData, P as ProvidedContext } from './chunks/environment.d.2fYMoz3o.js';
11
+ export { A as AfterSuiteRunMeta } from './chunks/environment.d.2fYMoz3o.js';
12
12
  import { ExpectStatic } from '@vitest/expect';
13
13
  export { Assertion, AsymmetricMatchersContaining, DeeplyAllowMatchers, ExpectPollOptions, ExpectStatic, JestAssertion, Matchers } from '@vitest/expect';
14
14
  import { spyOn, fn, MaybeMockedDeep, MaybeMocked, MaybePartiallyMocked, MaybePartiallyMockedDeep, MockInstance } from '@vitest/spy';
@@ -20,6 +20,7 @@ export { ExpectTypeOf, expectTypeOf } from 'expect-type';
20
20
  export { SnapshotData, SnapshotMatchOptions, SnapshotResult, SnapshotSerializer, SnapshotStateOptions, SnapshotSummary, SnapshotUpdateState, UncheckedSnapshot } from '@vitest/snapshot';
21
21
  export { ParsedStack, SerializedError, TestError } from '@vitest/utils';
22
22
  export { DiffOptions } from '@vitest/utils/diff';
23
+ export { EvaluatedModules } from 'vite/module-runner';
23
24
  import * as chai from 'chai';
24
25
  export { chai };
25
26
  export { assert, should } from 'chai';
package/dist/index.js CHANGED
@@ -1,18 +1,19 @@
1
- export { c as createExpect, a as expect, i as inject, v as vi, b as vitest } from './chunks/vi.CA0EPI9Y.js';
2
- export { b as bench } from './chunks/benchmark.CYdenmiT.js';
3
- export { a as assertType } from './chunks/index.D1_MsKEt.js';
1
+ export { c as createExpect, a as expect, i as inject, v as vi, b as vitest } from './chunks/vi.BfdOiD4j.js';
2
+ export { b as bench } from './chunks/benchmark.UW6Ezvxy.js';
3
+ export { a as assertType } from './chunks/index.AR8aAkCC.js';
4
4
  export { expectTypeOf } from 'expect-type';
5
5
  export { afterAll, afterEach, beforeAll, beforeEach, describe, it, onTestFailed, onTestFinished, suite, test } from '@vitest/runner';
6
+ export { EvaluatedModules } from 'vite/module-runner';
6
7
  import * as chai from 'chai';
7
8
  export { chai };
8
9
  export { assert, should } from 'chai';
9
10
  import '@vitest/expect';
10
11
  import '@vitest/runner/utils';
11
- import './chunks/utils.XdZDrNZV.js';
12
+ import './chunks/utils.C7__0Iv5.js';
12
13
  import '@vitest/utils';
13
14
  import './chunks/_commonjsHelpers.BFTU3MAI.js';
14
15
  import '@vitest/snapshot';
15
16
  import '@vitest/utils/error';
16
17
  import '@vitest/spy';
17
18
  import '@vitest/utils/source-map';
18
- import './chunks/date.Bq6ZW5rf.js';
19
+ import './chunks/date.-jtEtIeV.js';
@@ -0,0 +1,12 @@
1
+ import 'vite/module-runner';
2
+ export { b as VitestModuleEvaluator, a as VitestModuleEvaluatorOptions, c as createImportMetaEnvProxy, g as getDefaultRequestStubs, i as isPrimitive, u as unwrapId, w as wrapId } from './chunks/moduleRunner.d.8kKUsuDg.js';
3
+ import 'node:vm';
4
+ import './chunks/worker.d.D9QWnzAe.js';
5
+ import '@vitest/runner';
6
+ import './chunks/config.d.CKNVOKm0.js';
7
+ import '@vitest/pretty-format';
8
+ import '@vitest/snapshot';
9
+ import '@vitest/utils/diff';
10
+ import './chunks/environment.d.2fYMoz3o.js';
11
+ import '@vitest/mocker';
12
+ import './chunks/mocker.d.BE_2ls6u.js';
@@ -0,0 +1,276 @@
1
+ import { isBuiltin, createRequire } from 'node:module';
2
+ import { pathToFileURL } from 'node:url';
3
+ import vm from 'node:vm';
4
+ import { isAbsolute } from 'pathe';
5
+ import { ssrModuleExportsKey, ssrImportMetaKey, ssrImportKey, ssrDynamicImportKey, ssrExportAllKey } from 'vite/module-runner';
6
+
7
+ const performanceNow = performance.now.bind(performance);
8
+ class ModuleDebug {
9
+ executionStack = [];
10
+ startCalculateModuleExecutionInfo(filename, startOffset) {
11
+ const startTime = performanceNow();
12
+ return this.executionStack.push({
13
+ filename,
14
+ startTime,
15
+ subImportTime: 0
16
+ }), () => {
17
+ const duration = performanceNow() - startTime, currentExecution = this.executionStack.pop();
18
+ if (currentExecution == null) throw new Error("Execution stack is empty, this should never happen");
19
+ const selfTime = duration - currentExecution.subImportTime;
20
+ if (this.executionStack.length > 0) this.executionStack.at(-1).subImportTime += duration;
21
+ return {
22
+ startOffset,
23
+ duration,
24
+ selfTime
25
+ };
26
+ };
27
+ }
28
+ }
29
+
30
+ const isWindows = process.platform === "win32";
31
+ class VitestModuleEvaluator {
32
+ stubs = {};
33
+ env = createImportMetaEnvProxy();
34
+ vm;
35
+ compiledFunctionArgumentsNames;
36
+ compiledFunctionArgumentsValues = [];
37
+ primitives;
38
+ debug = new ModuleDebug();
39
+ constructor(vmOptions, options = {}) {
40
+ if (this.options = options, this.vm = vmOptions, this.stubs = getDefaultRequestStubs(vmOptions?.context), options.compiledFunctionArgumentsNames) this.compiledFunctionArgumentsNames = options.compiledFunctionArgumentsNames;
41
+ if (options.compiledFunctionArgumentsValues) this.compiledFunctionArgumentsValues = options.compiledFunctionArgumentsValues;
42
+ if (vmOptions) this.primitives = vm.runInContext("({ Object, Proxy, Reflect })", vmOptions.context);
43
+ else this.primitives = {
44
+ Object,
45
+ Proxy,
46
+ Reflect
47
+ };
48
+ }
49
+ convertIdToImportUrl(id) {
50
+ // TODO: vitest returns paths for external modules, but Vite returns file://
51
+ // unfortunetly, there is a bug in Vite where ID is resolved incorrectly, so we can't return files until the fix is merged
52
+ // https://github.com/vitejs/vite/pull/20449
53
+ if (!isWindows || isBuiltin(id) || /^(?:node:|data:|http:|https:|file:)/.test(id)) return id;
54
+ const [filepath, query] = id.split("?");
55
+ return query ? `${pathToFileURL(filepath).toString()}?${query}` : pathToFileURL(filepath).toString();
56
+ }
57
+ async runExternalModule(id) {
58
+ if (id in this.stubs) return this.stubs[id];
59
+ const file = this.convertIdToImportUrl(id), namespace = this.vm ? await this.vm.externalModulesExecutor.import(file) : await import(file);
60
+ if (!this.shouldInterop(file, namespace)) return namespace;
61
+ const { mod, defaultExport } = interopModule(namespace), { Proxy, Reflect } = this.primitives, proxy = new Proxy(mod, {
62
+ get(mod, prop) {
63
+ return prop === "default" ? defaultExport : mod[prop] ?? defaultExport?.[prop];
64
+ },
65
+ has(mod, prop) {
66
+ return prop === "default" ? defaultExport !== void 0 : prop in mod || defaultExport && prop in defaultExport;
67
+ },
68
+ getOwnPropertyDescriptor(mod, prop) {
69
+ const descriptor = Reflect.getOwnPropertyDescriptor(mod, prop);
70
+ if (descriptor) return descriptor;
71
+ if (prop === "default" && defaultExport !== void 0) return {
72
+ value: defaultExport,
73
+ enumerable: true,
74
+ configurable: true
75
+ };
76
+ }
77
+ });
78
+ return proxy;
79
+ }
80
+ async runInlinedModule(context, code, module) {
81
+ context.__vite_ssr_import_meta__.env = this.env;
82
+ const { Reflect, Proxy, Object } = this.primitives, exportsObject = context[ssrModuleExportsKey], SYMBOL_NOT_DEFINED = Symbol("not defined");
83
+ let moduleExports = SYMBOL_NOT_DEFINED;
84
+ // this proxy is triggered only on exports.{name} and module.exports access
85
+ // inside the module itself. imported module is always "exports"
86
+ const cjsExports = new Proxy(exportsObject, {
87
+ get: (target, p, receiver) => {
88
+ return Reflect.has(target, p) ? Reflect.get(target, p, receiver) : Reflect.get(Object.prototype, p, receiver);
89
+ },
90
+ getPrototypeOf: () => Object.prototype,
91
+ set: (_, p, value) => {
92
+ // treat "module.exports =" the same as "exports.default =" to not have nested "default.default",
93
+ // so "exports.default" becomes the actual module
94
+ if (p === "default" && this.shouldInterop(module.file, { default: value }) && cjsExports !== value) return exportAll(cjsExports, value), exportsObject.default = value, true;
95
+ if (!Reflect.has(exportsObject, "default")) exportsObject.default = {};
96
+ // returns undefined, when accessing named exports, if default is not an object
97
+ // but is still present inside hasOwnKeys, this is Node behaviour for CJS
98
+ if (moduleExports !== SYMBOL_NOT_DEFINED && isPrimitive(moduleExports)) return defineExport(exportsObject, p, () => void 0), true;
99
+ if (!isPrimitive(exportsObject.default)) exportsObject.default[p] = value;
100
+ if (p !== "default") defineExport(exportsObject, p, () => value);
101
+ return true;
102
+ }
103
+ }), moduleProxy = {
104
+ set exports(value) {
105
+ exportAll(cjsExports, value), exportsObject.default = value, moduleExports = value;
106
+ },
107
+ get exports() {
108
+ return cjsExports;
109
+ }
110
+ }, meta = context[ssrImportMetaKey], testFilepath = this.options.getCurrentTestFilepath?.();
111
+ if (testFilepath === module.file) {
112
+ const globalNamespace = this.vm?.context || globalThis;
113
+ Object.defineProperty(meta, "vitest", { get: () => globalNamespace.__vitest_index__ });
114
+ }
115
+ const filename = meta.filename, dirname = meta.dirname, require = this.createRequire(filename), argumentsList = [
116
+ ssrModuleExportsKey,
117
+ ssrImportMetaKey,
118
+ ssrImportKey,
119
+ ssrDynamicImportKey,
120
+ ssrExportAllKey,
121
+ "__vite_ssr_exportName__",
122
+ "__filename",
123
+ "__dirname",
124
+ "module",
125
+ "exports",
126
+ "require"
127
+ ];
128
+ if (this.compiledFunctionArgumentsNames) argumentsList.push(...this.compiledFunctionArgumentsNames);
129
+ // add 'use strict' since ESM enables it by default
130
+ const codeDefinition = `'use strict';async (${argumentsList.join(",")})=>{{`, wrappedCode = `${codeDefinition}${code}\n}}`, options = {
131
+ filename: module.file || filename,
132
+ lineOffset: 0,
133
+ columnOffset: -codeDefinition.length
134
+ }, finishModuleExecutionInfo = this.debug.startCalculateModuleExecutionInfo(filename, codeDefinition.length);
135
+ try {
136
+ const initModule = this.vm ? vm.runInContext(wrappedCode, this.vm.context, options) : vm.runInThisContext(wrappedCode, options), dynamicRequest = async (dep, options) => {
137
+ return dep = String(dep), dep[0] === "#" ? context[ssrDynamicImportKey](wrapId(dep), options) : context[ssrDynamicImportKey](dep, options);
138
+ };
139
+ await initModule(
140
+ context[ssrModuleExportsKey],
141
+ context[ssrImportMetaKey],
142
+ context[ssrImportKey],
143
+ dynamicRequest,
144
+ context[ssrExportAllKey],
145
+ // vite 7 support, remove when vite 7+ is supported
146
+ context.__vite_ssr_exportName__ || ((name, getter) => Object.defineProperty(exportsObject, name, {
147
+ enumerable: true,
148
+ configurable: true,
149
+ get: getter
150
+ })),
151
+ filename,
152
+ dirname,
153
+ moduleProxy,
154
+ cjsExports,
155
+ require,
156
+ ...this.compiledFunctionArgumentsValues
157
+ );
158
+ } finally {
159
+ // moduleExecutionInfo needs to use Node filename instead of the normalized one
160
+ // because we rely on this behaviour in coverage-v8, for example
161
+ this.options.moduleExecutionInfo?.set(filename, finishModuleExecutionInfo());
162
+ }
163
+ }
164
+ createRequire(filename) {
165
+ return filename.startsWith("\0") || !isAbsolute(filename) ? () => ({}) : this.vm ? this.vm.externalModulesExecutor.createRequire(filename) : createRequire(filename);
166
+ }
167
+ shouldInterop(path, mod) {
168
+ // never interop ESM modules
169
+ // TODO: should also skip for `.js` with `type="module"`
170
+ return this.options.interopDefault === false ? false : !path.endsWith(".mjs") && "default" in mod;
171
+ }
172
+ }
173
+ function createImportMetaEnvProxy() {
174
+ // packages/vitest/src/node/plugins/index.ts:146
175
+ const booleanKeys = [
176
+ "DEV",
177
+ "PROD",
178
+ "SSR"
179
+ ];
180
+ return new Proxy(process.env, {
181
+ get(_, key) {
182
+ return typeof key === "string" ? booleanKeys.includes(key) ? !!process.env[key] : process.env[key] : void 0;
183
+ },
184
+ set(_, key, value) {
185
+ if (typeof key !== "string") return true;
186
+ if (booleanKeys.includes(key)) process.env[key] = value ? "1" : "";
187
+ else process.env[key] = value;
188
+ return true;
189
+ }
190
+ });
191
+ }
192
+ function updateStyle(id, css) {
193
+ if (typeof document === "undefined") return;
194
+ const element = document.querySelector(`[data-vite-dev-id="${id}"]`);
195
+ if (element) {
196
+ element.textContent = css;
197
+ return;
198
+ }
199
+ const head = document.querySelector("head"), style = document.createElement("style");
200
+ style.setAttribute("type", "text/css"), style.setAttribute("data-vite-dev-id", id), style.textContent = css, head?.appendChild(style);
201
+ }
202
+ function removeStyle(id) {
203
+ if (typeof document === "undefined") return;
204
+ const sheet = document.querySelector(`[data-vite-dev-id="${id}"]`);
205
+ if (sheet) document.head.removeChild(sheet);
206
+ }
207
+ const defaultClientStub = {
208
+ injectQuery: (id) => id,
209
+ createHotContext: () => {
210
+ return {
211
+ accept: () => {},
212
+ prune: () => {},
213
+ dispose: () => {},
214
+ decline: () => {},
215
+ invalidate: () => {},
216
+ on: () => {},
217
+ send: () => {}
218
+ };
219
+ },
220
+ updateStyle: () => {},
221
+ removeStyle: () => {}
222
+ };
223
+ function getDefaultRequestStubs(context) {
224
+ if (!context) {
225
+ const clientStub = {
226
+ ...defaultClientStub,
227
+ updateStyle,
228
+ removeStyle
229
+ };
230
+ return { "/@vite/client": clientStub };
231
+ }
232
+ const clientStub = vm.runInContext(`(defaultClient) => ({ ...defaultClient, updateStyle: ${updateStyle.toString()}, removeStyle: ${removeStyle.toString()} })`, context)(defaultClientStub);
233
+ return { "/@vite/client": clientStub };
234
+ }
235
+ function exportAll(exports, sourceModule) {
236
+ if (exports !== sourceModule && !(isPrimitive(sourceModule) || Array.isArray(sourceModule) || sourceModule instanceof Promise)) {
237
+ for (const key in sourceModule) if (key !== "default" && !(key in exports)) try {
238
+ defineExport(exports, key, () => sourceModule[key]);
239
+ } catch {}
240
+ }
241
+ }
242
+ // keep consistency with Vite on how exports are defined
243
+ function defineExport(exports, key, value) {
244
+ Object.defineProperty(exports, key, {
245
+ enumerable: true,
246
+ configurable: true,
247
+ get: value
248
+ });
249
+ }
250
+ function isPrimitive(v) {
251
+ const isObject = typeof v === "object" || typeof v === "function";
252
+ return !isObject || v == null;
253
+ }
254
+ function interopModule(mod) {
255
+ if (isPrimitive(mod)) return {
256
+ mod: { default: mod },
257
+ defaultExport: mod
258
+ };
259
+ let defaultExport = "default" in mod ? mod.default : mod;
260
+ if (!isPrimitive(defaultExport) && "__esModule" in defaultExport) {
261
+ if (mod = defaultExport, "default" in defaultExport) defaultExport = defaultExport.default;
262
+ }
263
+ return {
264
+ mod,
265
+ defaultExport
266
+ };
267
+ }
268
+ const VALID_ID_PREFIX = `/@id/`, NULL_BYTE_PLACEHOLDER = `__x00__`;
269
+ function wrapId(id) {
270
+ return id.startsWith(VALID_ID_PREFIX) ? id : VALID_ID_PREFIX + id.replace("\0", NULL_BYTE_PLACEHOLDER);
271
+ }
272
+ function unwrapId(id) {
273
+ return id.startsWith(VALID_ID_PREFIX) ? id.slice(VALID_ID_PREFIX.length).replace(NULL_BYTE_PLACEHOLDER, "\0") : id;
274
+ }
275
+
276
+ export { VitestModuleEvaluator, createImportMetaEnvProxy, getDefaultRequestStubs, isPrimitive, unwrapId, wrapId };
@@ -0,0 +1,15 @@
1
+ export { VitestModuleEvaluator } from './module-evaluator.js';
2
+ export { a as VITEST_VM_CONTEXT_SYMBOL, V as VitestModuleRunner, s as startVitestModuleRunner } from './chunks/startModuleRunner.C8TW8zTN.js';
3
+ export { g as getWorkerState } from './chunks/utils.C7__0Iv5.js';
4
+ import 'node:module';
5
+ import 'node:url';
6
+ import 'node:vm';
7
+ import 'pathe';
8
+ import 'vite/module-runner';
9
+ import 'node:fs';
10
+ import '@vitest/utils';
11
+ import './path.js';
12
+ import 'node:path';
13
+ import '@vitest/utils/error';
14
+ import '@vitest/mocker';
15
+ import './chunks/moduleTransport.I-bgQy0S.js';