vitest 4.0.0-beta.5 → 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 (57) hide show
  1. package/LICENSE.md +1 -1
  2. package/dist/browser.d.ts +1 -1
  3. package/dist/browser.js +2 -2
  4. package/dist/chunks/{base.DMfOuRWD.js → base.BXI97p6t.js} +7 -16
  5. package/dist/chunks/{benchmark.CtuRzf-i.js → benchmark.UW6Ezvxy.js} +4 -9
  6. package/dist/chunks/{cac.CKnbxhn2.js → cac.WE-urWw5.js} +37 -113
  7. package/dist/chunks/{cli-api.COn58yrl.js → cli-api.CZz3evYC.js} +505 -1211
  8. package/dist/chunks/{console.Duv2dVIC.js → console.B0quX7yH.js} +32 -68
  9. package/dist/chunks/{coverage.B6cReEn1.js → coverage.BPRS6xgn.js} +210 -579
  10. package/dist/chunks/{creator.DUVZ6rfm.js → creator.KEg6n5IC.js} +28 -74
  11. package/dist/chunks/{date.Bq6ZW5rf.js → date.-jtEtIeV.js} +6 -17
  12. package/dist/chunks/{git.BVQ8w_Sw.js → git.BFNcloKD.js} +1 -2
  13. package/dist/chunks/{globals.CJQ63oO0.js → globals.lgsmH00r.js} +5 -5
  14. package/dist/chunks/{index.DgN0Zk9a.js → index.7w0eqmYM.js} +14 -24
  15. package/dist/chunks/{index.QZr3S3vQ.js → index.AR8aAkCC.js} +2 -2
  16. package/dist/chunks/{index.BRtIe7r8.js → index.BG0gqZH-.js} +39 -102
  17. package/dist/chunks/{index.oWRWx-nj.js → index.CsFXYRkW.js} +17 -36
  18. package/dist/chunks/{index.DQhAfQQU.js → index.VNI-1z5c.js} +270 -606
  19. package/dist/chunks/{inspector.C914Efll.js → inspector.CvQD-Nie.js} +10 -25
  20. package/dist/chunks/{moduleRunner.d.mmOmOGrW.d.ts → moduleRunner.d.8kKUsuDg.d.ts} +1 -1
  21. package/dist/chunks/{node.4JV5OXkt.js → node.BOqcT2jW.js} +1 -1
  22. package/dist/chunks/{plugin.d.CvOlgjxK.d.ts → plugin.d.DuiQJfUL.d.ts} +1 -1
  23. package/dist/chunks/{reporters.d.CYE9sT5z.d.ts → reporters.d.CqR9-CDJ.d.ts} +16 -33
  24. package/dist/chunks/{resolver.D5bG4zy5.js → resolver.Bx6lE0iq.js} +21 -64
  25. package/dist/chunks/{rpc.DGoW_Vl-.js → rpc.RpPylpp0.js} +7 -21
  26. package/dist/chunks/{runBaseTests.B3KcKqlF.js → runBaseTests.D6sfuWBM.js} +25 -54
  27. package/dist/chunks/{setup-common.lgPs-bYv.js → setup-common.hLGRxhC8.js} +9 -22
  28. package/dist/chunks/{startModuleRunner.C8FtT_BY.js → startModuleRunner.C8TW8zTN.js} +83 -205
  29. package/dist/chunks/{typechecker.BgoW4nTA.js → typechecker.Cd1wvxUM.js} +96 -208
  30. package/dist/chunks/{utils.CcGm2cd1.js → utils.C2YI6McM.js} +4 -13
  31. package/dist/chunks/{utils.B9FY3b73.js → utils.C7__0Iv5.js} +5 -14
  32. package/dist/chunks/{vi.DGAfBY4R.js → vi.BfdOiD4j.js} +110 -267
  33. package/dist/chunks/{vm.BKfKvaKl.js → vm.BHBje7cC.js} +73 -177
  34. package/dist/cli.js +3 -3
  35. package/dist/config.d.ts +4 -4
  36. package/dist/coverage.d.ts +1 -1
  37. package/dist/coverage.js +2 -2
  38. package/dist/environments.js +1 -1
  39. package/dist/index.js +5 -5
  40. package/dist/module-evaluator.d.ts +1 -1
  41. package/dist/module-evaluator.js +33 -84
  42. package/dist/module-runner.js +2 -2
  43. package/dist/node.d.ts +3 -3
  44. package/dist/node.js +13 -19
  45. package/dist/reporters.d.ts +2 -2
  46. package/dist/reporters.js +3 -3
  47. package/dist/runners.js +23 -51
  48. package/dist/snapshot.js +2 -2
  49. package/dist/suite.js +2 -2
  50. package/dist/worker.js +18 -34
  51. package/dist/workers/forks.js +4 -4
  52. package/dist/workers/runVmTests.js +19 -37
  53. package/dist/workers/threads.js +4 -4
  54. package/dist/workers/vmForks.js +7 -7
  55. package/dist/workers/vmThreads.js +7 -7
  56. package/dist/workers.js +11 -11
  57. package/package.json +11 -11
@@ -2,15 +2,15 @@ import { fileURLToPath, pathToFileURL } from 'node:url';
2
2
  import vm, { isContext } from 'node:vm';
3
3
  import { dirname, basename, extname, normalize, resolve } from 'pathe';
4
4
  import { distDir } from '../path.js';
5
- import { createCustomConsole } from './console.Duv2dVIC.js';
5
+ import { createCustomConsole } from './console.B0quX7yH.js';
6
6
  import fs from 'node:fs';
7
7
  import { createRequire, Module, isBuiltin } from 'node:module';
8
8
  import { CSS_LANGS_RE, KNOWN_ASSET_RE, toArray, isBareImport } from '@vitest/utils';
9
- import { f as findNearestPackageData } from './resolver.D5bG4zy5.js';
9
+ import { f as findNearestPackageData } from './resolver.Bx6lE0iq.js';
10
10
  import { dirname as dirname$1 } from 'node:path';
11
11
  import { getDefaultRequestStubs } from '../module-evaluator.js';
12
- import { s as startVitestModuleRunner, a as VITEST_VM_CONTEXT_SYMBOL } from './startModuleRunner.C8FtT_BY.js';
13
- import { p as provideWorkerState } from './utils.B9FY3b73.js';
12
+ import { s as startVitestModuleRunner, a as VITEST_VM_CONTEXT_SYMBOL } from './startModuleRunner.C8TW8zTN.js';
13
+ import { p as provideWorkerState } from './utils.C7__0Iv5.js';
14
14
 
15
15
  function interopCommonJsModule(interopDefault, mod) {
16
16
  if (isPrimitive(mod) || Array.isArray(mod) || mod instanceof Promise) return {
@@ -19,11 +19,8 @@ function interopCommonJsModule(interopDefault, mod) {
19
19
  defaultExport: mod
20
20
  };
21
21
  if (interopDefault !== false && "__esModule" in mod && !isPrimitive(mod.default)) {
22
- const defaultKets = Object.keys(mod.default);
23
- const moduleKeys = Object.keys(mod);
24
- const allKeys = new Set([...defaultKets, ...moduleKeys]);
25
- allKeys.delete("default");
26
- return {
22
+ const defaultKets = Object.keys(mod.default), moduleKeys = Object.keys(mod), allKeys = new Set([...defaultKets, ...moduleKeys]);
23
+ return allKeys.delete("default"), {
27
24
  keys: Array.from(allKeys),
28
25
  moduleExports: new Proxy(mod, { get(mod, prop) {
29
26
  return mod[prop] ?? mod.default?.[prop];
@@ -44,8 +41,7 @@ function isPrimitive(obj) {
44
41
  const SyntheticModule = vm.SyntheticModule;
45
42
  const SourceTextModule = vm.SourceTextModule;
46
43
 
47
- const _require = createRequire(import.meta.url);
48
- const requiresCache = /* @__PURE__ */ new WeakMap();
44
+ const _require = createRequire(import.meta.url), requiresCache = /* @__PURE__ */ new WeakMap();
49
45
  class CommonjsExecutor {
50
46
  context;
51
47
  requireCache = /* @__PURE__ */ new Map();
@@ -57,12 +53,8 @@ class CommonjsExecutor {
57
53
  Module;
58
54
  interopDefault;
59
55
  constructor(options) {
60
- this.context = options.context;
61
- this.fs = options.fileMap;
62
- this.interopDefault = options.interopDefault;
63
- const primitives = vm.runInContext("({ Object, Array, Error })", this.context);
64
- // eslint-disable-next-line ts/no-this-alias
65
- const executor = this;
56
+ this.context = options.context, this.fs = options.fileMap, this.interopDefault = options.interopDefault;
57
+ const primitives = vm.runInContext("({ Object, Array, Error })", this.context), executor = this;
66
58
  this.Module = class Module$1 {
67
59
  exports;
68
60
  isPreloading = false;
@@ -74,20 +66,13 @@ class CommonjsExecutor {
74
66
  path;
75
67
  paths = [];
76
68
  constructor(id = "", parent) {
77
- this.exports = primitives.Object.create(Object.prototype);
78
- // in our case the path should always be resolved already
79
- this.path = dirname(id);
80
- this.id = id;
81
- this.filename = id;
82
- this.loaded = false;
83
- this.parent = parent;
69
+ this.exports = primitives.Object.create(Object.prototype), this.path = dirname(id), this.id = id, this.filename = id, this.loaded = false, this.parent = parent;
84
70
  }
85
71
  get require() {
86
72
  const require = requiresCache.get(this);
87
73
  if (require) return require;
88
74
  const _require = Module$1.createRequire(this.id);
89
- requiresCache.set(this, _require);
90
- return _require;
75
+ return requiresCache.set(this, _require), _require;
91
76
  }
92
77
  static getSourceMapsSupport = () => ({
93
78
  enabled: false,
@@ -104,19 +89,16 @@ class CommonjsExecutor {
104
89
  throw new Error(`[vitest] "registerHooks" is not available when running in Vitest.`);
105
90
  };
106
91
  _compile(code, filename) {
107
- const cjsModule = Module$1.wrap(code);
108
- const script = new vm.Script(cjsModule, {
92
+ const cjsModule = Module$1.wrap(code), script = new vm.Script(cjsModule, {
109
93
  filename,
110
94
  importModuleDynamically: options.importModuleDynamically
111
95
  });
112
96
  // @ts-expect-error mark script with current identifier
113
97
  script.identifier = filename;
114
- const fn = script.runInContext(executor.context);
115
- const __dirname = dirname(filename);
98
+ const fn = script.runInContext(executor.context), __dirname = dirname(filename);
116
99
  executor.requireCache.set(filename, this);
117
100
  try {
118
- fn(this.exports, this.require, this, filename, __dirname);
119
- return this.exports;
101
+ return fn(this.exports, this.require, this, filename, __dirname), this.exports;
120
102
  } finally {
121
103
  this.loaded = true;
122
104
  }
@@ -162,9 +144,7 @@ class CommonjsExecutor {
162
144
  static stripTypeScriptTypes = Module.stripTypeScriptTypes;
163
145
  static findPackageJSON = Module.findPackageJSON;
164
146
  static Module = Module$1;
165
- };
166
- this.extensions[".js"] = this.requireJs;
167
- this.extensions[".json"] = this.requireJson;
147
+ }, this.extensions[".js"] = this.requireJs, this.extensions[".json"] = this.requireJson;
168
148
  }
169
149
  requireJs = (m, filename) => {
170
150
  const content = this.fs.readFile(filename);
@@ -175,23 +155,17 @@ class CommonjsExecutor {
175
155
  m.exports = JSON.parse(code);
176
156
  };
177
157
  createRequire = (filename) => {
178
- const _require = createRequire(filename);
179
- const require = (id) => {
180
- const resolved = _require.resolve(id);
181
- const ext = extname(resolved);
158
+ const _require = createRequire(filename), require = ((id) => {
159
+ const resolved = _require.resolve(id), ext = extname(resolved);
182
160
  if (ext === ".node" || isBuiltin(resolved)) return this.requireCoreModule(resolved);
183
161
  const module = new this.Module(resolved);
184
162
  return this.loadCommonJSModule(module, resolved);
185
- };
186
- require.resolve = _require.resolve;
187
- Object.defineProperty(require, "extensions", {
163
+ });
164
+ return require.resolve = _require.resolve, Object.defineProperty(require, "extensions", {
188
165
  get: () => this.extensions,
189
166
  set: () => {},
190
167
  configurable: true
191
- });
192
- require.main = void 0;
193
- require.cache = this.publicRequireCache;
194
- return require;
168
+ }), require.main = void 0, require.cache = this.publicRequireCache, require;
195
169
  };
196
170
  createProxyCache() {
197
171
  return new Proxy(Object.create(null), {
@@ -213,53 +187,40 @@ class CommonjsExecutor {
213
187
  loadCommonJSModule(module, filename) {
214
188
  const cached = this.requireCache.get(filename);
215
189
  if (cached) return cached.exports;
216
- const extension = this.findLongestRegisteredExtension(filename);
217
- const loader = this.extensions[extension] || this.extensions[".js"];
218
- loader(module, filename);
219
- return module.exports;
190
+ const extension = this.findLongestRegisteredExtension(filename), loader = this.extensions[extension] || this.extensions[".js"];
191
+ return loader(module, filename), module.exports;
220
192
  }
221
193
  findLongestRegisteredExtension(filename) {
222
194
  const name = basename(filename);
223
- let currentExtension;
224
- let index;
225
- let startIndex = 0;
195
+ let currentExtension, index, startIndex = 0;
226
196
  // eslint-disable-next-line no-cond-assign
227
197
  while ((index = name.indexOf(".", startIndex)) !== -1) {
228
- startIndex = index + 1;
229
- if (index === 0) continue;
230
- currentExtension = name.slice(index);
231
- if (this.extensions[currentExtension]) return currentExtension;
198
+ if (startIndex = index + 1, index === 0) continue;
199
+ if (currentExtension = name.slice(index), this.extensions[currentExtension]) return currentExtension;
232
200
  }
233
201
  return ".js";
234
202
  }
235
203
  getCoreSyntheticModule(identifier) {
236
204
  if (this.moduleCache.has(identifier)) return this.moduleCache.get(identifier);
237
- const exports = this.require(identifier);
238
- const keys = Object.keys(exports);
239
- const module = new SyntheticModule([...keys, "default"], () => {
205
+ const exports = this.require(identifier), keys = Object.keys(exports), module = new SyntheticModule([...keys, "default"], () => {
240
206
  for (const key of keys) module.setExport(key, exports[key]);
241
207
  module.setExport("default", exports);
242
208
  }, {
243
209
  context: this.context,
244
210
  identifier
245
211
  });
246
- this.moduleCache.set(identifier, module);
247
- return module;
212
+ return this.moduleCache.set(identifier, module), module;
248
213
  }
249
214
  getCjsSyntheticModule(path, identifier) {
250
215
  if (this.moduleCache.has(identifier)) return this.moduleCache.get(identifier);
251
- const exports = this.require(path);
252
- // TODO: technically module should be parsed to find static exports, implement for strict mode in #2854
253
- const { keys, moduleExports, defaultExport } = interopCommonJsModule(this.interopDefault, exports);
254
- const module = new SyntheticModule([...keys, "default"], function() {
216
+ const exports = this.require(path), { keys, moduleExports, defaultExport } = interopCommonJsModule(this.interopDefault, exports), module = new SyntheticModule([...keys, "default"], function() {
255
217
  for (const key of keys) this.setExport(key, moduleExports[key]);
256
218
  this.setExport("default", defaultExport);
257
219
  }, {
258
220
  context: this.context,
259
221
  identifier
260
222
  });
261
- this.moduleCache.set(identifier, module);
262
- return module;
223
+ return this.moduleCache.set(identifier, module), module;
263
224
  }
264
225
  // TODO: use this in strict mode, when available in #2854
265
226
  // private _getNamedCjsExports(path: string): Set<string> {
@@ -309,13 +270,10 @@ class CommonjsExecutor {
309
270
  const moduleExports = _require(identifier);
310
271
  if (identifier === "node:module" || identifier === "module") {
311
272
  const module = new this.Module("/module.js");
312
- module.exports = this.Module;
313
- this.builtinCache[normalized] = module;
314
- return module.exports;
273
+ return module.exports = this.Module, this.builtinCache[normalized] = module, module.exports;
315
274
  }
316
- this.builtinCache[normalized] = _require.cache[normalized];
317
275
  // TODO: should we wrap module to rethrow context errors?
318
- return moduleExports;
276
+ return this.builtinCache[normalized] = _require.cache[normalized], moduleExports;
319
277
  }
320
278
  }
321
279
 
@@ -326,21 +284,18 @@ class EsmExecutor {
326
284
  context;
327
285
  #httpIp = IPnumber("127.0.0.0");
328
286
  constructor(executor, options) {
329
- this.executor = executor;
330
- this.context = options.context;
287
+ this.executor = executor, this.context = options.context;
331
288
  }
332
289
  async evaluateModule(m) {
333
290
  if (m.status === "unlinked") this.esmLinkMap.set(m, m.link((identifier, referencer) => this.executor.resolveModule(identifier, referencer.identifier)));
334
- await this.esmLinkMap.get(m);
335
- if (m.status === "linked") await m.evaluate();
291
+ if (await this.esmLinkMap.get(m), m.status === "linked") await m.evaluate();
336
292
  return m;
337
293
  }
338
294
  async createEsModule(fileURL, getCode) {
339
295
  const cached = this.moduleCache.get(fileURL);
340
296
  if (cached) return cached;
341
297
  const promise = this.loadEsModule(fileURL, getCode);
342
- this.moduleCache.set(fileURL, promise);
343
- return promise;
298
+ return this.moduleCache.set(fileURL, promise), promise;
344
299
  }
345
300
  async loadEsModule(fileURL, getCode) {
346
301
  const code = await getCode();
@@ -350,34 +305,29 @@ class EsmExecutor {
350
305
  const result = JSON.parse(code);
351
306
  this.setExport("default", result);
352
307
  });
353
- this.moduleCache.set(fileURL, m);
354
- return m;
308
+ return this.moduleCache.set(fileURL, m), m;
355
309
  }
356
310
  const m = new SourceTextModule(code, {
357
311
  identifier: fileURL,
358
312
  context: this.context,
359
313
  importModuleDynamically: this.executor.importModuleDynamically,
360
314
  initializeImportMeta: (meta, mod) => {
361
- meta.url = mod.identifier;
362
- if (mod.identifier.startsWith("file:")) {
315
+ if (meta.url = mod.identifier, mod.identifier.startsWith("file:")) {
363
316
  const filename = fileURLToPath(mod.identifier);
364
- meta.filename = filename;
365
- meta.dirname = dirname$1(filename);
317
+ meta.filename = filename, meta.dirname = dirname$1(filename);
366
318
  }
367
319
  meta.resolve = (specifier, importer) => {
368
320
  return this.executor.resolve(specifier, importer != null ? importer.toString() : mod.identifier);
369
321
  };
370
322
  }
371
323
  });
372
- this.moduleCache.set(fileURL, m);
373
- return m;
324
+ return this.moduleCache.set(fileURL, m), m;
374
325
  }
375
326
  async createWebAssemblyModule(fileUrl, getCode) {
376
327
  const cached = this.moduleCache.get(fileUrl);
377
328
  if (cached) return cached;
378
329
  const m = this.loadWebAssemblyModule(getCode(), fileUrl);
379
- this.moduleCache.set(fileUrl, m);
380
- return m;
330
+ return this.moduleCache.set(fileUrl, m), m;
381
331
  }
382
332
  async createNetworkModule(fileUrl) {
383
333
  // https://nodejs.org/api/esm.html#https-and-http-imports
@@ -393,18 +343,13 @@ class EsmExecutor {
393
343
  async loadWebAssemblyModule(source, identifier) {
394
344
  const cached = this.moduleCache.get(identifier);
395
345
  if (cached) return cached;
396
- const wasmModule = await WebAssembly.compile(source);
397
- const exports = WebAssembly.Module.exports(wasmModule);
398
- const imports = WebAssembly.Module.imports(wasmModule);
399
- const moduleLookup = {};
346
+ const wasmModule = await WebAssembly.compile(source), exports = WebAssembly.Module.exports(wasmModule), imports = WebAssembly.Module.imports(wasmModule), moduleLookup = {};
400
347
  for (const { module } of imports) if (moduleLookup[module] === void 0) moduleLookup[module] = await this.executor.resolveModule(module, identifier);
401
- const evaluateModule = (module) => this.evaluateModule(module);
402
- const syntheticModule = new SyntheticModule(exports.map(({ name }) => name), async function() {
348
+ const evaluateModule = (module) => this.evaluateModule(module), syntheticModule = new SyntheticModule(exports.map(({ name }) => name), async function() {
403
349
  const importsObject = {};
404
350
  for (const { module, name } of imports) {
405
351
  if (!importsObject[module]) importsObject[module] = {};
406
- await evaluateModule(moduleLookup[module]);
407
- importsObject[module][name] = moduleLookup[module].namespace[name];
352
+ await evaluateModule(moduleLookup[module]), importsObject[module][name] = moduleLookup[module].namespace[name];
408
353
  }
409
354
  const wasmInstance = new WebAssembly.Instance(wasmModule, importsObject);
410
355
  for (const { name } of exports) this.setExport(name, wasmInstance.exports[name]);
@@ -425,14 +370,12 @@ class EsmExecutor {
425
370
  if (cached) return cached;
426
371
  const match = identifier.match(dataURIRegex);
427
372
  if (!match || !match.groups) throw new Error("Invalid data URI");
428
- const mime = match.groups.mime;
429
- const encoding = match.groups.encoding;
373
+ const mime = match.groups.mime, encoding = match.groups.encoding;
430
374
  if (mime === "application/wasm") {
431
375
  if (!encoding) throw new Error("Missing data URI encoding");
432
376
  if (encoding !== "base64") throw new Error(`Invalid data URI encoding: ${encoding}`);
433
377
  const module = this.loadWebAssemblyModule(Buffer.from(match.groups.code, "base64"), identifier);
434
- this.moduleCache.set(identifier, module);
435
- return module;
378
+ return this.moduleCache.set(identifier, module), module;
436
379
  }
437
380
  let code = match.groups.code;
438
381
  if (!encoding || encoding === "charset=utf-8") code = decodeURIComponent(code);
@@ -446,8 +389,7 @@ class EsmExecutor {
446
389
  context: this.context,
447
390
  identifier
448
391
  });
449
- this.moduleCache.set(identifier, module);
450
- return module;
392
+ return this.moduleCache.set(identifier, module), module;
451
393
  }
452
394
  return this.createEsModule(identifier, () => code);
453
395
  }
@@ -461,13 +403,11 @@ function IPmask(maskSize) {
461
403
  return -1 << 32 - maskSize;
462
404
  }
463
405
 
464
- const CLIENT_ID = "/@vite/client";
465
- const CLIENT_FILE = pathToFileURL(CLIENT_ID).href;
406
+ const CLIENT_ID = "/@vite/client", CLIENT_FILE = pathToFileURL(CLIENT_ID).href;
466
407
  class ViteExecutor {
467
408
  esm;
468
409
  constructor(options) {
469
- this.options = options;
470
- this.esm = options.esmExecutor;
410
+ this.options = options, this.esm = options.esmExecutor;
471
411
  }
472
412
  resolve = (identifier) => {
473
413
  if (identifier === CLIENT_ID) return identifier;
@@ -478,8 +418,7 @@ class ViteExecutor {
478
418
  async createViteModule(fileUrl) {
479
419
  if (fileUrl === CLIENT_FILE || fileUrl === CLIENT_ID) return this.createViteClientModule();
480
420
  const cached = this.esm.resolveCachedModule(fileUrl);
481
- if (cached) return cached;
482
- return this.esm.createEsModule(fileUrl, async () => {
421
+ return cached || this.esm.createEsModule(fileUrl, async () => {
483
422
  try {
484
423
  const result = await this.options.transform(fileUrl);
485
424
  if (result.code) return result.code;
@@ -487,20 +426,16 @@ class ViteExecutor {
487
426
  // rethrow vite error if it cannot load the module because it's not resolved
488
427
  if (typeof cause === "object" && cause.code === "ERR_LOAD_URL" || typeof cause?.message === "string" && cause.message.includes("Failed to load url")) {
489
428
  const error = new Error(`Cannot find module '${fileUrl}'`, { cause });
490
- error.code = "ERR_MODULE_NOT_FOUND";
491
- throw error;
429
+ throw error.code = "ERR_MODULE_NOT_FOUND", error;
492
430
  }
493
431
  }
494
432
  throw new Error(`[vitest] Failed to transform ${fileUrl}. Does the file exist?`);
495
433
  });
496
434
  }
497
435
  createViteClientModule() {
498
- const identifier = CLIENT_ID;
499
- const cached = this.esm.resolveCachedModule(identifier);
436
+ const identifier = CLIENT_ID, cached = this.esm.resolveCachedModule(identifier);
500
437
  if (cached) return cached;
501
- const stub = this.options.viteClientModule;
502
- const moduleKeys = Object.keys(stub);
503
- const module = new SyntheticModule(moduleKeys, function() {
438
+ const stub = this.options.viteClientModule, moduleKeys = Object.keys(stub), module = new SyntheticModule(moduleKeys, function() {
504
439
  moduleKeys.forEach((key) => {
505
440
  this.setExport(key, stub[key]);
506
441
  });
@@ -508,23 +443,16 @@ class ViteExecutor {
508
443
  context: this.options.context,
509
444
  identifier
510
445
  });
511
- this.esm.cacheModule(identifier, module);
512
- return module;
446
+ return this.esm.cacheModule(identifier, module), module;
513
447
  }
514
448
  canResolve = (fileUrl) => {
515
449
  if (fileUrl === CLIENT_FILE) return true;
516
- const config = this.workerState.config.deps?.web || {};
517
- const [modulePath] = fileUrl.split("?");
518
- if (config.transformCss && CSS_LANGS_RE.test(modulePath)) return true;
519
- if (config.transformAssets && KNOWN_ASSET_RE.test(modulePath)) return true;
520
- if (toArray(config.transformGlobPattern).some((pattern) => pattern.test(modulePath))) return true;
521
- return false;
450
+ const config = this.workerState.config.deps?.web || {}, [modulePath] = fileUrl.split("?");
451
+ return !!(config.transformCss && CSS_LANGS_RE.test(modulePath) || config.transformAssets && KNOWN_ASSET_RE.test(modulePath) || toArray(config.transformGlobPattern).some((pattern) => pattern.test(modulePath)));
522
452
  };
523
453
  }
524
454
 
525
- const { existsSync } = fs;
526
- // always defined when we use vm pool
527
- const nativeResolve = import.meta.resolve;
455
+ const { existsSync } = fs, nativeResolve = import.meta.resolve;
528
456
  // TODO: improve Node.js strict mode support in #2854
529
457
  class ExternalModulesExecutor {
530
458
  cjs;
@@ -535,28 +463,21 @@ class ExternalModulesExecutor {
535
463
  resolvers = [];
536
464
  #networkSupported = null;
537
465
  constructor(options) {
538
- this.options = options;
539
- this.context = options.context;
540
- this.fs = options.fileMap;
541
- this.esm = new EsmExecutor(this, { context: this.context });
542
- this.cjs = new CommonjsExecutor({
466
+ this.options = options, this.context = options.context, this.fs = options.fileMap, this.esm = new EsmExecutor(this, { context: this.context }), this.cjs = new CommonjsExecutor({
543
467
  context: this.context,
544
468
  importModuleDynamically: this.importModuleDynamically,
545
469
  fileMap: options.fileMap,
546
470
  interopDefault: options.interopDefault
547
- });
548
- this.vite = new ViteExecutor({
471
+ }), this.vite = new ViteExecutor({
549
472
  esmExecutor: this.esm,
550
473
  context: this.context,
551
474
  transform: options.transform,
552
475
  viteClientModule: options.viteClientModule
553
- });
554
- this.resolvers = [this.vite.resolve];
476
+ }), this.resolvers = [this.vite.resolve];
555
477
  }
556
478
  async import(identifier) {
557
479
  const module = await this.createModule(identifier);
558
- await this.esm.evaluateModule(module);
559
- return module.namespace;
480
+ return await this.esm.evaluateModule(module), module.namespace;
560
481
  }
561
482
  require(identifier) {
562
483
  return this.cjs.require(identifier);
@@ -599,9 +520,7 @@ class ExternalModulesExecutor {
599
520
  url: identifier,
600
521
  path: identifier
601
522
  };
602
- const isFileUrl = identifier.startsWith("file://");
603
- const pathUrl = isFileUrl ? fileURLToPath(identifier.split("?")[0]) : identifier;
604
- const fileUrl = isFileUrl ? identifier : pathToFileURL(pathUrl).toString();
523
+ const isFileUrl = identifier.startsWith("file://"), pathUrl = isFileUrl ? fileURLToPath(identifier.split("?")[0]) : identifier, fileUrl = isFileUrl ? identifier : pathToFileURL(pathUrl).toString();
605
524
  let type;
606
525
  if (this.vite.canResolve(fileUrl)) type = "vite";
607
526
  else if (extension === ".mjs") type = "module";
@@ -626,8 +545,7 @@ class ExternalModulesExecutor {
626
545
  // https://github.com/nodejs/node/pull/49038
627
546
  if ((type === "module" || type === "commonjs" || type === "wasm") && !existsSync(path)) {
628
547
  const error = /* @__PURE__ */ new Error(`Cannot find ${isBareImport(path) ? "package" : "module"} '${path}'`);
629
- error.code = "ERR_MODULE_NOT_FOUND";
630
- throw error;
548
+ throw error.code = "ERR_MODULE_NOT_FOUND", error;
631
549
  }
632
550
  switch (type) {
633
551
  case "data": return this.esm.createDataModule(identifier);
@@ -659,60 +577,41 @@ class FileMap {
659
577
  const cached = this.fsCache.get(path);
660
578
  if (cached != null) return cached;
661
579
  const source = await promises.readFile(path, "utf-8");
662
- this.fsCache.set(path, source);
663
- return source;
580
+ return this.fsCache.set(path, source), source;
664
581
  }
665
582
  readFile(path) {
666
583
  const cached = this.fsCache.get(path);
667
584
  if (cached != null) return cached;
668
585
  const source = readFileSync(path, "utf-8");
669
- this.fsCache.set(path, source);
670
- return source;
586
+ return this.fsCache.set(path, source), source;
671
587
  }
672
588
  readBuffer(path) {
673
589
  const cached = this.fsBufferCache.get(path);
674
590
  if (cached != null) return cached;
675
591
  const buffer = readFileSync(path);
676
- this.fsBufferCache.set(path, buffer);
677
- return buffer;
592
+ return this.fsBufferCache.set(path, buffer), buffer;
678
593
  }
679
594
  }
680
595
 
681
- const entryFile = pathToFileURL(resolve(distDir, "workers/runVmTests.js")).href;
682
- const fileMap = new FileMap();
683
- const packageCache = /* @__PURE__ */ new Map();
596
+ const entryFile = pathToFileURL(resolve(distDir, "workers/runVmTests.js")).href, fileMap = new FileMap(), packageCache = /* @__PURE__ */ new Map();
684
597
  async function runVmTests(method, state) {
685
598
  const { environment, ctx, rpc } = state;
686
599
  if (!environment.setupVM) {
687
- const envName = ctx.environment.name;
688
- const packageId = envName[0] === "." ? envName : `vitest-environment-${envName}`;
600
+ const envName = ctx.environment.name, packageId = envName[0] === "." ? envName : `vitest-environment-${envName}`;
689
601
  throw new TypeError(`Environment "${ctx.environment.name}" is not a valid environment. Path "${packageId}" doesn't support vm environment because it doesn't provide "setupVM" method.`);
690
602
  }
691
603
  const vm = await environment.setupVM(ctx.environment.options || ctx.config.environmentOptions || {});
692
- state.durations.environment = performance.now() - state.durations.environment;
693
- process.env.VITEST_VM_POOL = "1";
694
- if (!vm.getVmContext) throw new TypeError(`Environment ${environment.name} doesn't provide "getVmContext" method. It should return a context created by "vm.createContext" method.`);
604
+ if (state.durations.environment = performance.now() - state.durations.environment, process.env.VITEST_VM_POOL = "1", !vm.getVmContext) throw new TypeError(`Environment ${environment.name} doesn't provide "getVmContext" method. It should return a context created by "vm.createContext" method.`);
695
605
  const context = vm.getVmContext();
696
606
  if (!isContext(context)) throw new TypeError(`Environment ${environment.name} doesn't provide a valid context. It should be created by "vm.createContext" method.`);
697
- provideWorkerState(context, state);
698
- // this is unfortunately needed for our own dependencies
699
- // we need to find a way to not rely on this by default
700
- // because browser doesn't provide these globals
701
- context.process = process;
702
- context.global = context;
703
- context.console = state.config.disableConsoleIntercept ? console : createCustomConsole(state);
704
- // TODO: don't hardcode setImmediate in fake timers defaults
705
- context.setImmediate = setImmediate;
706
- context.clearImmediate = clearImmediate;
707
- const stubs = getDefaultRequestStubs(context);
708
- const externalModulesExecutor = new ExternalModulesExecutor({
607
+ provideWorkerState(context, state), context.process = process, context.global = context, context.console = state.config.disableConsoleIntercept ? console : createCustomConsole(state), context.setImmediate = setImmediate, context.clearImmediate = clearImmediate;
608
+ const stubs = getDefaultRequestStubs(context), externalModulesExecutor = new ExternalModulesExecutor({
709
609
  context,
710
610
  fileMap,
711
611
  packageCache,
712
612
  transform: rpc.transform,
713
613
  viteClientModule: stubs["/@vite/client"]
714
- });
715
- const moduleRunner = await startVitestModuleRunner({
614
+ }), moduleRunner = await startVitestModuleRunner({
716
615
  context,
717
616
  evaluatedModules: state.evaluatedModules,
718
617
  state,
@@ -726,18 +625,15 @@ async function runVmTests(method, state) {
726
625
  configurable: true,
727
626
  enumerable: false,
728
627
  writable: false
729
- });
730
- context.__vitest_mocker__ = moduleRunner.mocker;
731
- const { run } = await moduleRunner.import(entryFile);
732
- const fileSpecs = ctx.files.map((f) => typeof f === "string" ? {
628
+ }), context.__vitest_mocker__ = moduleRunner.mocker;
629
+ const { run } = await moduleRunner.import(entryFile), fileSpecs = ctx.files.map((f) => typeof f === "string" ? {
733
630
  filepath: f,
734
631
  testLocations: void 0
735
632
  } : f);
736
633
  try {
737
634
  await run(method, fileSpecs, ctx.config, moduleRunner);
738
635
  } finally {
739
- await vm.teardown?.();
740
- state.environmentTeardownRun = true;
636
+ await vm.teardown?.(), state.environmentTeardownRun = true;
741
637
  }
742
638
  }
743
639
 
package/dist/cli.js CHANGED
@@ -1,13 +1,13 @@
1
- import { c as createCLI } from './chunks/cac.CKnbxhn2.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
6
  import './chunks/constants.D_Q9UYh-.js';
7
- import './chunks/index.DQhAfQQU.js';
7
+ import './chunks/index.VNI-1z5c.js';
8
8
  import 'node:fs';
9
9
  import 'node:fs/promises';
10
- import './chunks/typechecker.BgoW4nTA.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.d.ts CHANGED
@@ -1,12 +1,12 @@
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.CYE9sT5z.js';
4
- export { a as TestProjectConfiguration, g as TestProjectInlineConfiguration, f as TestUserConfig, W as WatcherTriggerPattern } from './chunks/reporters.d.CYE9sT5z.js';
5
- import { V as VitestPluginContext } from './chunks/plugin.d.CvOlgjxK.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
6
  import { F as FakeTimerInstallOpts } from './chunks/config.d.CKNVOKm0.js';
7
7
  import '@vitest/runner';
8
- import './chunks/environment.d.2fYMoz3o.js';
9
8
  import '@vitest/utils';
9
+ import './chunks/environment.d.2fYMoz3o.js';
10
10
  import 'node:stream';
11
11
  import 'node:console';
12
12
  import './chunks/browser.d.Cawq_X_N.js';
@@ -1,4 +1,4 @@
1
- import { R as ResolvedCoverageOptions, V as Vitest, C as CoverageMap, b as ReportContext } from './chunks/reporters.d.CYE9sT5z.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
3
  import { A as AfterSuiteRunMeta } from './chunks/environment.d.2fYMoz3o.js';
4
4
  import '@vitest/runner';
package/dist/coverage.js CHANGED
@@ -1,4 +1,4 @@
1
- export { B as BaseCoverageProvider } from './chunks/coverage.B6cReEn1.js';
1
+ export { B as BaseCoverageProvider } from './chunks/coverage.BPRS6xgn.js';
2
2
  import 'node:fs';
3
3
  import 'node:path';
4
4
  import '@vitest/utils';
@@ -24,7 +24,7 @@ import 'node:tty';
24
24
  import 'node:events';
25
25
  import './chunks/index.Bgo3tNWt.js';
26
26
  import 'tinypool';
27
- import './chunks/typechecker.BgoW4nTA.js';
27
+ import './chunks/typechecker.Cd1wvxUM.js';
28
28
  import 'node:perf_hooks';
29
29
  import '@vitest/utils/source-map';
30
30
  import 'tinyexec';
@@ -1,2 +1,2 @@
1
- export { e as builtinEnvironments, p as populateGlobal } from './chunks/index.BRtIe7r8.js';
1
+ export { e as builtinEnvironments, p as populateGlobal } from './chunks/index.BG0gqZH-.js';
2
2
  import 'node:console';
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
- export { c as createExpect, a as expect, i as inject, v as vi, b as vitest } from './chunks/vi.DGAfBY4R.js';
2
- export { b as bench } from './chunks/benchmark.CtuRzf-i.js';
3
- export { a as assertType } from './chunks/index.QZr3S3vQ.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
6
  export { EvaluatedModules } from 'vite/module-runner';
@@ -9,11 +9,11 @@ export { chai };
9
9
  export { assert, should } from 'chai';
10
10
  import '@vitest/expect';
11
11
  import '@vitest/runner/utils';
12
- import './chunks/utils.B9FY3b73.js';
12
+ import './chunks/utils.C7__0Iv5.js';
13
13
  import '@vitest/utils';
14
14
  import './chunks/_commonjsHelpers.BFTU3MAI.js';
15
15
  import '@vitest/snapshot';
16
16
  import '@vitest/utils/error';
17
17
  import '@vitest/spy';
18
18
  import '@vitest/utils/source-map';
19
- import './chunks/date.Bq6ZW5rf.js';
19
+ import './chunks/date.-jtEtIeV.js';
@@ -1,5 +1,5 @@
1
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.mmOmOGrW.js';
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
3
  import 'node:vm';
4
4
  import './chunks/worker.d.D9QWnzAe.js';
5
5
  import '@vitest/runner';