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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (78) hide show
  1. package/LICENSE.md +1 -1
  2. package/dist/browser.d.ts +8 -9
  3. package/dist/browser.js +3 -2
  4. package/dist/chunks/base.BXI97p6t.js +39 -0
  5. package/dist/chunks/{benchmark.CYdenmiT.js → benchmark.UW6Ezvxy.js} +6 -8
  6. package/dist/chunks/{browser.d.BRP8scJf.d.ts → browser.d.Cawq_X_N.d.ts} +1 -1
  7. package/dist/chunks/{cac.CY0IAxC4.js → cac.WE-urWw5.js} +38 -115
  8. package/dist/chunks/{cli-api.B8xRY9Zt.js → cli-api.CZz3evYC.js} +931 -1439
  9. package/dist/chunks/{config.d.DZo8c7fw.d.ts → config.d.CKNVOKm0.d.ts} +3 -8
  10. package/dist/chunks/{console.DoJHFxmj.js → console.B0quX7yH.js} +32 -68
  11. package/dist/chunks/{constants.CXzqaLmq.js → constants.D_Q9UYh-.js} +1 -6
  12. package/dist/chunks/{coverage.C84l9G-M.js → coverage.BPRS6xgn.js} +395 -665
  13. package/dist/chunks/{coverage.DVF1vEu8.js → coverage.D_JHT54q.js} +2 -2
  14. package/dist/chunks/{coverage.d.CNYjU4GF.d.ts → coverage.d.BZtK59WP.d.ts} +7 -5
  15. package/dist/chunks/{creator.yfA2ExGt.js → creator.KEg6n5IC.js} +29 -75
  16. package/dist/chunks/{date.Bq6ZW5rf.js → date.-jtEtIeV.js} +6 -17
  17. package/dist/chunks/{environment.d.Bhm9oc0v.d.ts → environment.d.2fYMoz3o.d.ts} +26 -4
  18. package/dist/chunks/{git.BVQ8w_Sw.js → git.BFNcloKD.js} +1 -2
  19. package/dist/chunks/{global.d.DAhT2emn.d.ts → global.d.K6uBQHzY.d.ts} +1 -1
  20. package/dist/chunks/{globals.Dgo-vS5G.js → globals.lgsmH00r.js} +7 -6
  21. package/dist/chunks/{index.D3SKT3tv.js → index.7w0eqmYM.js} +14 -24
  22. package/dist/chunks/{index.D1_MsKEt.js → index.AR8aAkCC.js} +4 -2
  23. package/dist/chunks/{index.CmSc2RE5.js → index.BG0gqZH-.js} +43 -106
  24. package/dist/chunks/{index.CtUvr1c8.js → index.CsFXYRkW.js} +27 -46
  25. package/dist/chunks/{index.Bz6b0Ib7.js → index.VNI-1z5c.js} +276 -604
  26. package/dist/chunks/{inspector.C914Efll.js → inspector.CvQD-Nie.js} +10 -25
  27. package/dist/chunks/moduleRunner.d.8kKUsuDg.d.ts +202 -0
  28. package/dist/chunks/moduleTransport.I-bgQy0S.js +19 -0
  29. package/dist/chunks/{node.fjCdwEIl.js → node.BOqcT2jW.js} +1 -1
  30. package/dist/chunks/{plugin.d.CLhMcYdD.d.ts → plugin.d.DuiQJfUL.d.ts} +1 -1
  31. package/dist/chunks/{reporters.d.DWg40D2B.d.ts → reporters.d.CqR9-CDJ.d.ts} +52 -101
  32. package/dist/chunks/resolver.Bx6lE0iq.js +119 -0
  33. package/dist/chunks/{rpc.jnQO9F8a.js → rpc.RpPylpp0.js} +7 -21
  34. package/dist/chunks/runBaseTests.D6sfuWBM.js +99 -0
  35. package/dist/chunks/{setup-common.Ebx5x0eP.js → setup-common.hLGRxhC8.js} +15 -27
  36. package/dist/chunks/startModuleRunner.C8TW8zTN.js +655 -0
  37. package/dist/chunks/{typechecker.CMNPqJOo.js → typechecker.Cd1wvxUM.js} +97 -209
  38. package/dist/chunks/{utils.CcGm2cd1.js → utils.C2YI6McM.js} +4 -13
  39. package/dist/chunks/{utils.XdZDrNZV.js → utils.C7__0Iv5.js} +7 -17
  40. package/dist/chunks/{vi.CA0EPI9Y.js → vi.BfdOiD4j.js} +116 -269
  41. package/dist/chunks/{vm.BUnLJt_P.js → vm.BHBje7cC.js} +101 -225
  42. package/dist/chunks/{worker.d.zjyR34Pb.d.ts → worker.d.D9QWnzAe.d.ts} +16 -13
  43. package/dist/chunks/{worker.d.C-1AbnVe.d.ts → worker.d.Db-UVmXc.d.ts} +1 -1
  44. package/dist/cli.js +4 -4
  45. package/dist/config.cjs +3 -9
  46. package/dist/config.d.ts +10 -12
  47. package/dist/config.js +1 -1
  48. package/dist/coverage.d.ts +10 -11
  49. package/dist/coverage.js +5 -6
  50. package/dist/environments.d.ts +2 -2
  51. package/dist/environments.js +1 -1
  52. package/dist/index.d.ts +10 -9
  53. package/dist/index.js +6 -5
  54. package/dist/module-evaluator.d.ts +12 -0
  55. package/dist/module-evaluator.js +276 -0
  56. package/dist/module-runner.js +15 -0
  57. package/dist/node.d.ts +12 -13
  58. package/dist/node.js +19 -24
  59. package/dist/reporters.d.ts +7 -8
  60. package/dist/reporters.js +3 -3
  61. package/dist/runners.d.ts +3 -3
  62. package/dist/runners.js +35 -57
  63. package/dist/snapshot.js +2 -2
  64. package/dist/suite.js +2 -2
  65. package/dist/worker.js +82 -45
  66. package/dist/workers/forks.js +11 -10
  67. package/dist/workers/runVmTests.js +27 -46
  68. package/dist/workers/threads.js +11 -10
  69. package/dist/workers/vmForks.js +11 -10
  70. package/dist/workers/vmThreads.js +11 -10
  71. package/dist/workers.d.ts +5 -4
  72. package/dist/workers.js +17 -16
  73. package/package.json +22 -17
  74. package/dist/chunks/base.BaCDDRPG.js +0 -38
  75. package/dist/chunks/execute.Dt-pCVcL.js +0 -708
  76. package/dist/chunks/runBaseTests.DBVVLMSb.js +0 -129
  77. package/dist/execute.d.ts +0 -148
  78. package/dist/execute.js +0 -13
@@ -0,0 +1,119 @@
1
+ import fs from 'node:fs';
2
+
3
+ const _DRIVE_LETTER_START_RE = /^[A-Za-z]:\//;
4
+ function normalizeWindowsPath(input = "") {
5
+ return input && input.replace(/\\/g, "/").replace(_DRIVE_LETTER_START_RE, (r) => r.toUpperCase());
6
+ }
7
+ const _UNC_REGEX = /^[/\\]{2}/, _IS_ABSOLUTE_RE = /^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Za-z]:[/\\]/, _DRIVE_LETTER_RE = /^[A-Za-z]:$/, normalize = function(path) {
8
+ if (path.length === 0) return ".";
9
+ path = normalizeWindowsPath(path);
10
+ const isUNCPath = path.match(_UNC_REGEX), isPathAbsolute = isAbsolute(path), trailingSeparator = path[path.length - 1] === "/";
11
+ if (path = normalizeString(path, !isPathAbsolute), path.length === 0) return isPathAbsolute ? "/" : trailingSeparator ? "./" : ".";
12
+ if (trailingSeparator) path += "/";
13
+ if (_DRIVE_LETTER_RE.test(path)) path += "/";
14
+ return isUNCPath ? isPathAbsolute ? `//${path}` : `//./${path}` : isPathAbsolute && !isAbsolute(path) ? `/${path}` : path;
15
+ }, join = function(...segments) {
16
+ let path = "";
17
+ for (const seg of segments) {
18
+ if (!seg) continue;
19
+ if (path.length > 0) {
20
+ const pathTrailing = path[path.length - 1] === "/", segLeading = seg[0] === "/", both = pathTrailing && segLeading;
21
+ if (both) path += seg.slice(1);
22
+ else path += pathTrailing || segLeading ? seg : `/${seg}`;
23
+ } else path += seg;
24
+ }
25
+ return normalize(path);
26
+ };
27
+ function normalizeString(path, allowAboveRoot) {
28
+ let res = "", lastSegmentLength = 0, lastSlash = -1, dots = 0, char = null;
29
+ for (let index = 0; index <= path.length; ++index) {
30
+ if (index < path.length) char = path[index];
31
+ else if (char === "/") break;
32
+ else char = "/";
33
+ if (char === "/") {
34
+ if (lastSlash === index - 1 || dots === 1);
35
+ else if (dots === 2) {
36
+ if (res.length < 2 || lastSegmentLength !== 2 || res[res.length - 1] !== "." || res[res.length - 2] !== ".") {
37
+ if (res.length > 2) {
38
+ const lastSlashIndex = res.lastIndexOf("/");
39
+ if (lastSlashIndex === -1) res = "", lastSegmentLength = 0;
40
+ else res = res.slice(0, lastSlashIndex), lastSegmentLength = res.length - 1 - res.lastIndexOf("/");
41
+ lastSlash = index, dots = 0;
42
+ continue;
43
+ } else if (res.length > 0) {
44
+ res = "", lastSegmentLength = 0, lastSlash = index, dots = 0;
45
+ continue;
46
+ }
47
+ }
48
+ if (allowAboveRoot) res += res.length > 0 ? "/.." : "..", lastSegmentLength = 2;
49
+ } else {
50
+ if (res.length > 0) res += `/${path.slice(lastSlash + 1, index)}`;
51
+ else res = path.slice(lastSlash + 1, index);
52
+ lastSegmentLength = index - lastSlash - 1;
53
+ }
54
+ lastSlash = index, dots = 0;
55
+ } else if (char === "." && dots !== -1) ++dots;
56
+ else dots = -1;
57
+ }
58
+ return res;
59
+ }
60
+ const isAbsolute = function(p) {
61
+ return _IS_ABSOLUTE_RE.test(p);
62
+ }, dirname = function(p) {
63
+ const segments = normalizeWindowsPath(p).replace(/\/$/, "").split("/").slice(0, -1);
64
+ if (segments.length === 1 && _DRIVE_LETTER_RE.test(segments[0])) segments[0] += "/";
65
+ return segments.join("/") || (isAbsolute(p) ? "/" : ".");
66
+ };
67
+
68
+ const packageCache = /* @__PURE__ */ new Map();
69
+ function findNearestPackageData(basedir) {
70
+ const originalBasedir = basedir;
71
+ while (basedir) {
72
+ var _tryStatSync;
73
+ const cached = getCachedData(packageCache, basedir, originalBasedir);
74
+ if (cached) return cached;
75
+ const pkgPath = join(basedir, "package.json");
76
+ if ((_tryStatSync = tryStatSync(pkgPath)) === null || _tryStatSync === void 0 ? void 0 : _tryStatSync.isFile()) {
77
+ const pkgData = JSON.parse(stripBomTag(fs.readFileSync(pkgPath, "utf8")));
78
+ if (packageCache) setCacheData(packageCache, pkgData, basedir, originalBasedir);
79
+ return pkgData;
80
+ }
81
+ const nextBasedir = dirname(basedir);
82
+ if (nextBasedir === basedir) break;
83
+ basedir = nextBasedir;
84
+ }
85
+ return {};
86
+ }
87
+ function stripBomTag(content) {
88
+ return content.charCodeAt(0) === 65279 ? content.slice(1) : content;
89
+ }
90
+ function tryStatSync(file) {
91
+ try {
92
+ // The "throwIfNoEntry" is a performance optimization for cases where the file does not exist
93
+ return fs.statSync(file, { throwIfNoEntry: false });
94
+ } catch {}
95
+ }
96
+ function getCachedData(cache, basedir, originalBasedir) {
97
+ const pkgData = cache.get(getFnpdCacheKey(basedir));
98
+ if (pkgData) return traverseBetweenDirs(originalBasedir, basedir, (dir) => {
99
+ cache.set(getFnpdCacheKey(dir), pkgData);
100
+ }), pkgData;
101
+ }
102
+ function setCacheData(cache, data, basedir, originalBasedir) {
103
+ cache.set(getFnpdCacheKey(basedir), data), traverseBetweenDirs(originalBasedir, basedir, (dir) => {
104
+ cache.set(getFnpdCacheKey(dir), data);
105
+ });
106
+ }
107
+ function getFnpdCacheKey(basedir) {
108
+ return `fnpd_${basedir}`;
109
+ }
110
+ /**
111
+ * Traverse between `longerDir` (inclusive) and `shorterDir` (exclusive) and call `cb` for each dir.
112
+ * @param longerDir Longer dir path, e.g. `/User/foo/bar/baz`
113
+ * @param shorterDir Shorter dir path, e.g. `/User/foo`
114
+ */
115
+ function traverseBetweenDirs(longerDir, shorterDir, cb) {
116
+ while (longerDir !== shorterDir) cb(longerDir), longerDir = dirname(longerDir);
117
+ }
118
+
119
+ export { findNearestPackageData as f };
@@ -1,29 +1,18 @@
1
1
  import { getSafeTimers } from '@vitest/utils';
2
2
  import { c as createBirpc } from './index.Bgo3tNWt.js';
3
- import { g as getWorkerState } from './utils.XdZDrNZV.js';
3
+ import { g as getWorkerState } from './utils.C7__0Iv5.js';
4
4
 
5
5
  const { get } = Reflect;
6
6
  function withSafeTimers(fn) {
7
- const { setTimeout, clearTimeout, nextTick, setImmediate, clearImmediate } = getSafeTimers();
8
- const currentSetTimeout = globalThis.setTimeout;
9
- const currentClearTimeout = globalThis.clearTimeout;
10
- const currentSetImmediate = globalThis.setImmediate;
11
- const currentClearImmediate = globalThis.clearImmediate;
12
- const currentNextTick = globalThis.process?.nextTick;
7
+ const { setTimeout, clearTimeout, nextTick, setImmediate, clearImmediate } = getSafeTimers(), currentSetTimeout = globalThis.setTimeout, currentClearTimeout = globalThis.clearTimeout, currentSetImmediate = globalThis.setImmediate, currentClearImmediate = globalThis.clearImmediate, currentNextTick = globalThis.process?.nextTick;
13
8
  try {
14
- globalThis.setTimeout = setTimeout;
15
- globalThis.clearTimeout = clearTimeout;
16
- if (setImmediate) globalThis.setImmediate = setImmediate;
9
+ if (globalThis.setTimeout = setTimeout, globalThis.clearTimeout = clearTimeout, setImmediate) globalThis.setImmediate = setImmediate;
17
10
  if (clearImmediate) globalThis.clearImmediate = clearImmediate;
18
11
  if (globalThis.process && nextTick) globalThis.process.nextTick = nextTick;
19
12
  const result = fn();
20
13
  return result;
21
14
  } finally {
22
- globalThis.setTimeout = currentSetTimeout;
23
- globalThis.clearTimeout = currentClearTimeout;
24
- globalThis.setImmediate = currentSetImmediate;
25
- globalThis.clearImmediate = currentClearImmediate;
26
- if (globalThis.process && nextTick) nextTick(() => {
15
+ if (globalThis.setTimeout = currentSetTimeout, globalThis.clearTimeout = currentClearTimeout, globalThis.setImmediate = currentSetImmediate, globalThis.clearImmediate = currentClearImmediate, globalThis.process && nextTick) nextTick(() => {
27
16
  globalThis.process.nextTick = currentNextTick;
28
17
  });
29
18
  }
@@ -38,8 +27,7 @@ function createRuntimeRpc(options) {
38
27
  let setCancel = (_reason) => {};
39
28
  const onCancel = new Promise((resolve) => {
40
29
  setCancel = resolve;
41
- });
42
- const rpc = createSafeRpc(createBirpc({ onCancel: setCancel }, {
30
+ }), rpc = createSafeRpc(createBirpc({ onCancel: setCancel }, {
43
31
  eventNames: [
44
32
  "onUserConsoleLog",
45
33
  "onCollected",
@@ -57,8 +45,7 @@ function createSafeRpc(rpc) {
57
45
  return new Proxy(rpc, { get(target, p, handler) {
58
46
  // keep $rejectPendingCalls as sync function
59
47
  if (p === "$rejectPendingCalls") return rpc.$rejectPendingCalls;
60
- const sendCall = get(target, p, handler);
61
- const safeSendCall = (...args) => withSafeTimers(async () => {
48
+ const sendCall = get(target, p, handler), safeSendCall = (...args) => withSafeTimers(async () => {
62
49
  const result = sendCall(...args);
63
50
  promises.add(result);
64
51
  try {
@@ -67,8 +54,7 @@ function createSafeRpc(rpc) {
67
54
  promises.delete(result);
68
55
  }
69
56
  });
70
- safeSendCall.asEvent = sendCall.asEvent;
71
- return safeSendCall;
57
+ return safeSendCall.asEvent = sendCall.asEvent, safeSendCall;
72
58
  } });
73
59
  }
74
60
  function rpc() {
@@ -0,0 +1,99 @@
1
+ import { performance } from 'node:perf_hooks';
2
+ import { startTests, collectTests } from '@vitest/runner';
3
+ import { a as resolveSnapshotEnvironment, s as setupChaiConfig, r as resolveTestRunner } from './index.CsFXYRkW.js';
4
+ import { c as setupCommonEnv, s as startCoverageInsideWorker, a as stopCoverageInsideWorker } from './setup-common.hLGRxhC8.js';
5
+ import { a as globalExpect, v as vi } from './vi.BfdOiD4j.js';
6
+ import { c as closeInspector } from './inspector.CvQD-Nie.js';
7
+ import { createRequire } from 'node:module';
8
+ import timers from 'node:timers';
9
+ import timersPromises from 'node:timers/promises';
10
+ import util from 'node:util';
11
+ import { KNOWN_ASSET_TYPES, getSafeTimers } from '@vitest/utils';
12
+ import { V as VitestIndex } from './index.AR8aAkCC.js';
13
+ import { g as getWorkerState, r as resetModules } from './utils.C7__0Iv5.js';
14
+ import 'chai';
15
+ import 'node:path';
16
+ import '../path.js';
17
+ import 'node:url';
18
+ import './rpc.RpPylpp0.js';
19
+ import './index.Bgo3tNWt.js';
20
+ import './coverage.D_JHT54q.js';
21
+ import '@vitest/snapshot';
22
+ import '@vitest/expect';
23
+ import '@vitest/runner/utils';
24
+ import './_commonjsHelpers.BFTU3MAI.js';
25
+ import '@vitest/utils/error';
26
+ import '@vitest/spy';
27
+ import '@vitest/utils/source-map';
28
+ import './date.-jtEtIeV.js';
29
+ import './benchmark.UW6Ezvxy.js';
30
+ import 'expect-type';
31
+ import 'vite/module-runner';
32
+
33
+ // this should only be used in Node
34
+ let globalSetup = false;
35
+ async function setupGlobalEnv(config, { environment }, moduleRunner) {
36
+ await setupCommonEnv(config), Object.defineProperty(globalThis, "__vitest_index__", {
37
+ value: VitestIndex,
38
+ enumerable: false
39
+ });
40
+ const state = getWorkerState();
41
+ if (!state.config.snapshotOptions.snapshotEnvironment) state.config.snapshotOptions.snapshotEnvironment = await resolveSnapshotEnvironment(config, moduleRunner);
42
+ if (globalSetup) return;
43
+ globalSetup = true;
44
+ const viteEnvironment = environment.viteEnvironment || environment.name;
45
+ if (viteEnvironment === "client") {
46
+ const _require = createRequire(import.meta.url);
47
+ _require.extensions[".css"] = resolveCss, _require.extensions[".scss"] = resolveCss, _require.extensions[".sass"] = resolveCss, _require.extensions[".less"] = resolveCss, KNOWN_ASSET_TYPES.forEach((type) => {
48
+ _require.extensions[`.${type}`] = resolveAsset;
49
+ }), process.env.SSR = "";
50
+ } else process.env.SSR = "1";
51
+ if (globalThis.__vitest_required__ = {
52
+ util,
53
+ timers,
54
+ timersPromises
55
+ }, !config.disableConsoleIntercept) await setupConsoleLogSpy();
56
+ }
57
+ function resolveCss(mod) {
58
+ mod.exports = "";
59
+ }
60
+ function resolveAsset(mod, url) {
61
+ mod.exports = url;
62
+ }
63
+ async function setupConsoleLogSpy() {
64
+ const { createCustomConsole } = await import('./console.B0quX7yH.js');
65
+ globalThis.console = createCustomConsole();
66
+ }
67
+ async function withEnv({ environment }, options, fn) {
68
+ globalThis.__vitest_environment__ = environment.name, globalExpect.setState({ environment: environment.name });
69
+ const env = await environment.setup(globalThis, options);
70
+ try {
71
+ await fn();
72
+ } finally {
73
+ // Run possible setTimeouts, e.g. the onces used by ConsoleLogSpy
74
+ const { setTimeout } = getSafeTimers();
75
+ await new Promise((resolve) => setTimeout(resolve)), await env.teardown(globalThis);
76
+ }
77
+ }
78
+
79
+ // browser shouldn't call this!
80
+ async function run(method, files, config, environment, moduleRunner) {
81
+ const workerState = getWorkerState(), isIsolatedThreads = config.pool === "threads" && (config.poolOptions?.threads?.isolate ?? true), isIsolatedForks = config.pool === "forks" && (config.poolOptions?.forks?.isolate ?? true), isolate = isIsolatedThreads || isIsolatedForks;
82
+ if (await setupGlobalEnv(config, environment, moduleRunner), await startCoverageInsideWorker(config.coverage, moduleRunner, { isolate }), config.chaiConfig) setupChaiConfig(config.chaiConfig);
83
+ const runner = await resolveTestRunner(config, moduleRunner);
84
+ workerState.onCancel.then((reason) => {
85
+ closeInspector(config), runner.cancel?.(reason);
86
+ }), workerState.durations.prepare = performance.now() - workerState.durations.prepare, workerState.durations.environment = performance.now(), await withEnv(environment, environment.options || config.environmentOptions || {}, async () => {
87
+ workerState.durations.environment = performance.now() - workerState.durations.environment;
88
+ for (const file of files) {
89
+ if (isolate) moduleRunner.mocker.reset(), resetModules(workerState.evaluatedModules, true);
90
+ if (workerState.filepath = file.filepath, method === "run") await startTests([file], runner);
91
+ else await collectTests([file], runner);
92
+ // mocks should not affect different files
93
+ vi.resetConfig(), vi.restoreAllMocks();
94
+ }
95
+ await stopCoverageInsideWorker(config.coverage, moduleRunner, { isolate });
96
+ }), workerState.environmentTeardownRun = true;
97
+ }
98
+
99
+ export { run };
@@ -1,54 +1,42 @@
1
- import { r as resolveCoverageProviderModule } from './coverage.DVF1vEu8.js';
1
+ import { r as resolveCoverageProviderModule } from './coverage.D_JHT54q.js';
2
2
  import { addSerializer } from '@vitest/snapshot';
3
3
  import { setSafeTimers } from '@vitest/utils';
4
+ import { g as getWorkerState } from './utils.C7__0Iv5.js';
4
5
 
5
6
  async function startCoverageInsideWorker(options, loader, runtimeOptions) {
6
7
  const coverageModule = await resolveCoverageProviderModule(options, loader);
7
- if (coverageModule) return coverageModule.startCoverage?.(runtimeOptions);
8
- return null;
8
+ return coverageModule ? coverageModule.startCoverage?.(runtimeOptions) : null;
9
9
  }
10
10
  async function takeCoverageInsideWorker(options, loader) {
11
11
  const coverageModule = await resolveCoverageProviderModule(options, loader);
12
- if (coverageModule) return coverageModule.takeCoverage?.({ moduleExecutionInfo: loader.moduleExecutionInfo });
13
- return null;
12
+ return coverageModule ? coverageModule.takeCoverage?.({ moduleExecutionInfo: loader.moduleExecutionInfo }) : null;
14
13
  }
15
14
  async function stopCoverageInsideWorker(options, loader, runtimeOptions) {
16
15
  const coverageModule = await resolveCoverageProviderModule(options, loader);
17
- if (coverageModule) return coverageModule.stopCoverage?.(runtimeOptions);
18
- return null;
16
+ return coverageModule ? coverageModule.stopCoverage?.(runtimeOptions) : null;
19
17
  }
20
18
 
21
19
  let globalSetup = false;
22
20
  async function setupCommonEnv(config) {
23
- setupDefines(config.defines);
24
- setupEnv(config.env);
25
- if (globalSetup) return;
26
- globalSetup = true;
27
- setSafeTimers();
28
- if (config.globals) (await import('./globals.Dgo-vS5G.js')).registerApiGlobally();
21
+ if (setupDefines(config.defines), setupEnv(config.env), !globalSetup && (globalSetup = true, setSafeTimers(), config.globals)) (await import('./globals.lgsmH00r.js')).registerApiGlobally();
29
22
  }
30
23
  function setupDefines(defines) {
31
24
  for (const key in defines) globalThis[key] = defines[key];
32
25
  }
33
26
  function setupEnv(env) {
34
- if (typeof process === "undefined") return;
35
- // same boolean-to-string assignment as VitestPlugin.configResolved
36
- const { PROD, DEV,...restEnvs } = env;
37
- process.env.PROD = PROD ? "1" : "";
38
- process.env.DEV = DEV ? "1" : "";
39
- for (const key in restEnvs) process.env[key] = env[key];
40
- }
41
- async function loadDiffConfig(config, executor) {
27
+ const state = getWorkerState(), { PROD, DEV,...restEnvs } = env;
28
+ for (const key in state.metaEnv.PROD = PROD, state.metaEnv.DEV = DEV, restEnvs) state.metaEnv[key] = env[key];
29
+ }
30
+ async function loadDiffConfig(config, moduleRunner) {
42
31
  if (typeof config.diff === "object") return config.diff;
43
32
  if (typeof config.diff !== "string") return;
44
- const diffModule = await executor.executeId(config.diff);
33
+ const diffModule = await moduleRunner.import(config.diff);
45
34
  if (diffModule && typeof diffModule.default === "object" && diffModule.default != null) return diffModule.default;
46
- else throw new Error(`invalid diff config file ${config.diff}. Must have a default export with config object`);
35
+ throw new Error(`invalid diff config file ${config.diff}. Must have a default export with config object`);
47
36
  }
48
- async function loadSnapshotSerializers(config, executor) {
49
- const files = config.snapshotSerializers;
50
- const snapshotSerializers = await Promise.all(files.map(async (file) => {
51
- const mo = await executor.executeId(file);
37
+ async function loadSnapshotSerializers(config, moduleRunner) {
38
+ const files = config.snapshotSerializers, snapshotSerializers = await Promise.all(files.map(async (file) => {
39
+ const mo = await moduleRunner.import(file);
52
40
  if (!mo || typeof mo.default !== "object" || mo.default === null) throw new Error(`invalid snapshot serializer file ${file}. Must export a default object`);
53
41
  const config = mo.default;
54
42
  if (typeof config.test !== "function" || typeof config.serialize !== "function" && typeof config.print !== "function") throw new TypeError(`invalid snapshot serializer in ${file}. Must have a 'test' method along with either a 'serialize' or 'print' method.`);