vitest 4.0.0-beta.10 → 4.0.0-beta.12

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 (69) hide show
  1. package/LICENSE.md +85 -101
  2. package/dist/browser.d.ts +10 -6
  3. package/dist/browser.js +8 -5
  4. package/dist/chunks/{benchmark.CJUa-Hsa.js → benchmark.DHKMYAts.js} +2 -2
  5. package/dist/chunks/{browser.d.yFAklsD1.d.ts → browser.d.D9YV3JvA.d.ts} +1 -1
  6. package/dist/chunks/{cac.DCxo_nSu.js → cac.r1gel_VZ.js} +18 -11
  7. package/dist/chunks/{cli-api.BJJXh9BV.js → cli-api.CpywZzJV.js} +153 -176
  8. package/dist/chunks/{config.d.B_LthbQq.d.ts → config.d.DGazh2r6.d.ts} +3 -1
  9. package/dist/chunks/{console.7h5kHUIf.js → console.CTJL2nuH.js} +4 -6
  10. package/dist/chunks/{coverage.BCU-r2QL.js → coverage.CiB0fs_7.js} +57 -79
  11. package/dist/chunks/{creator.08Gi-vCA.js → creator.DfXDsUyL.js} +6 -8
  12. package/dist/chunks/{global.d.BK3X7FW1.d.ts → global.d.BcFPD2LN.d.ts} +0 -13
  13. package/dist/chunks/{globals.DG-S3xFe.js → globals.DC4ntO86.js} +8 -6
  14. package/dist/chunks/{index.DIWhzsUh.js → index.Bt-upxGS.js} +6 -12
  15. package/dist/chunks/{index.BIP7prJq.js → index.CHrBLuEH.js} +94 -103
  16. package/dist/chunks/{index.X0nbfr6-.js → index.Dc3xnDvT.js} +48 -289
  17. package/dist/chunks/{index.CMfqw92x.js → index.Dnl38iQ_.js} +2 -2
  18. package/dist/chunks/{index.BjKEiSn0.js → index.uLUz1RDt.js} +3 -3
  19. package/dist/chunks/{inspector.CvQD-Nie.js → inspector.Br76Q2Mb.js} +1 -4
  20. package/dist/chunks/{moduleRunner.d.D9nBoC4p.d.ts → moduleRunner.d.CeYc7nZ0.d.ts} +1 -1
  21. package/dist/chunks/{node.CyipiPvJ.js → node.BwAWWjHZ.js} +3 -4
  22. package/dist/chunks/{plugin.d.BMVSnsGV.d.ts → plugin.d.XreRXLXS.d.ts} +1 -1
  23. package/dist/chunks/{reporters.d.BUWjmRYq.d.ts → reporters.d.CJVTaaWb.d.ts} +54 -13
  24. package/dist/chunks/{resolveSnapshotEnvironment.Bkht6Yor.js → resolveSnapshotEnvironment.BsJpmVZR.js} +7 -8
  25. package/dist/chunks/{rpc.BKr6mtxz.js → rpc.cD77ENhU.js} +13 -14
  26. package/dist/chunks/{setup-common.uiMcU3cv.js → setup-common.BewgbkTd.js} +6 -6
  27. package/dist/chunks/{startModuleRunner.p67gbNo9.js → startModuleRunner.DPBo3mme.js} +65 -56
  28. package/dist/chunks/{test.BiqSKISg.js → test.CTuWuHYH.js} +7 -7
  29. package/dist/chunks/{typechecker.DB-fIMaH.js → typechecker.BfOQ86_a.js} +624 -14
  30. package/dist/chunks/{utils.D2R2NiOH.js → utils.CG9h5ccR.js} +2 -5
  31. package/dist/chunks/{vi.ZPgvtBao.js → vi.B2--mG9U.js} +38 -145
  32. package/dist/{worker.js → chunks/worker.DVTUM2IW.js} +71 -42
  33. package/dist/chunks/{worker.d.BDsXGkwh.d.ts → worker.d.buwuBpBt.d.ts} +2 -77
  34. package/dist/cli.js +7 -5
  35. package/dist/config.d.ts +6 -6
  36. package/dist/coverage.d.ts +5 -5
  37. package/dist/coverage.js +4 -5
  38. package/dist/environments.js +1 -1
  39. package/dist/index.d.ts +8 -8
  40. package/dist/index.js +8 -6
  41. package/dist/module-evaluator.d.ts +3 -3
  42. package/dist/module-evaluator.js +11 -13
  43. package/dist/module-runner.js +5 -5
  44. package/dist/node.d.ts +14 -11
  45. package/dist/node.js +18 -14
  46. package/dist/reporters.d.ts +5 -5
  47. package/dist/reporters.js +7 -5
  48. package/dist/runners.d.ts +1 -1
  49. package/dist/runners.js +9 -7
  50. package/dist/snapshot.js +3 -3
  51. package/dist/suite.js +4 -3
  52. package/dist/{chunks/base.Cjha6usc.js → worker-base.js} +104 -32
  53. package/dist/{chunks/vm.Ca0Y0W5f.js → worker-vm.js} +81 -31
  54. package/dist/workers/runVmTests.js +14 -11
  55. package/package.json +26 -26
  56. package/browser.d.ts +0 -1
  57. package/dist/chunks/moduleTransport.I-bgQy0S.js +0 -19
  58. package/dist/chunks/resolver.Bx6lE0iq.js +0 -119
  59. package/dist/chunks/utils.C2YI6McM.js +0 -52
  60. package/dist/chunks/worker.d.BNcX_2mH.d.ts +0 -8
  61. package/dist/workers/forks.js +0 -67
  62. package/dist/workers/threads.js +0 -55
  63. package/dist/workers/vmForks.js +0 -48
  64. package/dist/workers/vmThreads.js +0 -38
  65. package/dist/workers.d.ts +0 -38
  66. package/dist/workers.js +0 -48
  67. package/execute.d.ts +0 -1
  68. package/utils.d.ts +0 -1
  69. package/workers.d.ts +0 -1
@@ -1,20 +1,48 @@
1
+ import { c as createForksRpcOptions, u as unwrapSerializableConfig, a as createThreadsRpcOptions, e as execute, t as teardown$1 } from './chunks/worker.DVTUM2IW.js';
2
+ import v8 from 'node:v8';
1
3
  import { runInThisContext } from 'node:vm';
2
4
  import * as spyModule from '@vitest/spy';
3
5
  import { EvaluatedModules } from 'vite/module-runner';
4
- import { s as startVitestModuleRunner, c as createNodeImportMeta } from './startModuleRunner.p67gbNo9.js';
6
+ import { s as startVitestModuleRunner, c as createNodeImportMeta } from './chunks/startModuleRunner.DPBo3mme.js';
5
7
  import { performance } from 'node:perf_hooks';
6
8
  import { startTests, collectTests } from '@vitest/runner';
7
- import { a as resolveSnapshotEnvironment, s as setupChaiConfig, r as resolveTestRunner } from './resolveSnapshotEnvironment.Bkht6Yor.js';
8
- import { c as setupCommonEnv, s as startCoverageInsideWorker, a as stopCoverageInsideWorker } from './setup-common.uiMcU3cv.js';
9
- import { g as globalExpect, v as vi } from './vi.ZPgvtBao.js';
10
- import { c as closeInspector } from './inspector.CvQD-Nie.js';
9
+ import { a as resolveSnapshotEnvironment, s as setupChaiConfig, r as resolveTestRunner } from './chunks/resolveSnapshotEnvironment.BsJpmVZR.js';
10
+ import { c as setupCommonEnv, s as startCoverageInsideWorker, a as stopCoverageInsideWorker } from './chunks/setup-common.BewgbkTd.js';
11
+ import { g as globalExpect, v as vi } from './chunks/vi.B2--mG9U.js';
12
+ import { c as closeInspector } from './chunks/inspector.Br76Q2Mb.js';
11
13
  import { createRequire } from 'node:module';
12
14
  import timers from 'node:timers';
13
15
  import timersPromises from 'node:timers/promises';
14
16
  import util from 'node:util';
15
- import { KNOWN_ASSET_TYPES, getSafeTimers } from '@vitest/utils';
16
- import { i as index } from './index.CMfqw92x.js';
17
- import { g as getWorkerState, r as resetModules, p as provideWorkerState } from './utils.D2R2NiOH.js';
17
+ import { KNOWN_ASSET_TYPES } from '@vitest/utils/constants';
18
+ import { getSafeTimers } from '@vitest/utils/timers';
19
+ import { i as index } from './chunks/index.Dnl38iQ_.js';
20
+ import { g as getWorkerState, r as resetModules, p as provideWorkerState } from './chunks/utils.CG9h5ccR.js';
21
+ import '@vitest/utils/source-map';
22
+ import 'node:fs';
23
+ import 'node:url';
24
+ import 'pathe';
25
+ import './chunks/index.Bt-upxGS.js';
26
+ import 'node:console';
27
+ import './chunks/rpc.cD77ENhU.js';
28
+ import './chunks/index.Bgo3tNWt.js';
29
+ import '@vitest/utils/helpers';
30
+ import './path.js';
31
+ import 'node:path';
32
+ import '@vitest/utils/serialize';
33
+ import './module-evaluator.js';
34
+ import '@vitest/mocker';
35
+ import '@vitest/expect';
36
+ import './chunks/test.CTuWuHYH.js';
37
+ import './chunks/benchmark.DHKMYAts.js';
38
+ import '@vitest/runner/utils';
39
+ import '@vitest/utils/error';
40
+ import './chunks/coverage.D_JHT54q.js';
41
+ import '@vitest/snapshot';
42
+ import '@vitest/utils/offset';
43
+ import './chunks/_commonjsHelpers.BFTU3MAI.js';
44
+ import './chunks/date.-jtEtIeV.js';
45
+ import 'expect-type';
18
46
 
19
47
  // this should only be used in Node
20
48
  let globalSetup = false;
@@ -25,20 +53,19 @@ async function setupGlobalEnv(config, { environment }, moduleRunner) {
25
53
  });
26
54
  const state = getWorkerState();
27
55
  if (!state.config.snapshotOptions.snapshotEnvironment) state.config.snapshotOptions.snapshotEnvironment = await resolveSnapshotEnvironment(config, moduleRunner);
28
- if (globalSetup) return;
29
- globalSetup = true;
30
- const viteEnvironment = environment.viteEnvironment || environment.name;
31
- if (viteEnvironment === "client") {
32
- const _require = createRequire(import.meta.url);
33
- _require.extensions[".css"] = resolveCss, _require.extensions[".scss"] = resolveCss, _require.extensions[".sass"] = resolveCss, _require.extensions[".less"] = resolveCss, KNOWN_ASSET_TYPES.forEach((type) => {
34
- _require.extensions[`.${type}`] = resolveAsset;
35
- }), process.env.SSR = "";
36
- } else process.env.SSR = "1";
37
- if (globalThis.__vitest_required__ = {
38
- util,
39
- timers,
40
- timersPromises
41
- }, !config.disableConsoleIntercept) await setupConsoleLogSpy();
56
+ if (!globalSetup) {
57
+ if (globalSetup = true, (environment.viteEnvironment || environment.name) === "client") {
58
+ const _require = createRequire(import.meta.url);
59
+ _require.extensions[".css"] = resolveCss, _require.extensions[".scss"] = resolveCss, _require.extensions[".sass"] = resolveCss, _require.extensions[".less"] = resolveCss, KNOWN_ASSET_TYPES.forEach((type) => {
60
+ _require.extensions[`.${type}`] = resolveAsset;
61
+ }), process.env.SSR = "";
62
+ } else process.env.SSR = "1";
63
+ if (globalThis.__vitest_required__ = {
64
+ util,
65
+ timers,
66
+ timersPromises
67
+ }, !config.disableConsoleIntercept) await setupConsoleLogSpy();
68
+ }
42
69
  }
43
70
  function resolveCss(mod) {
44
71
  mod.exports = "";
@@ -47,7 +74,7 @@ function resolveAsset(mod, url) {
47
74
  mod.exports = url;
48
75
  }
49
76
  async function setupConsoleLogSpy() {
50
- const { createCustomConsole } = await import('./console.7h5kHUIf.js');
77
+ const { createCustomConsole } = await import('./chunks/console.CTJL2nuH.js');
51
78
  globalThis.console = createCustomConsole();
52
79
  }
53
80
  async function withEnv({ environment }, options, fn) {
@@ -63,7 +90,7 @@ async function withEnv({ environment }, options, fn) {
63
90
  }
64
91
 
65
92
  // browser shouldn't call this!
66
- async function run(method, files, config, environment, moduleRunner) {
93
+ async function run$1(method, files, config, environment, moduleRunner) {
67
94
  const workerState = getWorkerState(), isIsolatedThreads = config.pool === "threads" && (config.poolOptions?.threads?.isolate ?? true), isIsolatedForks = config.pool === "forks" && (config.poolOptions?.forks?.isolate ?? true), isolate = isIsolatedThreads || isIsolatedForks;
68
95
  if (await setupGlobalEnv(config, environment, moduleRunner), await startCoverageInsideWorker(config.coverage, moduleRunner, { isolate }), config.chaiConfig) setupChaiConfig(config.chaiConfig);
69
96
  const runner = await resolveTestRunner(config, moduleRunner);
@@ -90,16 +117,13 @@ function startModuleRunner(options) {
90
117
  async function runBaseTests(method, state) {
91
118
  const { ctx } = state;
92
119
  if (state.evaluatedModules = evaluatedModules, state.moduleExecutionInfo = moduleExecutionInfo, provideWorkerState(globalThis, state), ctx.invalidates) ctx.invalidates.forEach((filepath) => {
93
- const modules = state.evaluatedModules.fileToModulesMap.get(filepath) || [];
94
- modules.forEach((module) => {
120
+ (state.evaluatedModules.fileToModulesMap.get(filepath) || []).forEach((module) => {
95
121
  state.evaluatedModules.invalidateModule(module);
96
122
  });
97
- // evaluatedModules.delete(fsPath)
98
- // evaluatedModules.delete(`mock:${fsPath}`)
99
123
  });
100
124
  ctx.files.forEach((i) => {
101
- const filepath = typeof i === "string" ? i : i.filepath, modules = state.evaluatedModules.fileToModulesMap.get(filepath) || [];
102
- modules.forEach((module) => {
125
+ const filepath = typeof i === "string" ? i : i.filepath;
126
+ (state.evaluatedModules.fileToModulesMap.get(filepath) || []).forEach((module) => {
103
127
  state.evaluatedModules.invalidateModule(module);
104
128
  });
105
129
  });
@@ -112,6 +136,7 @@ async function runBaseTests(method, state) {
112
136
  filepath: f,
113
137
  testLocations: void 0
114
138
  } : f);
139
+ // we could load @vite/env, but it would take ~8ms, while this takes ~0,02ms
115
140
  if (ctx.config.serializedDefines) try {
116
141
  runInThisContext(`(() =>{\n${ctx.config.serializedDefines}})()`, {
117
142
  lineOffset: 1,
@@ -120,10 +145,57 @@ async function runBaseTests(method, state) {
120
145
  } catch (error) {
121
146
  throw new Error(`Failed to load custom "defines": ${error.message}`);
122
147
  }
123
- await run(method, fileSpecs, ctx.config, {
148
+ await run$1(method, fileSpecs, ctx.config, {
124
149
  environment: state.environment,
125
150
  options: ctx.environment.options
126
151
  }, executor);
127
152
  }
128
153
 
129
- export { runBaseTests as r };
154
+ class ForksBaseWorker {
155
+ getRpcOptions() {
156
+ return createForksRpcOptions(v8);
157
+ }
158
+ async executeTests(method, state) {
159
+ // TODO: don't rely on reassigning process.exit
160
+ // https://github.com/vitest-dev/vitest/pull/4441#discussion_r1443771486
161
+ const exit = process.exit;
162
+ state.ctx.config = unwrapSerializableConfig(state.ctx.config);
163
+ try {
164
+ await runBaseTests(method, state);
165
+ } finally {
166
+ process.exit = exit;
167
+ }
168
+ }
169
+ runTests(state) {
170
+ return this.executeTests("run", state);
171
+ }
172
+ collectTests(state) {
173
+ return this.executeTests("collect", state);
174
+ }
175
+ }
176
+ const worker$1 = new ForksBaseWorker();
177
+
178
+ class ThreadsBaseWorker {
179
+ getRpcOptions(ctx) {
180
+ return createThreadsRpcOptions(ctx);
181
+ }
182
+ runTests(state) {
183
+ return runBaseTests("run", state);
184
+ }
185
+ collectTests(state) {
186
+ return runBaseTests("collect", state);
187
+ }
188
+ }
189
+ const worker = new ThreadsBaseWorker();
190
+
191
+ async function run(ctx) {
192
+ await execute("run", ctx, ctx.pool === "forks" ? worker$1 : worker);
193
+ }
194
+ async function collect(ctx) {
195
+ await execute("collect", ctx, ctx.pool === "forks" ? worker$1 : worker);
196
+ }
197
+ async function teardown() {
198
+ await teardown$1();
199
+ }
200
+
201
+ export { collect, run, teardown };
@@ -1,16 +1,32 @@
1
+ import { c as createForksRpcOptions, u as unwrapSerializableConfig, a as createThreadsRpcOptions, e as execute, t as teardown$1 } from './chunks/worker.DVTUM2IW.js';
2
+ import v8 from 'node:v8';
1
3
  import { fileURLToPath, pathToFileURL } from 'node:url';
2
4
  import vm, { isContext, runInContext } from 'node:vm';
3
5
  import { dirname, basename, extname, normalize, resolve } from 'pathe';
4
- import { distDir } from '../path.js';
5
- import { createCustomConsole } from './console.7h5kHUIf.js';
6
+ import { distDir } from './path.js';
7
+ import { createCustomConsole } from './chunks/console.CTJL2nuH.js';
6
8
  import fs from 'node:fs';
7
9
  import { createRequire, Module, isBuiltin } from 'node:module';
8
- import { CSS_LANGS_RE, KNOWN_ASSET_RE, toArray, isBareImport } from '@vitest/utils';
9
- import { f as findNearestPackageData } from './resolver.Bx6lE0iq.js';
10
+ import { toArray, isBareImport } from '@vitest/utils/helpers';
11
+ import { findNearestPackageData } from '@vitest/utils/resolver';
10
12
  import { dirname as dirname$1 } from 'node:path';
11
- import { getDefaultRequestStubs } from '../module-evaluator.js';
12
- import { s as startVitestModuleRunner, a as VITEST_VM_CONTEXT_SYMBOL, c as createNodeImportMeta } from './startModuleRunner.p67gbNo9.js';
13
- import { p as provideWorkerState } from './utils.D2R2NiOH.js';
13
+ import { CSS_LANGS_RE, KNOWN_ASSET_RE } from '@vitest/utils/constants';
14
+ import { getDefaultRequestStubs } from './module-evaluator.js';
15
+ import { s as startVitestModuleRunner, c as createNodeImportMeta, a as VITEST_VM_CONTEXT_SYMBOL } from './chunks/startModuleRunner.DPBo3mme.js';
16
+ import { p as provideWorkerState } from './chunks/utils.CG9h5ccR.js';
17
+ import '@vitest/utils/source-map';
18
+ import 'vite/module-runner';
19
+ import './chunks/index.Bt-upxGS.js';
20
+ import 'node:console';
21
+ import './chunks/inspector.Br76Q2Mb.js';
22
+ import './chunks/rpc.cD77ENhU.js';
23
+ import '@vitest/utils/timers';
24
+ import './chunks/index.Bgo3tNWt.js';
25
+ import 'node:stream';
26
+ import 'tinyrainbow';
27
+ import './chunks/date.-jtEtIeV.js';
28
+ import '@vitest/utils/serialize';
29
+ import '@vitest/mocker';
14
30
 
15
31
  function interopCommonJsModule(interopDefault, mod) {
16
32
  if (isPrimitive(mod) || Array.isArray(mod) || mod instanceof Promise) return {
@@ -35,8 +51,7 @@ function interopCommonJsModule(interopDefault, mod) {
35
51
  };
36
52
  }
37
53
  function isPrimitive(obj) {
38
- const isObject = obj != null && (typeof obj === "object" || typeof obj === "function");
39
- return !isObject;
54
+ return !(obj != null && (typeof obj === "object" || typeof obj === "function"));
40
55
  }
41
56
  const SyntheticModule = vm.SyntheticModule;
42
57
  const SourceTextModule = vm.SourceTextModule;
@@ -105,8 +120,7 @@ class CommonjsExecutor {
105
120
  }
106
121
  // exposed for external use, Node.js does the opposite
107
122
  static _load = (request, parent, _isMain) => {
108
- const require = Module$1.createRequire(parent?.filename ?? request);
109
- return require(request);
123
+ return Module$1.createRequire(parent?.filename ?? request)(request);
110
124
  };
111
125
  static wrap = (script) => {
112
126
  return Module$1.wrapper[0] + script + Module$1.wrapper[1];
@@ -156,8 +170,8 @@ class CommonjsExecutor {
156
170
  };
157
171
  createRequire = (filename) => {
158
172
  const _require = createRequire(filename), require = ((id) => {
159
- const resolved = _require.resolve(id), ext = extname(resolved);
160
- if (ext === ".node" || isBuiltin(resolved)) return this.requireCoreModule(resolved);
173
+ const resolved = _require.resolve(id);
174
+ if (extname(resolved) === ".node" || isBuiltin(resolved)) return this.requireCoreModule(resolved);
161
175
  const module = new this.Module(resolved);
162
176
  return this.loadCommonJSModule(module, resolved);
163
177
  });
@@ -187,8 +201,8 @@ class CommonjsExecutor {
187
201
  loadCommonJSModule(module, filename) {
188
202
  const cached = this.requireCache.get(filename);
189
203
  if (cached) return cached.exports;
190
- const extension = this.findLongestRegisteredExtension(filename), loader = this.extensions[extension] || this.extensions[".js"];
191
- return loader(module, filename), module.exports;
204
+ const extension = this.findLongestRegisteredExtension(filename);
205
+ return (this.extensions[extension] || this.extensions[".js"])(module, filename), module.exports;
192
206
  }
193
207
  findLongestRegisteredExtension(filename) {
194
208
  const name = basename(filename);
@@ -259,8 +273,7 @@ class CommonjsExecutor {
259
273
  // return namedExports
260
274
  // }
261
275
  require(identifier) {
262
- const ext = extname(identifier);
263
- if (ext === ".node" || isBuiltin(identifier)) return this.requireCoreModule(identifier);
276
+ if (extname(identifier) === ".node" || isBuiltin(identifier)) return this.requireCoreModule(identifier);
264
277
  const module = new this.Module(identifier);
265
278
  return this.loadCommonJSModule(module, identifier);
266
279
  }
@@ -345,7 +358,8 @@ class EsmExecutor {
345
358
  if (cached) return cached;
346
359
  const wasmModule = await WebAssembly.compile(source), exports = WebAssembly.Module.exports(wasmModule), imports = WebAssembly.Module.imports(wasmModule), moduleLookup = {};
347
360
  for (const { module } of imports) if (moduleLookup[module] === void 0) moduleLookup[module] = await this.executor.resolveModule(module, identifier);
348
- const evaluateModule = (module) => this.evaluateModule(module), syntheticModule = new SyntheticModule(exports.map(({ name }) => name), async function() {
361
+ const evaluateModule = (module) => this.evaluateModule(module);
362
+ return new SyntheticModule(exports.map(({ name }) => name), async function() {
349
363
  const importsObject = {};
350
364
  for (const { module, name } of imports) {
351
365
  if (!importsObject[module]) importsObject[module] = {};
@@ -357,7 +371,6 @@ class EsmExecutor {
357
371
  context: this.context,
358
372
  identifier
359
373
  });
360
- return syntheticModule;
361
374
  }
362
375
  cacheModule(identifier, module) {
363
376
  this.moduleCache.set(identifier, module);
@@ -416,9 +429,7 @@ class ViteExecutor {
416
429
  return this.options.context.__vitest_worker__;
417
430
  }
418
431
  async createViteModule(fileUrl) {
419
- if (fileUrl === CLIENT_FILE || fileUrl === CLIENT_ID) return this.createViteClientModule();
420
- const cached = this.esm.resolveCachedModule(fileUrl);
421
- return cached || this.esm.createEsModule(fileUrl, async () => {
432
+ return fileUrl === CLIENT_FILE || fileUrl === CLIENT_ID ? this.createViteClientModule() : this.esm.resolveCachedModule(fileUrl) || this.esm.createEsModule(fileUrl, async () => {
422
433
  try {
423
434
  const result = await this.options.transform(fileUrl);
424
435
  if (result.code) return result.code;
@@ -529,10 +540,7 @@ class ExternalModulesExecutor {
529
540
  // still experimental on NodeJS --experimental-wasm-modules
530
541
  // cf. ESM_FILE_FORMAT(url) in https://nodejs.org/docs/latest-v20.x/api/esm.html#resolution-algorithm
531
542
  type = "wasm";
532
- else {
533
- const pkgData = findNearestPackageData(normalize(pathUrl));
534
- type = pkgData.type === "module" ? "module" : "commonjs";
535
- }
543
+ else type = findNearestPackageData(normalize(pathUrl)).type === "module" ? "module" : "commonjs";
536
544
  return {
537
545
  type,
538
546
  path: pathUrl,
@@ -555,10 +563,7 @@ class ExternalModulesExecutor {
555
563
  case "module": return this.esm.createEsModule(url, () => this.fs.readFileAsync(path));
556
564
  case "commonjs": return this.cjs.getCjsSyntheticModule(path, identifier);
557
565
  case "network": return this.esm.createNetworkModule(url);
558
- default: {
559
- const _deadend = type;
560
- return _deadend;
561
- }
566
+ default: return type;
562
567
  }
563
568
  }
564
569
  get isNetworkSupported() {
@@ -643,4 +648,49 @@ async function runVmTests(method, state) {
643
648
  }
644
649
  }
645
650
 
646
- export { runVmTests as r };
651
+ class ForksVmWorker {
652
+ getRpcOptions() {
653
+ return createForksRpcOptions(v8);
654
+ }
655
+ async executeTests(method, state) {
656
+ const exit = process.exit;
657
+ state.ctx.config = unwrapSerializableConfig(state.ctx.config);
658
+ try {
659
+ await runVmTests(method, state);
660
+ } finally {
661
+ process.exit = exit;
662
+ }
663
+ }
664
+ runTests(state) {
665
+ return this.executeTests("run", state);
666
+ }
667
+ collectTests(state) {
668
+ return this.executeTests("collect", state);
669
+ }
670
+ }
671
+ const worker$1 = new ForksVmWorker();
672
+
673
+ class ThreadsVmWorker {
674
+ getRpcOptions(ctx) {
675
+ return createThreadsRpcOptions(ctx);
676
+ }
677
+ runTests(state) {
678
+ return runVmTests("run", state);
679
+ }
680
+ collectTests(state) {
681
+ return runVmTests("collect", state);
682
+ }
683
+ }
684
+ const worker = new ThreadsVmWorker();
685
+
686
+ async function run(ctx) {
687
+ await execute("run", ctx, ctx.pool === "vmForks" ? worker$1 : worker);
688
+ }
689
+ async function collect(ctx) {
690
+ await execute("collect", ctx, ctx.pool === "vmForks" ? worker$1 : worker);
691
+ }
692
+ async function teardown() {
693
+ await teardown$1();
694
+ }
695
+
696
+ export { collect, run, teardown };
@@ -4,18 +4,20 @@ import timers from 'node:timers';
4
4
  import timersPromises from 'node:timers/promises';
5
5
  import util from 'node:util';
6
6
  import { startTests, collectTests } from '@vitest/runner';
7
- import { KNOWN_ASSET_TYPES } from '@vitest/utils';
8
- import { s as setupChaiConfig, r as resolveTestRunner, a as resolveSnapshotEnvironment } from '../chunks/resolveSnapshotEnvironment.Bkht6Yor.js';
9
- import { c as setupCommonEnv, s as startCoverageInsideWorker, a as stopCoverageInsideWorker } from '../chunks/setup-common.uiMcU3cv.js';
10
- import { i as index } from '../chunks/index.CMfqw92x.js';
11
- import { c as closeInspector } from '../chunks/inspector.CvQD-Nie.js';
12
- import { g as getWorkerState } from '../chunks/utils.D2R2NiOH.js';
13
- import { g as globalExpect } from '../chunks/vi.ZPgvtBao.js';
7
+ import { KNOWN_ASSET_TYPES } from '@vitest/utils/constants';
8
+ import { s as setupChaiConfig, r as resolveTestRunner, a as resolveSnapshotEnvironment } from '../chunks/resolveSnapshotEnvironment.BsJpmVZR.js';
9
+ import { c as setupCommonEnv, s as startCoverageInsideWorker, a as stopCoverageInsideWorker } from '../chunks/setup-common.BewgbkTd.js';
10
+ import { i as index } from '../chunks/index.Dnl38iQ_.js';
11
+ import { c as closeInspector } from '../chunks/inspector.Br76Q2Mb.js';
12
+ import { g as getWorkerState } from '../chunks/utils.CG9h5ccR.js';
13
+ import { g as globalExpect } from '../chunks/vi.B2--mG9U.js';
14
14
  import '@vitest/expect';
15
- import '../chunks/rpc.BKr6mtxz.js';
15
+ import '../chunks/rpc.cD77ENhU.js';
16
+ import '@vitest/utils/timers';
16
17
  import '../chunks/index.Bgo3tNWt.js';
17
- import '../chunks/test.BiqSKISg.js';
18
- import '../chunks/benchmark.CJUa-Hsa.js';
18
+ import '../chunks/test.CTuWuHYH.js';
19
+ import '@vitest/utils/helpers';
20
+ import '../chunks/benchmark.DHKMYAts.js';
19
21
  import '@vitest/runner/utils';
20
22
  import '@vitest/utils/error';
21
23
  import 'pathe';
@@ -24,9 +26,10 @@ import '@vitest/snapshot';
24
26
  import 'expect-type';
25
27
  import 'vite/module-runner';
26
28
  import 'node:url';
27
- import '../chunks/_commonjsHelpers.BFTU3MAI.js';
28
29
  import '@vitest/spy';
30
+ import '@vitest/utils/offset';
29
31
  import '@vitest/utils/source-map';
32
+ import '../chunks/_commonjsHelpers.BFTU3MAI.js';
30
33
  import '../chunks/date.-jtEtIeV.js';
31
34
 
32
35
  async function run(method, files, config, moduleRunner) {
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "vitest",
3
3
  "type": "module",
4
- "version": "4.0.0-beta.10",
4
+ "version": "4.0.0-beta.12",
5
5
  "description": "Next generation testing framework powered by Vite",
6
6
  "author": "Anthony Fu <anthonyfu117@hotmail.com>",
7
7
  "license": "MIT",
8
8
  "funding": "https://opencollective.com/vitest",
9
- "homepage": "https://github.com/vitest-dev/vitest#readme",
9
+ "homepage": "https://vitest.dev",
10
10
  "repository": {
11
11
  "type": "git",
12
12
  "url": "git+https://github.com/vitest-dev/vitest.git",
@@ -39,7 +39,11 @@
39
39
  "default": "./index.cjs"
40
40
  }
41
41
  },
42
- "./*": "./*",
42
+ "./package.json": "./package.json",
43
+ "./optional-types.js": {
44
+ "types": "./optional-types.d.ts"
45
+ },
46
+ "./src/*": "./src/*",
43
47
  "./globals": {
44
48
  "types": "./globals.d.ts"
45
49
  },
@@ -56,10 +60,6 @@
56
60
  "types": "./dist/node.d.ts",
57
61
  "default": "./dist/node.js"
58
62
  },
59
- "./workers": {
60
- "types": "./dist/workers.d.ts",
61
- "import": "./dist/workers.js"
62
- },
63
63
  "./internal/browser": {
64
64
  "types": "./dist/browser.d.ts",
65
65
  "default": "./dist/browser.js"
@@ -117,7 +117,7 @@
117
117
  "dist"
118
118
  ],
119
119
  "engines": {
120
- "node": "^18.0.0 || ^20.0.0 || >=22.0.0"
120
+ "node": "^20.0.0 || ^22.0.0 || >=24.0.0"
121
121
  },
122
122
  "peerDependencies": {
123
123
  "@edge-runtime/vm": "*",
@@ -125,8 +125,8 @@
125
125
  "@types/node": "^18.0.0 || ^20.0.0 || >=22.0.0",
126
126
  "happy-dom": "*",
127
127
  "jsdom": "*",
128
- "@vitest/browser": "4.0.0-beta.10",
129
- "@vitest/ui": "4.0.0-beta.10"
128
+ "@vitest/browser": "4.0.0-beta.12",
129
+ "@vitest/ui": "4.0.0-beta.12"
130
130
  },
131
131
  "peerDependenciesMeta": {
132
132
  "@edge-runtime/vm": {
@@ -152,57 +152,57 @@
152
152
  }
153
153
  },
154
154
  "dependencies": {
155
- "debug": "^4.4.1",
155
+ "debug": "^4.4.3",
156
156
  "es-module-lexer": "^1.7.0",
157
157
  "expect-type": "^1.2.2",
158
- "magic-string": "^0.30.18",
158
+ "magic-string": "^0.30.19",
159
159
  "pathe": "^2.0.3",
160
160
  "picomatch": "^4.0.3",
161
161
  "std-env": "^3.9.0",
162
162
  "tinybench": "^2.9.0",
163
163
  "tinyexec": "^0.3.2",
164
- "tinyglobby": "^0.2.14",
164
+ "tinyglobby": "^0.2.15",
165
165
  "tinypool": "^2.0.0",
166
- "tinyrainbow": "^2.0.0",
166
+ "tinyrainbow": "^3.0.3",
167
167
  "vite": "^6.0.0 || ^7.0.0-0",
168
168
  "why-is-node-running": "^2.3.0",
169
- "@vitest/expect": "4.0.0-beta.10",
170
- "@vitest/pretty-format": "^4.0.0-beta.10",
171
- "@vitest/runner": "4.0.0-beta.10",
172
- "@vitest/spy": "4.0.0-beta.10",
173
- "@vitest/mocker": "4.0.0-beta.10",
174
- "@vitest/snapshot": "4.0.0-beta.10",
175
- "@vitest/utils": "4.0.0-beta.10"
169
+ "@vitest/expect": "4.0.0-beta.12",
170
+ "@vitest/mocker": "4.0.0-beta.12",
171
+ "@vitest/pretty-format": "4.0.0-beta.12",
172
+ "@vitest/runner": "4.0.0-beta.12",
173
+ "@vitest/snapshot": "4.0.0-beta.12",
174
+ "@vitest/utils": "4.0.0-beta.12",
175
+ "@vitest/spy": "4.0.0-beta.12"
176
176
  },
177
177
  "devDependencies": {
178
178
  "@antfu/install-pkg": "^1.1.0",
179
179
  "@edge-runtime/vm": "^5.0.0",
180
+ "@jridgewell/trace-mapping": "0.3.31",
180
181
  "@sinonjs/fake-timers": "14.0.0",
181
182
  "@types/debug": "^4.1.12",
182
183
  "@types/estree": "^1.0.8",
183
184
  "@types/istanbul-lib-coverage": "^2.0.6",
184
185
  "@types/istanbul-reports": "^3.0.4",
185
186
  "@types/jsdom": "^21.1.7",
186
- "@types/node": "^22.18.0",
187
+ "@types/node": "^22.18.6",
187
188
  "@types/picomatch": "^4.0.2",
188
189
  "@types/prompts": "^2.4.9",
189
190
  "@types/sinonjs__fake-timers": "^8.1.5",
190
191
  "acorn-walk": "^8.3.4",
191
192
  "birpc": "^2.5.0",
192
193
  "cac": "^6.7.14",
193
- "chai-subset": "^1.6.0",
194
- "find-up": "^6.3.0",
194
+ "empathic": "^2.0.0",
195
195
  "flatted": "^3.3.3",
196
196
  "happy-dom": "^18.0.1",
197
197
  "jsdom": "^26.1.0",
198
198
  "local-pkg": "^1.1.2",
199
- "mime": "^4.0.7",
199
+ "mime": "^4.1.0",
200
200
  "prompts": "^2.4.2",
201
201
  "strip-literal": "^3.0.0",
202
202
  "ws": "^8.18.3"
203
203
  },
204
204
  "scripts": {
205
- "build": "rimraf dist && rollup -c",
205
+ "build": "premove dist && rollup -c",
206
206
  "dev": "NODE_OPTIONS=\"--max-old-space-size=8192\" rollup -c --watch -m inline"
207
207
  }
208
208
  }
package/browser.d.ts DELETED
@@ -1 +0,0 @@
1
- export * from './dist/browser.js'
@@ -1,19 +0,0 @@
1
- class VitestTransport {
2
- constructor(options) {
3
- this.options = options;
4
- }
5
- async invoke(event) {
6
- if (event.type !== "custom") return { error: /* @__PURE__ */ new Error(`Vitest Module Runner doesn't support Vite HMR events.`) };
7
- if (event.event !== "vite:invoke") return { error: /* @__PURE__ */ new Error(`Vitest Module Runner doesn't support ${event.event} event.`) };
8
- const { name, data } = event.data;
9
- if (name !== "fetchModule") return { error: /* @__PURE__ */ new Error(`Unknown method: ${name}. Expected "fetchModule".`) };
10
- try {
11
- const result = await this.options.fetchModule(...data);
12
- return { result };
13
- } catch (error) {
14
- return { error };
15
- }
16
- }
17
- }
18
-
19
- export { VitestTransport as V };