vitest 2.0.0-beta.9 → 2.0.1

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 (73) hide show
  1. package/LICENSE.md +1 -22
  2. package/dist/browser.d.ts +24 -7
  3. package/dist/browser.js +5 -19
  4. package/dist/chunks/browser-creator.DSqYDthP.js +673 -0
  5. package/dist/chunks/{environments-node.39w4gmlF.js → environments-node.XE5FbRPQ.js} +1 -1
  6. package/dist/chunks/{integrations-globals.BK0Cn4q1.js → integrations-globals.CzYWb38r.js} +10 -9
  7. package/dist/chunks/{node-git.CCI8evVZ.js → node-git.ZtkbKc8u.js} +14 -15
  8. package/dist/chunks/{runtime-console.DiVMr5d4.js → runtime-console.O41g23Zj.js} +26 -11
  9. package/dist/chunks/{runtime-runBaseTests.C-Bkopka.js → runtime-runBaseTests.DX3h28Mp.js} +47 -34
  10. package/dist/cli.js +3 -3
  11. package/dist/config.cjs +48 -23
  12. package/dist/config.d.ts +2 -1
  13. package/dist/config.js +48 -24
  14. package/dist/coverage.d.ts +6 -4
  15. package/dist/coverage.js +102 -38
  16. package/dist/environments.d.ts +2 -1
  17. package/dist/environments.js +1 -1
  18. package/dist/execute.d.ts +4 -3
  19. package/dist/execute.js +2 -2
  20. package/dist/index.d.ts +1437 -7
  21. package/dist/index.js +10 -9
  22. package/dist/node.d.ts +34 -7
  23. package/dist/node.js +31 -20
  24. package/dist/path.js +4 -1
  25. package/dist/{reporters-DaDey3o0.d.ts → reporters-BU_vXAUX.d.ts} +216 -206
  26. package/dist/reporters.d.ts +2 -1
  27. package/dist/reporters.js +8 -8
  28. package/dist/runners.d.ts +3 -1
  29. package/dist/runners.js +100 -61
  30. package/dist/snapshot.js +2 -2
  31. package/dist/{suite-BHSUxUib.d.ts → suite-BRl_IYuM.d.ts} +1 -1
  32. package/dist/suite.d.ts +3 -2
  33. package/dist/suite.js +3 -3
  34. package/dist/utils.d.ts +1 -5
  35. package/dist/utils.js +1 -6
  36. package/dist/vendor/{base._gnK9Slw.js → base.CTYV4Gnz.js} +24 -17
  37. package/dist/vendor/{base.D4XK-wRp.js → base.CdA1i5tB.js} +6 -4
  38. package/dist/vendor/{benchmark.BNLebNi5.js → benchmark.B6pblCp2.js} +13 -14
  39. package/dist/vendor/{cac.DCg3FnEs.js → cac.BQc6bsef.js} +142 -47
  40. package/dist/vendor/{cli-api.LMvYagQ5.js → cli-api.BGRtK_Kj.js} +4189 -9537
  41. package/dist/vendor/{constants.TCjCaw2D.js → constants.CsnA4eRy.js} +5 -23
  42. package/dist/vendor/{coverage.ChSqD-qS.js → coverage.BhYSDdTT.js} +27 -11
  43. package/dist/vendor/{date.BKM1wewY.js → date.W2xKR2qe.js} +5 -3
  44. package/dist/vendor/env.2ltrQNq0.js +8 -0
  45. package/dist/vendor/{execute.BHj6OMh4.js → execute.Dx503nGn.js} +186 -64
  46. package/dist/vendor/{index.TBU3GqRP.js → index.3x3MdmUV.js} +1075 -526
  47. package/dist/vendor/{index._7XLd8Kd.js → index.BJmtb_7W.js} +3 -2
  48. package/dist/vendor/{index.DP-km6lF.js → index.BMmMjLIQ.js} +64 -51
  49. package/dist/vendor/{index.DHRpy7zp.js → index.CROIsoiT.js} +18 -10
  50. package/dist/vendor/{index.DeR1hhfY.js → index.D4nqnQWz.js} +71 -74
  51. package/dist/vendor/index.D6GZqexG.js +6575 -0
  52. package/dist/vendor/{index.DwR86H5i.js → index.Hqvcg1pf.js} +4 -27
  53. package/dist/vendor/{rpc.DRDE9Pu1.js → rpc.BGx7q_k2.js} +30 -19
  54. package/dist/vendor/run-once.Db8Hgq9X.js +28 -0
  55. package/dist/vendor/{setup-common.BhJvzjns.js → setup-common.yHaxjRhz.js} +30 -15
  56. package/dist/vendor/spy.Cf_4R5Oe.js +22 -0
  57. package/dist/vendor/{tasks.WC7M-K-v.js → tasks.DhVtQBtW.js} +3 -1
  58. package/dist/vendor/{utils.YuQ3LT2a.js → utils.BVMrsl6E.js} +55 -30
  59. package/dist/vendor/{utils.CUjzkRH7.js → utils.DkxLWvS1.js} +12 -5
  60. package/dist/vendor/{vi.C6AfDXK6.js → vi.DXACdGTu.js} +269 -136
  61. package/dist/vendor/{vm.Ow-X2mkS.js → vm.BrDS6p7h.js} +157 -90
  62. package/dist/worker.js +41 -18
  63. package/dist/workers/forks.js +12 -6
  64. package/dist/workers/runVmTests.js +22 -16
  65. package/dist/workers/threads.js +8 -5
  66. package/dist/workers/vmForks.js +15 -9
  67. package/dist/workers/vmThreads.js +11 -8
  68. package/dist/workers.d.ts +8 -5
  69. package/dist/workers.js +11 -11
  70. package/package.json +22 -21
  71. package/suppress-warnings.cjs +2 -4
  72. package/dist/index-B0dCycbN.d.ts +0 -1571
  73. package/dist/vendor/env.bmJgw1qP.js +0 -7
@@ -1,18 +1,18 @@
1
1
  import vm, { isContext } from 'node:vm';
2
2
  import { fileURLToPath, pathToFileURL } from 'node:url';
3
3
  import { dirname, basename, extname, normalize, join, resolve } from 'pathe';
4
- import { createCustomConsole } from '../chunks/runtime-console.DiVMr5d4.js';
5
- import { g as getDefaultRequestStubs, s as startVitestExecutor } from './execute.BHj6OMh4.js';
4
+ import { createCustomConsole } from '../chunks/runtime-console.O41g23Zj.js';
5
+ import { g as getDefaultRequestStubs, s as startVitestExecutor } from './execute.Dx503nGn.js';
6
6
  import { distDir } from '../path.js';
7
7
  import { dirname as dirname$1 } from 'node:path';
8
- import { statSync, existsSync, promises, readFileSync } from 'node:fs';
8
+ import fs from 'node:fs';
9
9
  import { isNodeBuiltin, isPrimitive, toArray, getCachedData, setCacheData } from 'vite-node/utils';
10
10
  import { createRequire, Module } from 'node:module';
11
11
  import { CSS_LANGS_RE, KNOWN_ASSET_RE } from 'vite-node/constants';
12
12
  import '@vitest/runner/utils';
13
13
  import '@vitest/utils';
14
14
  import { p as provideWorkerState } from './global.7bFbnyXl.js';
15
- import './env.bmJgw1qP.js';
15
+ import './env.2ltrQNq0.js';
16
16
 
17
17
  const _require = createRequire(import.meta.url);
18
18
  const requiresCache = /* @__PURE__ */ new WeakMap();
@@ -28,7 +28,10 @@ class CommonjsExecutor {
28
28
  constructor(options) {
29
29
  this.context = options.context;
30
30
  this.fs = options.fileMap;
31
- const primitives = vm.runInContext("({ Object, Array, Error })", this.context);
31
+ const primitives = vm.runInContext(
32
+ "({ Object, Array, Error })",
33
+ this.context
34
+ );
32
35
  const executor = this;
33
36
  this.Module = class Module$1 {
34
37
  exports;
@@ -50,14 +53,17 @@ class CommonjsExecutor {
50
53
  }
51
54
  get require() {
52
55
  const require = requiresCache.get(this);
53
- if (require)
56
+ if (require) {
54
57
  return require;
58
+ }
55
59
  const _require2 = Module$1.createRequire(this.id);
56
60
  requiresCache.set(this, _require2);
57
61
  return _require2;
58
62
  }
59
63
  static register = () => {
60
- throw new Error(`[vitest] "register" is not available when running in Vitest.`);
64
+ throw new Error(
65
+ `[vitest] "register" is not available when running in Vitest.`
66
+ );
61
67
  };
62
68
  _compile(code, filename) {
63
69
  const cjsModule = Module$1.wrap(code);
@@ -131,8 +137,9 @@ class CommonjsExecutor {
131
137
  const require = (id) => {
132
138
  const resolved = _require2.resolve(id);
133
139
  const ext = extname(resolved);
134
- if (ext === ".node" || isNodeBuiltin(resolved))
140
+ if (ext === ".node" || isNodeBuiltin(resolved)) {
135
141
  return this.requireCoreModule(resolved);
142
+ }
136
143
  const module = new this.Module(resolved);
137
144
  return this.loadCommonJSModule(module, resolved);
138
145
  };
@@ -166,8 +173,9 @@ class CommonjsExecutor {
166
173
  // very naive implementation for Node.js require
167
174
  loadCommonJSModule(module, filename) {
168
175
  const cached = this.requireCache.get(filename);
169
- if (cached)
176
+ if (cached) {
170
177
  return cached.exports;
178
+ }
171
179
  const extension = this.findLongestRegisteredExtension(filename);
172
180
  const loader = this.extensions[extension] || this.extensions[".js"];
173
181
  loader(module, filename);
@@ -180,25 +188,29 @@ class CommonjsExecutor {
180
188
  let startIndex = 0;
181
189
  while ((index = name.indexOf(".", startIndex)) !== -1) {
182
190
  startIndex = index + 1;
183
- if (index === 0)
191
+ if (index === 0) {
184
192
  continue;
193
+ }
185
194
  currentExtension = name.slice(index);
186
- if (this.extensions[currentExtension])
195
+ if (this.extensions[currentExtension]) {
187
196
  return currentExtension;
197
+ }
188
198
  }
189
199
  return ".js";
190
200
  }
191
201
  require(identifier) {
192
202
  const ext = extname(identifier);
193
- if (ext === ".node" || isNodeBuiltin(identifier))
203
+ if (ext === ".node" || isNodeBuiltin(identifier)) {
194
204
  return this.requireCoreModule(identifier);
205
+ }
195
206
  const module = new this.Module(identifier);
196
207
  return this.loadCommonJSModule(module, identifier);
197
208
  }
198
209
  requireCoreModule(identifier) {
199
210
  const normalized = identifier.replace(/^node:/, "");
200
- if (this.builtinCache[normalized])
211
+ if (this.builtinCache[normalized]) {
201
212
  return this.builtinCache[normalized].exports;
213
+ }
202
214
  const moduleExports = _require(identifier);
203
215
  if (identifier === "node:module" || identifier === "module") {
204
216
  const module = new this.Module("/module.js");
@@ -268,18 +280,22 @@ class EsmExecutor {
268
280
  if (m.status === "unlinked") {
269
281
  this.esmLinkMap.set(
270
282
  m,
271
- m.link((identifier, referencer) => this.executor.resolveModule(identifier, referencer.identifier))
283
+ m.link(
284
+ (identifier, referencer) => this.executor.resolveModule(identifier, referencer.identifier)
285
+ )
272
286
  );
273
287
  }
274
288
  await this.esmLinkMap.get(m);
275
- if (m.status === "linked")
289
+ if (m.status === "linked") {
276
290
  await m.evaluate();
291
+ }
277
292
  return m;
278
293
  }
279
294
  async createEsModule(fileURL, getCode) {
280
295
  const cached = this.moduleCache.get(fileURL);
281
- if (cached)
296
+ if (cached) {
282
297
  return cached;
298
+ }
283
299
  const promise = this.loadEsModule(fileURL, getCode);
284
300
  this.moduleCache.set(fileURL, promise);
285
301
  return promise;
@@ -287,42 +303,40 @@ class EsmExecutor {
287
303
  async loadEsModule(fileURL, getCode) {
288
304
  const code = await getCode();
289
305
  if (fileURL.endsWith(".json")) {
290
- const m2 = new SyntheticModule$1(
291
- ["default"],
292
- () => {
293
- const result = JSON.parse(code);
294
- m2.setExport("default", result);
295
- }
296
- );
306
+ const m2 = new SyntheticModule$1(["default"], () => {
307
+ const result = JSON.parse(code);
308
+ m2.setExport("default", result);
309
+ });
297
310
  this.moduleCache.set(fileURL, m2);
298
311
  return m2;
299
312
  }
300
- const m = new SourceTextModule(
301
- code,
302
- {
303
- identifier: fileURL,
304
- context: this.context,
305
- importModuleDynamically: this.executor.importModuleDynamically,
306
- initializeImportMeta: (meta, mod) => {
307
- meta.url = mod.identifier;
308
- if (mod.identifier.startsWith("file:")) {
309
- const filename = fileURLToPath(mod.identifier);
310
- meta.filename = filename;
311
- meta.dirname = dirname$1(filename);
312
- }
313
- meta.resolve = (specifier, importer) => {
314
- return this.executor.resolve(specifier, importer != null ? importer.toString() : mod.identifier);
315
- };
313
+ const m = new SourceTextModule(code, {
314
+ identifier: fileURL,
315
+ context: this.context,
316
+ importModuleDynamically: this.executor.importModuleDynamically,
317
+ initializeImportMeta: (meta, mod) => {
318
+ meta.url = mod.identifier;
319
+ if (mod.identifier.startsWith("file:")) {
320
+ const filename = fileURLToPath(mod.identifier);
321
+ meta.filename = filename;
322
+ meta.dirname = dirname$1(filename);
316
323
  }
324
+ meta.resolve = (specifier, importer) => {
325
+ return this.executor.resolve(
326
+ specifier,
327
+ importer != null ? importer.toString() : mod.identifier
328
+ );
329
+ };
317
330
  }
318
- );
331
+ });
319
332
  this.moduleCache.set(fileURL, m);
320
333
  return m;
321
334
  }
322
335
  async createWebAssemblyModule(fileUrl, getCode) {
323
336
  const cached = this.moduleCache.get(fileUrl);
324
- if (cached)
337
+ if (cached) {
325
338
  return cached;
339
+ }
326
340
  const m = this.loadWebAssemblyModule(getCode(), fileUrl);
327
341
  this.moduleCache.set(fileUrl, m);
328
342
  return m;
@@ -341,8 +355,9 @@ class EsmExecutor {
341
355
  }
342
356
  async loadWebAssemblyModule(source, identifier) {
343
357
  const cached = this.moduleCache.get(identifier);
344
- if (cached)
358
+ if (cached) {
345
359
  return cached;
360
+ }
346
361
  const wasmModule = await WebAssembly.compile(source);
347
362
  const exports = WebAssembly.Module.exports(wasmModule);
348
363
  const imports = WebAssembly.Module.imports(wasmModule);
@@ -360,8 +375,9 @@ class EsmExecutor {
360
375
  async () => {
361
376
  const importsObject = {};
362
377
  for (const { module, name } of imports) {
363
- if (!importsObject[module])
378
+ if (!importsObject[module]) {
364
379
  importsObject[module] = {};
380
+ }
365
381
  await this.evaluateModule(moduleLookup[module]);
366
382
  importsObject[module][name] = moduleLookup[module].namespace[name];
367
383
  }
@@ -369,8 +385,9 @@ class EsmExecutor {
369
385
  wasmModule,
370
386
  importsObject
371
387
  );
372
- for (const { name } of exports)
388
+ for (const { name } of exports) {
373
389
  syntheticModule.setExport(name, wasmInstance.exports[name]);
390
+ }
374
391
  },
375
392
  { context: this.context, identifier }
376
393
  );
@@ -384,18 +401,22 @@ class EsmExecutor {
384
401
  }
385
402
  async createDataModule(identifier) {
386
403
  const cached = this.moduleCache.get(identifier);
387
- if (cached)
404
+ if (cached) {
388
405
  return cached;
406
+ }
389
407
  const match = identifier.match(dataURIRegex);
390
- if (!match || !match.groups)
408
+ if (!match || !match.groups) {
391
409
  throw new Error("Invalid data URI");
410
+ }
392
411
  const mime = match.groups.mime;
393
412
  const encoding = match.groups.encoding;
394
413
  if (mime === "application/wasm") {
395
- if (!encoding)
414
+ if (!encoding) {
396
415
  throw new Error("Missing data URI encoding");
397
- if (encoding !== "base64")
416
+ }
417
+ if (encoding !== "base64") {
398
418
  throw new Error(`Invalid data URI encoding: ${encoding}`);
419
+ }
399
420
  const module = this.loadWebAssemblyModule(
400
421
  Buffer.from(match.groups.code, "base64"),
401
422
  identifier
@@ -404,12 +425,13 @@ class EsmExecutor {
404
425
  return module;
405
426
  }
406
427
  let code = match.groups.code;
407
- if (!encoding || encoding === "charset=utf-8")
428
+ if (!encoding || encoding === "charset=utf-8") {
408
429
  code = decodeURIComponent(code);
409
- else if (encoding === "base64")
430
+ } else if (encoding === "base64") {
410
431
  code = Buffer.from(code, "base64").toString();
411
- else
432
+ } else {
412
433
  throw new Error(`Invalid data URI encoding: ${encoding}`);
434
+ }
413
435
  if (mime === "application/json") {
414
436
  const module = new SyntheticModule$1(
415
437
  ["default"],
@@ -428,8 +450,9 @@ class EsmExecutor {
428
450
  _httpIp = new WeakMap();
429
451
  function IPnumber(address) {
430
452
  const ip = address.match(/^(\d+)\.(\d+)\.(\d+)\.(\d+)$/);
431
- if (ip)
453
+ if (ip) {
432
454
  return (+ip[1] << 24) + (+ip[2] << 16) + (+ip[3] << 8) + +ip[4];
455
+ }
433
456
  throw new Error(`Expected IP address, received ${address}`);
434
457
  }
435
458
  function IPmask(maskSize) {
@@ -446,8 +469,9 @@ class ViteExecutor {
446
469
  esm;
447
470
  resolve = (identifier, parent) => {
448
471
  if (identifier === CLIENT_ID) {
449
- if (this.workerState.environment.transformMode === "web")
472
+ if (this.workerState.environment.transformMode === "web") {
450
473
  return identifier;
474
+ }
451
475
  const packageName = this.getPackageName(parent);
452
476
  throw new Error(
453
477
  `[vitest] Vitest cannot handle ${CLIENT_ID} imported in ${parent} when running in SSR environment. Add "${packageName}" to "ssr.noExternal" if you are using Vite SSR, or to "server.deps.inline" if you are using Vite Node.`
@@ -460,30 +484,37 @@ class ViteExecutor {
460
484
  getPackageName(modulePath) {
461
485
  const path = normalize(modulePath);
462
486
  let name = path.split("/node_modules/").pop() || "";
463
- if (name == null ? void 0 : name.startsWith("@"))
487
+ if (name == null ? void 0 : name.startsWith("@")) {
464
488
  name = name.split("/").slice(0, 2).join("/");
465
- else
489
+ } else {
466
490
  name = name.split("/")[0];
491
+ }
467
492
  return name;
468
493
  }
469
494
  async createViteModule(fileUrl) {
470
- if (fileUrl === CLIENT_FILE)
495
+ if (fileUrl === CLIENT_FILE) {
471
496
  return this.createViteClientModule();
497
+ }
472
498
  const cached = this.esm.resolveCachedModule(fileUrl);
473
- if (cached)
499
+ if (cached) {
474
500
  return cached;
501
+ }
475
502
  return this.esm.createEsModule(fileUrl, async () => {
476
503
  const result = await this.options.transform(fileUrl, "web");
477
- if (!result.code)
478
- throw new Error(`[vitest] Failed to transform ${fileUrl}. Does the file exist?`);
504
+ if (!result.code) {
505
+ throw new Error(
506
+ `[vitest] Failed to transform ${fileUrl}. Does the file exist?`
507
+ );
508
+ }
479
509
  return result.code;
480
510
  });
481
511
  }
482
512
  createViteClientModule() {
483
513
  const identifier = CLIENT_ID;
484
514
  const cached = this.esm.resolveCachedModule(identifier);
485
- if (cached)
515
+ if (cached) {
486
516
  return cached;
517
+ }
487
518
  const stub = this.options.viteClientModule;
488
519
  const moduleKeys = Object.keys(stub);
489
520
  const module = new SyntheticModule$1(
@@ -501,18 +532,25 @@ class ViteExecutor {
501
532
  canResolve = (fileUrl) => {
502
533
  var _a;
503
534
  const transformMode = this.workerState.environment.transformMode;
504
- if (transformMode !== "web")
535
+ if (transformMode !== "web") {
505
536
  return false;
506
- if (fileUrl === CLIENT_FILE)
537
+ }
538
+ if (fileUrl === CLIENT_FILE) {
507
539
  return true;
540
+ }
508
541
  const config = ((_a = this.workerState.config.deps) == null ? void 0 : _a.web) || {};
509
542
  const [modulePath] = fileUrl.split("?");
510
- if (config.transformCss && CSS_LANGS_RE.test(modulePath))
543
+ if (config.transformCss && CSS_LANGS_RE.test(modulePath)) {
511
544
  return true;
512
- if (config.transformAssets && KNOWN_ASSET_RE.test(modulePath))
545
+ }
546
+ if (config.transformAssets && KNOWN_ASSET_RE.test(modulePath)) {
513
547
  return true;
514
- if (toArray(config.transformGlobPattern).some((pattern) => pattern.test(modulePath)))
548
+ }
549
+ if (toArray(config.transformGlobPattern).some(
550
+ (pattern) => pattern.test(modulePath)
551
+ )) {
515
552
  return true;
553
+ }
516
554
  return false;
517
555
  };
518
556
  }
@@ -529,6 +567,7 @@ var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot
529
567
  var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), member.set(obj, value), value);
530
568
  var _networkSupported;
531
569
  const SyntheticModule = vm.SyntheticModule;
570
+ const { existsSync, statSync } = fs;
532
571
  const nativeResolve = import.meta.resolve;
533
572
  class ExternalModulesExecutor {
534
573
  constructor(options) {
@@ -547,8 +586,9 @@ class ExternalModulesExecutor {
547
586
  });
548
587
  __publicField(this, "resolveModule", async (specifier, referencer) => {
549
588
  let identifier = this.resolve(specifier, referencer);
550
- if (identifier instanceof Promise)
589
+ if (identifier instanceof Promise) {
551
590
  identifier = await identifier;
591
+ }
552
592
  return await this.createModule(identifier);
553
593
  });
554
594
  this.context = options.context;
@@ -583,8 +623,9 @@ class ExternalModulesExecutor {
583
623
  resolve(specifier, parent) {
584
624
  for (const resolver of this.resolvers) {
585
625
  const id = resolver(specifier, parent);
586
- if (id)
626
+ if (id) {
587
627
  return id;
628
+ }
588
629
  }
589
630
  return nativeResolve(specifier, parent);
590
631
  }
@@ -594,21 +635,24 @@ class ExternalModulesExecutor {
594
635
  const packageCache = this.options.packageCache;
595
636
  while (basedir) {
596
637
  const cached = getCachedData(packageCache, basedir, originalBasedir);
597
- if (cached)
638
+ if (cached) {
598
639
  return cached;
640
+ }
599
641
  const pkgPath = join(basedir, "package.json");
600
642
  try {
601
643
  if ((_a = statSync(pkgPath, { throwIfNoEntry: false })) == null ? void 0 : _a.isFile()) {
602
644
  const pkgData = JSON.parse(this.fs.readFile(pkgPath));
603
- if (packageCache)
645
+ if (packageCache) {
604
646
  setCacheData(packageCache, pkgData, basedir, originalBasedir);
647
+ }
605
648
  return pkgData;
606
649
  }
607
650
  } catch {
608
651
  }
609
652
  const nextBasedir = dirname$1(basedir);
610
- if (nextBasedir === basedir)
653
+ if (nextBasedir === basedir) {
611
654
  break;
655
+ }
612
656
  basedir = nextBasedir;
613
657
  }
614
658
  return {};
@@ -618,8 +662,9 @@ class ExternalModulesExecutor {
618
662
  const m = new SyntheticModule(
619
663
  [...moduleKeys, "default"],
620
664
  () => {
621
- for (const key of moduleKeys)
665
+ for (const key of moduleKeys) {
622
666
  m.setExport(key, exports[key]);
667
+ }
623
668
  m.setExport("default", exports);
624
669
  },
625
670
  {
@@ -630,12 +675,16 @@ class ExternalModulesExecutor {
630
675
  return m;
631
676
  }
632
677
  wrapCommonJsSynteticModule(identifier, exports) {
633
- const { keys, moduleExports, defaultExport } = interopCommonJsModule(this.options.interopDefault, exports);
678
+ const { keys, moduleExports, defaultExport } = interopCommonJsModule(
679
+ this.options.interopDefault,
680
+ exports
681
+ );
634
682
  const m = new SyntheticModule(
635
683
  [...keys, "default"],
636
684
  () => {
637
- for (const key of keys)
685
+ for (const key of keys) {
638
686
  m.setExport(key, moduleExports[key]);
687
+ }
639
688
  m.setExport("default", defaultExport);
640
689
  },
641
690
  {
@@ -646,13 +695,16 @@ class ExternalModulesExecutor {
646
695
  return m;
647
696
  }
648
697
  getModuleInformation(identifier) {
649
- if (identifier.startsWith("data:"))
698
+ if (identifier.startsWith("data:")) {
650
699
  return { type: "data", url: identifier, path: identifier };
700
+ }
651
701
  const extension = extname(identifier);
652
- if (extension === ".node" || isNodeBuiltin(identifier))
702
+ if (extension === ".node" || isNodeBuiltin(identifier)) {
653
703
  return { type: "builtin", url: identifier, path: identifier };
654
- if (this.isNetworkSupported && (identifier.startsWith("http:") || identifier.startsWith("https:")))
704
+ }
705
+ if (this.isNetworkSupported && (identifier.startsWith("http:") || identifier.startsWith("https:"))) {
655
706
  return { type: "network", url: identifier, path: identifier };
707
+ }
656
708
  const isFileUrl = identifier.startsWith("file://");
657
709
  const pathUrl = isFileUrl ? fileURLToPath(identifier.split("?")[0]) : identifier;
658
710
  const fileUrl = isFileUrl ? identifier : pathToFileURL(pathUrl).toString();
@@ -706,41 +758,46 @@ class ExternalModulesExecutor {
706
758
  get isNetworkSupported() {
707
759
  var _a;
708
760
  if (__privateGet(this, _networkSupported) == null) {
709
- if (process.execArgv.includes("--experimental-network-imports"))
761
+ if (process.execArgv.includes("--experimental-network-imports")) {
710
762
  __privateSet(this, _networkSupported, true);
711
- else if ((_a = process.env.NODE_OPTIONS) == null ? void 0 : _a.includes("--experimental-network-imports"))
763
+ } else if ((_a = process.env.NODE_OPTIONS) == null ? void 0 : _a.includes("--experimental-network-imports")) {
712
764
  __privateSet(this, _networkSupported, true);
713
- else
765
+ } else {
714
766
  __privateSet(this, _networkSupported, false);
767
+ }
715
768
  }
716
769
  return __privateGet(this, _networkSupported);
717
770
  }
718
771
  }
719
772
  _networkSupported = new WeakMap();
720
773
 
774
+ const { promises, readFileSync } = fs;
721
775
  class FileMap {
722
776
  fsCache = /* @__PURE__ */ new Map();
723
777
  fsBufferCache = /* @__PURE__ */ new Map();
724
778
  async readFileAsync(path) {
725
779
  const cached = this.fsCache.get(path);
726
- if (cached != null)
780
+ if (cached != null) {
727
781
  return cached;
782
+ }
728
783
  const source = await promises.readFile(path, "utf-8");
729
784
  this.fsCache.set(path, source);
730
785
  return source;
731
786
  }
732
787
  readFile(path) {
733
788
  const cached = this.fsCache.get(path);
734
- if (cached != null)
789
+ if (cached != null) {
735
790
  return cached;
791
+ }
736
792
  const source = readFileSync(path, "utf-8");
737
793
  this.fsCache.set(path, source);
738
794
  return source;
739
795
  }
740
796
  readBuffer(path) {
741
797
  const cached = this.fsBufferCache.get(path);
742
- if (cached != null)
798
+ if (cached != null) {
743
799
  return cached;
800
+ }
744
801
  const buffer = readFileSync(path);
745
802
  this.fsBufferCache.set(path, buffer);
746
803
  return buffer;
@@ -750,7 +807,7 @@ class FileMap {
750
807
  const entryFile = pathToFileURL(resolve(distDir, "workers/runVmTests.js")).href;
751
808
  const fileMap = new FileMap();
752
809
  const packageCache = /* @__PURE__ */ new Map();
753
- async function runVmTests(state) {
810
+ async function runVmTests(method, state) {
754
811
  var _a;
755
812
  const { environment, ctx, rpc } = state;
756
813
  if (!environment.setupVM) {
@@ -760,14 +817,22 @@ async function runVmTests(state) {
760
817
  `Environment "${ctx.environment.name}" is not a valid environment. Path "${packageId}" doesn't support vm environment because it doesn't provide "setupVM" method.`
761
818
  );
762
819
  }
763
- const vm = await environment.setupVM(ctx.environment.options || ctx.config.environmentOptions || {});
820
+ const vm = await environment.setupVM(
821
+ ctx.environment.options || ctx.config.environmentOptions || {}
822
+ );
764
823
  state.durations.environment = performance.now() - state.durations.environment;
765
824
  process.env.VITEST_VM_POOL = "1";
766
- if (!vm.getVmContext)
767
- throw new TypeError(`Environment ${environment.name} doesn't provide "getVmContext" method. It should return a context created by "vm.createContext" method.`);
825
+ if (!vm.getVmContext) {
826
+ throw new TypeError(
827
+ `Environment ${environment.name} doesn't provide "getVmContext" method. It should return a context created by "vm.createContext" method.`
828
+ );
829
+ }
768
830
  const context = vm.getVmContext();
769
- if (!isContext(context))
770
- throw new TypeError(`Environment ${environment.name} doesn't provide a valid context. It should be created by "vm.createContext" method.`);
831
+ if (!isContext(context)) {
832
+ throw new TypeError(
833
+ `Environment ${environment.name} doesn't provide a valid context. It should be created by "vm.createContext" method.`
834
+ );
835
+ }
771
836
  provideWorkerState(context, state);
772
837
  context.process = process;
773
838
  context.global = context;
@@ -791,9 +856,11 @@ async function runVmTests(state) {
791
856
  requestStubs: stubs
792
857
  });
793
858
  context.__vitest_mocker__ = executor.mocker;
794
- const { run } = await executor.importExternalModule(entryFile);
859
+ const { run } = await executor.importExternalModule(
860
+ entryFile
861
+ );
795
862
  try {
796
- await run(ctx.files, ctx.config, executor);
863
+ await run(method, ctx.files, ctx.config, executor);
797
864
  } finally {
798
865
  await ((_a = vm.teardown) == null ? void 0 : _a.call(vm));
799
866
  state.environmentTeardownRun = true;