vitest 4.0.0-beta.1 → 4.0.0-beta.10

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 (85) hide show
  1. package/LICENSE.md +2 -2
  2. package/dist/browser.d.ts +13 -14
  3. package/dist/browser.js +6 -5
  4. package/dist/chunks/base.Cjha6usc.js +129 -0
  5. package/dist/chunks/{benchmark.CYdenmiT.js → benchmark.CJUa-Hsa.js} +6 -8
  6. package/dist/chunks/{benchmark.d.BwvBVTda.d.ts → benchmark.d.DAaHLpsq.d.ts} +4 -4
  7. package/dist/chunks/{browser.d.q8Z0P0q1.d.ts → browser.d.yFAklsD1.d.ts} +5 -5
  8. package/dist/chunks/{cac.D3EzDDZd.js → cac.DCxo_nSu.js} +70 -152
  9. package/dist/chunks/{cli-api.Dn5gKePv.js → cli-api.BJJXh9BV.js} +1330 -1677
  10. package/dist/chunks/{config.d.HJdfX-8k.d.ts → config.d.B_LthbQq.d.ts} +58 -63
  11. package/dist/chunks/{console.CtFJOzRO.js → console.7h5kHUIf.js} +34 -70
  12. package/dist/chunks/{constants.DnKduX2e.js → constants.D_Q9UYh-.js} +1 -9
  13. package/dist/chunks/{coverage.Cwa-XhJt.js → coverage.BCU-r2QL.js} +515 -781
  14. package/dist/chunks/{coverage.DVF1vEu8.js → coverage.D_JHT54q.js} +2 -2
  15. package/dist/chunks/{coverage.d.S9RMNXIe.d.ts → coverage.d.BZtK59WP.d.ts} +10 -8
  16. package/dist/chunks/{creator.GK6I-cL4.js → creator.08Gi-vCA.js} +93 -77
  17. package/dist/chunks/{date.Bq6ZW5rf.js → date.-jtEtIeV.js} +6 -17
  18. package/dist/chunks/{environment.d.CUq4cUgQ.d.ts → environment.d.BsToaxti.d.ts} +27 -6
  19. package/dist/chunks/{git.BVQ8w_Sw.js → git.BFNcloKD.js} +1 -2
  20. package/dist/chunks/{global.d.CVbXEflG.d.ts → global.d.BK3X7FW1.d.ts} +2 -5
  21. package/dist/chunks/{globals.Cxal6MLI.js → globals.DG-S3xFe.js} +8 -8
  22. package/dist/chunks/{index.CZI_8rVt.js → index.BIP7prJq.js} +289 -608
  23. package/dist/chunks/{index.B521nVV-.js → index.Bgo3tNWt.js} +23 -4
  24. package/dist/chunks/{index.TfbsX-3I.js → index.BjKEiSn0.js} +14 -24
  25. package/dist/chunks/{index.BWf_gE5n.js → index.CMfqw92x.js} +7 -6
  26. package/dist/chunks/{index.CmSc2RE5.js → index.DIWhzsUh.js} +72 -118
  27. package/dist/chunks/{inspector.C914Efll.js → inspector.CvQD-Nie.js} +10 -25
  28. package/dist/chunks/moduleRunner.d.D9nBoC4p.d.ts +201 -0
  29. package/dist/chunks/moduleTransport.I-bgQy0S.js +19 -0
  30. package/dist/chunks/{node.fjCdwEIl.js → node.CyipiPvJ.js} +1 -1
  31. package/dist/chunks/{plugin.d.C2EcJUjo.d.ts → plugin.d.BMVSnsGV.d.ts} +1 -1
  32. package/dist/chunks/{reporters.d.DxZg19fy.d.ts → reporters.d.BUWjmRYq.d.ts} +1226 -1291
  33. package/dist/chunks/resolveSnapshotEnvironment.Bkht6Yor.js +81 -0
  34. package/dist/chunks/resolver.Bx6lE0iq.js +119 -0
  35. package/dist/chunks/rpc.BKr6mtxz.js +65 -0
  36. package/dist/chunks/{setup-common.D7ZqXFx-.js → setup-common.uiMcU3cv.js} +17 -29
  37. package/dist/chunks/startModuleRunner.p67gbNo9.js +665 -0
  38. package/dist/chunks/{suite.d.FvehnV49.d.ts → suite.d.BJWk38HB.d.ts} +1 -1
  39. package/dist/chunks/test.BiqSKISg.js +214 -0
  40. package/dist/chunks/{typechecker.CVytUJuF.js → typechecker.DB-fIMaH.js} +144 -213
  41. package/dist/chunks/{utils.CAioKnHs.js → utils.C2YI6McM.js} +5 -14
  42. package/dist/chunks/{utils.XdZDrNZV.js → utils.D2R2NiOH.js} +8 -27
  43. package/dist/chunks/{vi.bdSIJ99Y.js → vi.ZPgvtBao.js} +156 -305
  44. package/dist/chunks/{vm.BThCzidc.js → vm.Ca0Y0W5f.js} +116 -226
  45. package/dist/chunks/{worker.d.DoNjFAiv.d.ts → worker.d.BDsXGkwh.d.ts} +28 -22
  46. package/dist/chunks/{worker.d.CmvJfRGs.d.ts → worker.d.BNcX_2mH.d.ts} +1 -1
  47. package/dist/cli.js +4 -4
  48. package/dist/config.cjs +3 -9
  49. package/dist/config.d.ts +49 -54
  50. package/dist/config.js +1 -1
  51. package/dist/coverage.d.ts +27 -26
  52. package/dist/coverage.js +6 -7
  53. package/dist/environments.d.ts +9 -13
  54. package/dist/environments.js +1 -1
  55. package/dist/index.d.ts +38 -45
  56. package/dist/index.js +7 -9
  57. package/dist/module-evaluator.d.ts +13 -0
  58. package/dist/module-evaluator.js +276 -0
  59. package/dist/module-runner.js +15 -0
  60. package/dist/node.d.ts +40 -41
  61. package/dist/node.js +23 -33
  62. package/dist/reporters.d.ts +12 -13
  63. package/dist/reporters.js +3 -3
  64. package/dist/runners.d.ts +3 -3
  65. package/dist/runners.js +13 -232
  66. package/dist/snapshot.js +2 -2
  67. package/dist/suite.d.ts +2 -2
  68. package/dist/suite.js +2 -2
  69. package/dist/worker.js +90 -47
  70. package/dist/workers/forks.js +34 -10
  71. package/dist/workers/runVmTests.js +36 -56
  72. package/dist/workers/threads.js +34 -10
  73. package/dist/workers/vmForks.js +11 -10
  74. package/dist/workers/vmThreads.js +11 -10
  75. package/dist/workers.d.ts +5 -4
  76. package/dist/workers.js +35 -17
  77. package/globals.d.ts +17 -17
  78. package/package.json +32 -31
  79. package/dist/chunks/base.Bj3pWTr1.js +0 -38
  80. package/dist/chunks/execute.B7h3T_Hc.js +0 -708
  81. package/dist/chunks/index.D-VkfKhf.js +0 -105
  82. package/dist/chunks/rpc.CsFtxqeq.js +0 -83
  83. package/dist/chunks/runBaseTests.BC7ZIH5L.js +0 -129
  84. package/dist/execute.d.ts +0 -148
  85. package/dist/execute.js +0 -13
@@ -0,0 +1,81 @@
1
+ import { chai } from '@vitest/expect';
2
+ import { l as loadDiffConfig, b as loadSnapshotSerializers, t as takeCoverageInsideWorker } from './setup-common.uiMcU3cv.js';
3
+ import { r as rpc } from './rpc.BKr6mtxz.js';
4
+ import { g as getWorkerState } from './utils.D2R2NiOH.js';
5
+ import { V as VitestTestRunner, N as NodeBenchmarkRunner } from './test.BiqSKISg.js';
6
+
7
+ function setupChaiConfig(config) {
8
+ Object.assign(chai.config, config);
9
+ }
10
+
11
+ async function getTestRunnerConstructor(config, moduleRunner) {
12
+ if (!config.runner) return config.mode === "test" ? VitestTestRunner : NodeBenchmarkRunner;
13
+ const mod = await moduleRunner.import(config.runner);
14
+ if (!mod.default && typeof mod.default !== "function") throw new Error(`Runner must export a default function, but got ${typeof mod.default} imported from ${config.runner}`);
15
+ return mod.default;
16
+ }
17
+ async function resolveTestRunner(config, moduleRunner) {
18
+ const TestRunner = await getTestRunnerConstructor(config, moduleRunner), testRunner = new TestRunner(config);
19
+ if (Object.defineProperty(testRunner, "moduleRunner", {
20
+ value: moduleRunner,
21
+ enumerable: false,
22
+ configurable: false
23
+ }), !testRunner.config) testRunner.config = config;
24
+ if (!testRunner.importFile) throw new Error("Runner must implement \"importFile\" method.");
25
+ const [diffOptions] = await Promise.all([loadDiffConfig(config, moduleRunner), loadSnapshotSerializers(config, moduleRunner)]);
26
+ testRunner.config.diffOptions = diffOptions;
27
+ // patch some methods, so custom runners don't need to call RPC
28
+ const originalOnTaskUpdate = testRunner.onTaskUpdate;
29
+ testRunner.onTaskUpdate = async (task, events) => {
30
+ const p = rpc().onTaskUpdate(task, events);
31
+ return await originalOnTaskUpdate?.call(testRunner, task, events), p;
32
+ };
33
+ // patch some methods, so custom runners don't need to call RPC
34
+ const originalOnTestAnnotate = testRunner.onTestAnnotate;
35
+ testRunner.onTestAnnotate = async (test, annotation) => {
36
+ const p = rpc().onTaskAnnotate(test.id, annotation), overriddenResult = await originalOnTestAnnotate?.call(testRunner, test, annotation), vitestResult = await p;
37
+ return overriddenResult || vitestResult;
38
+ };
39
+ const originalOnCollectStart = testRunner.onCollectStart;
40
+ testRunner.onCollectStart = async (file) => {
41
+ await rpc().onQueued(file), await originalOnCollectStart?.call(testRunner, file);
42
+ };
43
+ const originalOnCollected = testRunner.onCollected;
44
+ testRunner.onCollected = async (files) => {
45
+ const state = getWorkerState();
46
+ files.forEach((file) => {
47
+ file.prepareDuration = state.durations.prepare, file.environmentLoad = state.durations.environment, state.durations.prepare = 0, state.durations.environment = 0;
48
+ }), rpc().onCollected(files), await originalOnCollected?.call(testRunner, files);
49
+ };
50
+ const originalOnAfterRun = testRunner.onAfterRunFiles;
51
+ testRunner.onAfterRunFiles = async (files) => {
52
+ const state = getWorkerState(), coverage = await takeCoverageInsideWorker(config.coverage, moduleRunner);
53
+ if (coverage) rpc().onAfterSuiteRun({
54
+ coverage,
55
+ testFiles: files.map((file) => file.name).sort(),
56
+ environment: state.environment.viteEnvironment || state.environment.name,
57
+ projectName: state.ctx.projectName
58
+ });
59
+ await originalOnAfterRun?.call(testRunner, files);
60
+ };
61
+ const originalOnAfterRunTask = testRunner.onAfterRunTask;
62
+ return testRunner.onAfterRunTask = async (test) => {
63
+ if (config.bail && test.result?.state === "fail") {
64
+ const previousFailures = await rpc().getCountOfFailedTests(), currentFailures = 1 + previousFailures;
65
+ if (currentFailures >= config.bail) rpc().onCancel("test-failure"), testRunner.cancel?.("test-failure");
66
+ }
67
+ await originalOnAfterRunTask?.call(testRunner, test);
68
+ }, testRunner;
69
+ }
70
+
71
+ async function resolveSnapshotEnvironment(config, executor) {
72
+ if (!config.snapshotEnvironment) {
73
+ const { VitestNodeSnapshotEnvironment } = await import('./node.CyipiPvJ.js');
74
+ return new VitestNodeSnapshotEnvironment();
75
+ }
76
+ const mod = await executor.import(config.snapshotEnvironment);
77
+ if (typeof mod.default !== "object" || !mod.default) throw new Error("Snapshot environment module must have a default export object with a shape of `SnapshotEnvironment`");
78
+ return mod.default;
79
+ }
80
+
81
+ export { resolveSnapshotEnvironment as a, resolveTestRunner as r, setupChaiConfig as s };
@@ -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 };
@@ -0,0 +1,65 @@
1
+ import { getSafeTimers } from '@vitest/utils';
2
+ import { c as createBirpc } from './index.Bgo3tNWt.js';
3
+ import { g as getWorkerState } from './utils.D2R2NiOH.js';
4
+
5
+ const { get } = Reflect;
6
+ function withSafeTimers(fn) {
7
+ const { setTimeout, clearTimeout, nextTick, setImmediate, clearImmediate } = getSafeTimers(), currentSetTimeout = globalThis.setTimeout, currentClearTimeout = globalThis.clearTimeout, currentSetImmediate = globalThis.setImmediate, currentClearImmediate = globalThis.clearImmediate, currentNextTick = globalThis.process?.nextTick;
8
+ try {
9
+ if (globalThis.setTimeout = setTimeout, globalThis.clearTimeout = clearTimeout, setImmediate) globalThis.setImmediate = setImmediate;
10
+ if (clearImmediate) globalThis.clearImmediate = clearImmediate;
11
+ if (globalThis.process && nextTick) globalThis.process.nextTick = nextTick;
12
+ const result = fn();
13
+ return result;
14
+ } finally {
15
+ if (globalThis.setTimeout = currentSetTimeout, globalThis.clearTimeout = currentClearTimeout, globalThis.setImmediate = currentSetImmediate, globalThis.clearImmediate = currentClearImmediate, globalThis.process && nextTick) nextTick(() => {
16
+ globalThis.process.nextTick = currentNextTick;
17
+ });
18
+ }
19
+ }
20
+ const promises = /* @__PURE__ */ new Set();
21
+ async function rpcDone() {
22
+ if (!promises.size) return;
23
+ const awaitable = Array.from(promises);
24
+ return Promise.all(awaitable);
25
+ }
26
+ function createRuntimeRpc(options) {
27
+ let setCancel = (_reason) => {};
28
+ const onCancel = new Promise((resolve) => {
29
+ setCancel = resolve;
30
+ }), rpc = createSafeRpc(createBirpc({ onCancel: setCancel }, {
31
+ eventNames: [
32
+ "onUserConsoleLog",
33
+ "onCollected",
34
+ "onCancel"
35
+ ],
36
+ timeout: -1,
37
+ ...options
38
+ }));
39
+ return {
40
+ rpc,
41
+ onCancel
42
+ };
43
+ }
44
+ function createSafeRpc(rpc) {
45
+ return new Proxy(rpc, { get(target, p, handler) {
46
+ // keep $rejectPendingCalls as sync function
47
+ if (p === "$rejectPendingCalls") return rpc.$rejectPendingCalls;
48
+ const sendCall = get(target, p, handler), safeSendCall = (...args) => withSafeTimers(async () => {
49
+ const result = sendCall(...args);
50
+ promises.add(result);
51
+ try {
52
+ return await result;
53
+ } finally {
54
+ promises.delete(result);
55
+ }
56
+ });
57
+ return safeSendCall.asEvent = sendCall.asEvent, safeSendCall;
58
+ } });
59
+ }
60
+ function rpc() {
61
+ const { rpc } = getWorkerState();
62
+ return rpc;
63
+ }
64
+
65
+ export { rpcDone as a, createRuntimeRpc as c, rpc as r };
@@ -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.D2R2NiOH.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.Cxal6MLI.js')).registerApiGlobally();
21
+ if (setupDefines(config), setupEnv(config.env), !globalSetup && (globalSetup = true, setSafeTimers(), config.globals)) (await import('./globals.DG-S3xFe.js')).registerApiGlobally();
29
22
  }
30
- function setupDefines(defines) {
31
- for (const key in defines) globalThis[key] = defines[key];
23
+ function setupDefines(config) {
24
+ for (const key in config.defines) globalThis[key] = config.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.`);