vitest 5.1.0 → 5.1.2

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 (61) hide show
  1. package/dist/browser.d.ts +6 -5
  2. package/dist/browser.js +7 -7
  3. package/dist/chunks/{base.Cof-UHJf.js → base.DCg6Jh4N.js} +12 -12
  4. package/dist/chunks/{browser.d.C7tWgUvw.d.ts → browser.d.B-QwH_F6.d.ts} +3 -3
  5. package/dist/chunks/{cac.BYbt0aJp.js → cac.DnNTZKhD.js} +15 -10
  6. package/dist/chunks/{cli-api.COfZo8lK.js → cli-api.9v9AxcPO.js} +444 -161
  7. package/dist/chunks/{config.d.B3YV4t0O.d.ts → config.d.BpJq6tRA.d.ts} +7 -1
  8. package/dist/chunks/{console.CQZ877Hi.js → console.DdxlsSsm.js} +4 -4
  9. package/dist/chunks/{creator.DHWmytIK.js → creator.B-BIoERb.js} +13 -11
  10. package/dist/chunks/{display.BlTmubjj.js → display.Cj2h2zsY.js} +1 -1
  11. package/dist/chunks/{doctor.B-oPbwps.js → doctor.DBFXC86z.js} +1 -1
  12. package/dist/chunks/{environment.d.BFQtFKdZ.d.ts → environment.d.rlpAM-ON.d.ts} +1 -1
  13. package/dist/chunks/{globals.ZKtKSkEf.js → globals.Cz5RAf6U.js} +10 -10
  14. package/dist/chunks/{index.Di8au7q4.js → index.6pLw0FLK.js} +220 -91
  15. package/dist/chunks/{index.w_oBZ9N8.js → index.BSqmIH9v.js} +3 -3
  16. package/dist/chunks/{index.Bi0NXYPf.js → index.C7Nn66Gy.js} +21 -9
  17. package/dist/chunks/{index.DmDMHCg8.js → index.CAmut2NG.js} +25 -1
  18. package/dist/chunks/{index.CZzC1gGg.js → index.D5jWOaqm.js} +35 -22
  19. package/dist/chunks/{index.D0heQG4v.js → index.Or9psEGe.js} +1 -1
  20. package/dist/chunks/{init-forks.BaDXQSD8.js → init-forks.q4IoGYZe.js} +7 -1
  21. package/dist/chunks/{init-threads.ZX_Vov0z.js → init-threads.Bf1Frg9S.js} +1 -1
  22. package/dist/chunks/{init.CO4AB7HZ.js → init.dGO4K2C0.js} +16 -8
  23. package/dist/chunks/{inspector.CvyFGlXm.js → inspector.D6o1NPo1.js} +12 -1
  24. package/dist/chunks/{modules.BJuCwlRJ.js → moduleSourceMap.Dp1WduWi.js} +31 -1
  25. package/dist/chunks/{native.upB-V0CK.js → native.D5q1ylZC.js} +2 -1
  26. package/dist/chunks/{nativeModuleMocker.Dh5azSB4.js → nativeModuleMocker.ihb3q7Cg.js} +4 -2
  27. package/dist/chunks/{plugin.d.LRFSN46m.d.ts → plugin.d.Bx2wJglX.d.ts} +58 -75
  28. package/dist/chunks/{plugins.DPQHVT0p.js → plugins.BPruPOR8.js} +1 -1
  29. package/dist/chunks/{rawSnapshot.DqSiqIEx.js → rawSnapshot.DvoRLRNr.js} +2 -2
  30. package/dist/chunks/{rpc.Uhkwr2NM.js → rpc.CNYWPa97.js} +3 -19
  31. package/dist/chunks/{rpc.d.3FOhdFx8.d.ts → rpc.d.DHfuwqP0.d.ts} +2 -2
  32. package/dist/chunks/{run.CjdgFZiW.js → run.zBhXlcZQ.js} +113 -49
  33. package/dist/chunks/{setup-common.CqAQCXzx.js → setup-common.kEGtNVHG.js} +3 -3
  34. package/dist/chunks/{source-map.DakdQc29.js → source-map.DPHGMWvM.js} +3 -1
  35. package/dist/chunks/{source-map.d.BkG8YK_3.d.ts → source-map.d.xB6_75fl.d.ts} +2 -1
  36. package/dist/chunks/{spy.DDMXghXv.js → spy.BO0hTE3G.js} +76 -53
  37. package/dist/chunks/{task-utils.d.D-gFPNFi.d.ts → task-utils.d.DgSjIb7r.d.ts} +1 -1
  38. package/dist/chunks/{utils.BBk_icFG.js → utils.sAsh2ClK.js} +2 -6
  39. package/dist/chunks/{vm.b4MbCAJQ.js → vm.DNr3Eju_.js} +4 -4
  40. package/dist/chunks/{worker.d.CyJRpyfZ.d.ts → worker.d.BigfbIsH.d.ts} +3 -3
  41. package/dist/cli.js +1 -1
  42. package/dist/config.d.ts +8 -8
  43. package/dist/index.d.ts +10 -10
  44. package/dist/index.js +10 -10
  45. package/dist/module-evaluator.d.ts +3 -3
  46. package/dist/module-evaluator.js +1 -1
  47. package/dist/node.d.ts +11 -10
  48. package/dist/node.js +18 -15
  49. package/dist/runtime.d.ts +5 -4
  50. package/dist/runtime.js +5 -3
  51. package/dist/spy.js +1 -1
  52. package/dist/worker.d.ts +4 -4
  53. package/dist/worker.js +19 -18
  54. package/dist/workers/forks.js +20 -19
  55. package/dist/workers/runVmTests.js +14 -14
  56. package/dist/workers/threads.js +20 -19
  57. package/dist/workers/vmForks.js +14 -13
  58. package/dist/workers/vmThreads.js +14 -13
  59. package/dist/workers/watchdog.js +20 -0
  60. package/package.json +21 -21
  61. /package/dist/chunks/{index.BoyTG_B7.js → dist.BoyTG_B7.js} +0 -0
@@ -1,6 +1,7 @@
1
1
  import fs__default from 'node:fs';
2
2
  import { n as normalize, m as splitFileAndPostfix$1, j as join, o as isBareImport } from './pathe.M-eThtNZ.zq3TM4NT.js';
3
- import { i as isBuiltin, a as isBrowserExternal, t as toBuiltin } from './modules.BJuCwlRJ.js';
3
+ import { w as withInlineSourceMap, i as isBuiltin, a as isBrowserExternal, t as toBuiltin, s as splitSourceMap } from './moduleSourceMap.Dp1WduWi.js';
4
+ import { i as isInspectorOpen } from './inspector.D6o1NPo1.js';
4
5
  import { E as EnvironmentTeardownError, a as getSafeWorkerState } from './utils.DYj33du9.js';
5
6
  import { pathToFileURL, URL as URL$1 } from 'node:url';
6
7
  import { distDir } from '../path.js';
@@ -548,7 +549,8 @@ class VitestTransport {
548
549
  return { result: [] };
549
550
  if (name !== "fetchModule") return { error: /* @__PURE__ */ new Error(`Unknown method: ${name}. Expected "fetchModule".`) };
550
551
  try {
551
- return { result: await this.options.fetchModule(...data) };
552
+ const result = await this.options.fetchModule(...data);
553
+ return { result: this.options.inlineSourceMap ? withInlineSourceMap(result) : result };
552
554
  } catch (cause) {
553
555
  if (cause instanceof EnvironmentTeardownError) {
554
556
  const [id, importer] = data;
@@ -819,7 +821,7 @@ function startVitestModuleRunner(options) {
819
821
  resolved.then((value) => resolvedIds.set(key, value), () => resolvedIds.delete(key));
820
822
  return resolved;
821
823
  }
822
- const evaluator = options.evaluator || new VitestModuleEvaluator(vm, {
824
+ const evaluator = options.evaluator || new VitestModuleEvaluator({
823
825
  traces,
824
826
  metaEnv: state().metaEnv,
825
827
  evaluatedModules: options.evaluatedModules,
@@ -835,7 +837,7 @@ function startVitestModuleRunner(options) {
835
837
  getCurrentTestFilepath: () => state().filepath,
836
838
  getEnvironmentName: environment,
837
839
  getterTracker: state().getterTracker
838
- });
840
+ }, vm);
839
841
  const moduleRunner = new VitestModuleRunner({
840
842
  spyModule: options.spyModule,
841
843
  evaluatedModules: options.evaluatedModules,
@@ -843,6 +845,10 @@ function startVitestModuleRunner(options) {
843
845
  traces,
844
846
  mocker: options.mocker,
845
847
  transport: {
848
+ get inlineSourceMap() {
849
+ // a debugger attached to the main process can attach to worker threads too
850
+ return state().config.inspector.openInMainProcess || isInspectorOpen();
851
+ },
846
852
  async fetchModule(id, importer, options) {
847
853
  const resolvingModules = state().resolvingModules;
848
854
  if (isWindows) {
@@ -897,8 +903,10 @@ function startVitestModuleRunner(options) {
897
903
  const warmResult = warm && (Object.hasOwn(warm, id) ? warm[id] : Object.hasOwn(warm, rawId) ? warm[rawId] : void 0);
898
904
  if (warmResult) {
899
905
  if ("tmp" in warmResult) try {
906
+ const { code, sourceMap } = splitSourceMap(readFileSync(warmResult.tmp, "utf-8"));
900
907
  return {
901
- code: readFileSync(warmResult.tmp, "utf-8"),
908
+ code,
909
+ sourceMap,
902
910
  ...warmResult
903
911
  };
904
912
  } catch {}
@@ -907,10 +915,14 @@ function startVitestModuleRunner(options) {
907
915
  }
908
916
  const otelCarrier = traces?.getContextCarrier();
909
917
  const result = await trackFetchTime(rpc().fetch(id, importer, environment(), options, otelCarrier));
910
- if ("cached" in result) return {
911
- code: readFileSync(result.tmp, "utf-8"),
912
- ...result
913
- };
918
+ if ("cached" in result) {
919
+ const { code, sourceMap } = splitSourceMap(readFileSync(result.tmp, "utf-8"));
920
+ return {
921
+ code,
922
+ sourceMap,
923
+ ...result
924
+ };
925
+ }
914
926
  return result;
915
927
  } catch (cause) {
916
928
  // rethrow vite error if it cannot load the module because it's not resolved
@@ -1,3 +1,27 @@
1
+ import { D as DecodedMap } from './source-map.DPHGMWvM.js';
2
+ import { EvaluatedModules } from 'vite/module-runner';
3
+ import { d as dirname, r as resolve } from './pathe.M-eThtNZ.zq3TM4NT.js';
4
+
5
+ class VitestEvaluatedModules extends EvaluatedModules {
6
+ getModuleSourceMapById(id) {
7
+ const mod = this.getModuleById(id);
8
+ const sourceMap = (mod?.meta)?.sourceMap;
9
+ if (mod && sourceMap) {
10
+ mod.map ??= new DecodedMap(JSON.parse(sourceMap), mod.file);
11
+ return mod.map;
12
+ }
13
+ // TODO: this is not needed in Vite 7.2+
14
+ /** the return type is not exposed by Vite */
15
+ const map = super.getModuleSourceMapById(id);
16
+ if (map != null && !("_patched" in map)) {
17
+ map._patched = true;
18
+ const dir = dirname(map.url);
19
+ map.resolvedSources = (map.map.sources || []).map((s) => resolve(dir, s || ""));
20
+ }
21
+ return map;
22
+ }
23
+ }
24
+
1
25
  //#region src/utils.ts
2
26
  function createPromiseWithResolvers() {
3
27
  let resolve;
@@ -197,4 +221,4 @@ function createBirpc($functions, options) {
197
221
  return rpc;
198
222
  }
199
223
 
200
- export { createBirpc as c };
224
+ export { VitestEvaluatedModules as V, createBirpc as c };
@@ -1,18 +1,19 @@
1
- import { b as printDiffOrStringify, d as diff, a as processError, g as getRunningTests, c as getCurrentTest, r as recordArtifact, T as TestSyntaxError, e as createTaskCollector, f as getCurrentSuite, h as createChainable, i as getHooks, j as getFn, m as matchesTags, k as afterAll, l as afterEach, n as aroundAll, o as aroundEach, q as beforeAll, t as beforeEach, u as describe, v as it, w as onTestFailed, x as onTestFinished, y as suite, z as test } from './run.CjdgFZiW.js';
1
+ import { b as printDiffOrStringify, d as diff, a as processError, r as replaceAsymmetricMatcher, g as getRunningTests, c as getCurrentTest, e as recordArtifact, T as TestSyntaxError, f as createTaskCollector, h as getCurrentSuite, i as createChainable, j as getHooks, k as getFn, m as matchesTags, l as afterAll, n as afterEach, o as aroundAll, q as aroundEach, t as beforeAll, u as beforeEach, v as describe, w as it, x as onTestFailed, y as onTestFinished, z as suite, A as test } from './run.zBhXlcZQ.js';
2
2
  import { i as isChildProcess, r as resetModules, g as getWorkerState } from './utils.DYj33du9.js';
3
- import { e as parseErrorStacktrace, a as getSafeTimers, f as parseSingleStack, h as delay } from './source-map.DakdQc29.js';
4
- import { i as isMockFunction, f as fn, a as spyOn, r as restoreAllMocks, b as resetAllMocks, c as clearAllMocks } from './spy.DDMXghXv.js';
5
- import { g as getType, f as isObject, D as noop, y as assertTypes, x as ordinal, E as createSimpleStackTrace, i as isAbsolute, a as relative, n as normalize } from './pathe.M-eThtNZ.zq3TM4NT.js';
6
- import { a as commonjsGlobal } from './index.D0heQG4v.js';
7
- import { s as stringify, i as inspect } from './display.BlTmubjj.js';
3
+ import { e as parseErrorStacktrace, a as getSafeTimers, f as parseSingleStack, h as delay } from './source-map.DPHGMWvM.js';
4
+ import { i as isMockFunction, f as fn, a as spyOn, r as restoreAllMocks, b as resetAllMocks, c as clearAllMocks } from './spy.BO0hTE3G.js';
5
+ import { g as getType, f as isObject, D as noop, y as assertTypes, x as ordinal, u as deepClone, E as createSimpleStackTrace, i as isAbsolute, a as relative, n as normalize } from './pathe.M-eThtNZ.zq3TM4NT.js';
6
+ import { a as commonjsGlobal } from './index.Or9psEGe.js';
7
+ import { s as stringify, i as inspect } from './display.Cj2h2zsY.js';
8
8
  import { $ } from './tinyrainbow.Do8I1XRG.js';
9
9
  import * as chai from 'chai';
10
- import { use, util } from 'chai';
10
+ import { util } from 'chai';
11
11
  import { getNames, getTests, getTestName, createFileTask } from '../task-utils.js';
12
- import { a as addSerializer } from './plugins.DPQHVT0p.js';
13
- import { C as CounterMap, D as DefaultMap, e as evaluateSnapshotFile, k as keyToTestName, s as saveSnapshotFile, a as saveInlineSnapshots, b as saveRawSnapshots, t as testNameToKey, c as serialize, d as addExtraLineBreaks, n as normalizeNewlines, r as removeExtraLineBreaks, f as deepMergeSnapshot, g as stripSnapshotIndentation } from './rawSnapshot.DqSiqIEx.js';
14
- import { r as rpc, V as VitestEvaluatedModules } from './rpc.Uhkwr2NM.js';
12
+ import { a as addSerializer } from './plugins.BPruPOR8.js';
13
+ import { C as CounterMap, D as DefaultMap, e as evaluateSnapshotFile, k as keyToTestName, s as saveSnapshotFile, a as saveInlineSnapshots, b as saveRawSnapshots, t as testNameToKey, c as serialize, d as addExtraLineBreaks, n as normalizeNewlines, r as removeExtraLineBreaks, f as deepMergeSnapshot, g as stripSnapshotIndentation } from './rawSnapshot.DvoRLRNr.js';
14
+ import { V as VitestEvaluatedModules } from './index.CAmut2NG.js';
15
15
  import { Bench } from 'tinybench';
16
+ import { r as rpc } from './rpc.CNYWPa97.js';
16
17
  import { expectTypeOf } from 'expect-type';
17
18
 
18
19
  function isSameStackPosition(x, y) {
@@ -127,7 +128,8 @@ class SnapshotState {
127
128
  const name = keyToTestName(key);
128
129
  const count = this._counters.get(name);
129
130
  if (count > 0) {
130
- if (key in this._snapshotData || key in this._initialData) this._snapshotData[key] = this._initialData[key];
131
+ if (key in this._initialData) this._snapshotData[key] = this._initialData[key];
132
+ else delete this._snapshotData[key];
131
133
  this._counters.set(name, count - 1);
132
134
  }
133
135
  }
@@ -1042,7 +1044,8 @@ function isErrorEqual(a, b, aStack, bStack, customTesters, hasKey) {
1042
1044
  function keys(obj, hasKey) {
1043
1045
  const keys = [];
1044
1046
  for (const key in obj) if (hasKey(obj, key)) keys.push(key);
1045
- return keys.concat(Object.getOwnPropertySymbols(obj).filter((symbol) => Object.getOwnPropertyDescriptor(obj, symbol).enumerable));
1047
+ for (const symbol of Object.getOwnPropertySymbols(obj)) if (Object.getOwnPropertyDescriptor(obj, symbol).enumerable) keys.push(symbol);
1048
+ return keys;
1046
1049
  }
1047
1050
  function hasDefinedKey(obj, key) {
1048
1051
  return hasKey(obj, key) && obj[key] !== void 0;
@@ -2207,10 +2210,14 @@ const JestChaiExpect = (chai, utils) => {
2207
2210
  return proxy;
2208
2211
  });
2209
2212
  };
2213
+ function formatDiff(expected, received) {
2214
+ const { replacedExpected, replacedActual } = replaceAsymmetricMatcher(deepClone(received, { forceWritable: true }), deepClone(expected, { forceWritable: true }));
2215
+ return diff(replacedExpected, replacedActual, { omitAnnotationLines: true });
2216
+ }
2210
2217
  function formatCalls(spy, msg, showActualCall) {
2211
2218
  if (spy.mock.calls.length) msg += $.gray(`\n\nReceived:\n\n${spy.mock.calls.map((callArg, i) => {
2212
2219
  let methodCall = $.bold(` ${ordinal(i + 1)} ${spy.getMockName()} call:\n\n`);
2213
- if (showActualCall) methodCall += diff(showActualCall, callArg, { omitAnnotationLines: true });
2220
+ if (showActualCall) methodCall += formatDiff(showActualCall, callArg);
2214
2221
  else methodCall += stringify(callArg).split("\n").map((line) => ` ${line}`).join("\n");
2215
2222
  methodCall += "\n";
2216
2223
  return methodCall;
@@ -2221,7 +2228,7 @@ function formatCalls(spy, msg, showActualCall) {
2221
2228
  function formatReturns(spy, results, msg, showActualReturn) {
2222
2229
  if (results.length) msg += $.gray(`\n\nReceived:\n\n${results.map((callReturn, i) => {
2223
2230
  let methodCall = $.bold(` ${ordinal(i + 1)} ${spy.getMockName()} call return:\n\n`);
2224
- if (showActualReturn) methodCall += diff(showActualReturn, callReturn.value, { omitAnnotationLines: true });
2231
+ if (showActualReturn) methodCall += formatDiff(showActualReturn, callReturn.value);
2225
2232
  else methodCall += stringify(callReturn).split("\n").map((line) => ` ${line}`).join("\n");
2226
2233
  methodCall += "\n";
2227
2234
  return methodCall;
@@ -2360,7 +2367,8 @@ function JestExtendPlugin(c, expect, matchers) {
2360
2367
  }
2361
2368
  const JestExtend = (chai, utils) => {
2362
2369
  utils.addMethod(chai.expect, "extend", (expect, expects) => {
2363
- use(JestExtendPlugin(chai, expect, expects));
2370
+ // not `chai.use`, it keeps every plugin forever
2371
+ JestExtendPlugin(chai, expect, expects)(chai, utils);
2364
2372
  });
2365
2373
  };
2366
2374
 
@@ -7355,7 +7363,7 @@ function throwWithCause(error, source, message) {
7355
7363
  } catch {}
7356
7364
  throw copyStackTrace(error, source);
7357
7365
  }
7358
- function createExpectPoll(expect) {
7366
+ function createExpectPoll(expect, isLocalExpect) {
7359
7367
  return function poll(fn, options = {}) {
7360
7368
  const defaults = getWorkerState().config.expect?.poll ?? {};
7361
7369
  const { interval = defaults.interval ?? 50, timeout = defaults.timeout ?? 1e3, message } = options;
@@ -7368,7 +7376,8 @@ function createExpectPoll(expect) {
7368
7376
  chai.util.flag(assertion, "_poll.interval", interval);
7369
7377
  const test = chai.util.flag(assertion, "vitest-test");
7370
7378
  if (!test) throw new Error("expect.poll() must be called inside a test");
7371
- setTraceHandlers(assertion, test);
7379
+ // the global expect guesses the current test, which is ambiguous while several tests run concurrently
7380
+ if (isLocalExpect || getRunningTests().size === 1) setTraceHandlers(assertion, test);
7372
7381
  const proxy = new Proxy(assertion, { get(target, key, receiver) {
7373
7382
  const assertionFunction = Reflect.get(target, key, receiver);
7374
7383
  if (typeof assertionFunction !== "function") return assertionFunction instanceof chai.Assertion ? proxy : assertionFunction;
@@ -7924,7 +7933,7 @@ function createExpect(test) {
7924
7933
  // @ts-expect-error private soft access
7925
7934
  return expect(...args).withContext({ soft: true });
7926
7935
  };
7927
- expect.poll = createExpectPoll(expect);
7936
+ expect.poll = createExpectPoll(expect, !!test);
7928
7937
  expect.unreachable = (message) => {
7929
7938
  chai.assert.fail(`expected${message ? ` "${message}" ` : " "}not to be reached`);
7930
7939
  };
@@ -7946,11 +7955,11 @@ function createExpect(test) {
7946
7955
  }
7947
7956
  chai.util.addMethod(expect, "assertions", assertions);
7948
7957
  chai.util.addMethod(expect, "hasAssertions", hasAssertions);
7949
- expect.extend(customMatchers);
7950
- expect.extend(benchMatchers);
7951
7958
  return expect;
7952
7959
  }
7953
7960
  const globalExpect = createExpect();
7961
+ globalExpect.extend(customMatchers);
7962
+ globalExpect.extend(benchMatchers);
7954
7963
  Object.defineProperty(globalThis, GLOBAL_EXPECT, {
7955
7964
  value: globalExpect,
7956
7965
  writable: true,
@@ -8377,15 +8386,19 @@ class TestRunner {
8377
8386
  if (this.config.experimental.traceTimeline && test.type === "test") startTraceAttempt(test, options);
8378
8387
  clearModuleMocks(this.config);
8379
8388
  this.snapshotClient.clearTest(test.file.filepath, test.id);
8380
- setState({
8389
+ const assertionState = {
8381
8390
  assertionCalls: 0,
8382
8391
  isExpectingAssertions: false,
8383
8392
  isExpectingAssertionsError: null,
8384
8393
  expectedAssertionsNumber: null,
8385
- expectedAssertionsNumberErrorGen: null,
8394
+ expectedAssertionsNumberErrorGen: null
8395
+ };
8396
+ setState({
8397
+ ...assertionState,
8386
8398
  currentTestName: getTestName(test),
8387
8399
  snapshotState: this.snapshotClient.getSnapshotState(test.file.filepath)
8388
8400
  }, globalThis[GLOBAL_EXPECT]);
8401
+ if (test.type === "test" && test.context._local) setState(assertionState, test.context.expect);
8389
8402
  }
8390
8403
  async onAfterRetryTask(test, _options) {
8391
8404
  if (this.config.experimental.traceTimeline) await finishTraceAttempt(test);
@@ -156,7 +156,7 @@ const serialize$5 = (val, config, indentation, depth, refs, printer) => {
156
156
  if (stringedValue === "StringMatching" || stringedValue === "StringNotMatching") return stringedValue + SPACE$2 + printer(val.sample, config, indentation, depth, refs);
157
157
  if (stringedValue === "StringContaining" || stringedValue === "StringNotContaining") return stringedValue + SPACE$2 + printer(val.sample, config, indentation, depth, refs);
158
158
  if (typeof val.toAsymmetricMatcher !== "function") throw new TypeError(`Asymmetric matcher ${val.constructor.name} does not implement toAsymmetricMatcher()`);
159
- return val.toAsymmetricMatcher();
159
+ return val.toAsymmetricMatcher().replaceAll("\n", `\n${indentation}`);
160
160
  };
161
161
  const test$5 = (val) => val && val.$$typeof === asymmetricMatcher;
162
162
  const plugin$5 = {
@@ -1,4 +1,4 @@
1
- import { i as init } from './init.CO4AB7HZ.js';
1
+ import { i as init } from './init.dGO4K2C0.js';
2
2
 
3
3
  if (!process.send) throw new Error("Expected worker to be run in node:child_process");
4
4
  // Store globals in case tests overwrite them
@@ -10,6 +10,7 @@ const processRemoveAllListeners = process.removeAllListeners.bind(process);
10
10
  // Work-around for nodejs/node#55094
11
11
  if (process.execArgv.some((execArg) => execArg.startsWith("--prof") || execArg.startsWith("--cpu-prof") || execArg.startsWith("--heap-prof") || execArg.startsWith("--diagnostic-dir"))) processOn("SIGTERM", () => processExit());
12
12
  processOn("error", onError);
13
+ processOn("disconnect", onDisconnect);
13
14
  function workerInit(options) {
14
15
  const { runTests } = options;
15
16
  init({
@@ -19,6 +20,7 @@ function workerInit(options) {
19
20
  teardown: () => {
20
21
  processRemoveAllListeners("message");
21
22
  processOff("error", onError);
23
+ processOff("disconnect", onDisconnect);
22
24
  // the guard installed by the test runner stays active between test
23
25
  // files: with `isolate: false` a late process.exit would kill the
24
26
  // other files sharing this process
@@ -34,5 +36,9 @@ function workerInit(options) {
34
36
  function onError(error) {
35
37
  if (error?.code === "ERR_IPC_CHANNEL_CLOSED" || error?.code === "EPIPE") processExit(1);
36
38
  }
39
+ // Main process has died, there is no one to report results to
40
+ function onDisconnect() {
41
+ processExit(1);
42
+ }
37
43
 
38
44
  export { workerInit as w };
@@ -1,5 +1,5 @@
1
1
  import { isMainThread, parentPort } from 'node:worker_threads';
2
- import { i as init } from './init.CO4AB7HZ.js';
2
+ import { i as init } from './init.dGO4K2C0.js';
3
3
 
4
4
  if (isMainThread || !parentPort) throw new Error("Expected worker to be run in node:worker_threads");
5
5
  function workerInit(options) {
@@ -2,13 +2,15 @@ import { readFileSync } from 'node:fs';
2
2
  import module$1, { isBuiltin } from 'node:module';
3
3
  import { pathToFileURL } from 'node:url';
4
4
  import { EvaluatedModules, ModuleRunner } from 'vite/module-runner';
5
- import { e as environments, b as VitestTransport } from './index.Bi0NXYPf.js';
5
+ import { e as environments, b as VitestTransport } from './index.C7Nn66Gy.js';
6
+ import { s as splitSourceMap } from './moduleSourceMap.Dp1WduWi.js';
6
7
  import { r as resolve } from './pathe.M-eThtNZ.zq3TM4NT.js';
7
- import { b as serializeValue, c as createStackString, p as parseStacktrace } from './source-map.DakdQc29.js';
8
+ import { b as serializeValue, c as createStackString, p as parseStacktrace } from './source-map.DPHGMWvM.js';
8
9
  import { w } from './tinyrainbow.Do8I1XRG.js';
9
10
  import { Traces } from '../traces.js';
10
- import { o as onCancel, V as VitestEvaluatedModules, a as rpcDone, c as createRuntimeRpc } from './rpc.Uhkwr2NM.js';
11
- import { s as setupInspect } from './inspector.CvyFGlXm.js';
11
+ import { o as onCancel, a as rpcDone, c as createRuntimeRpc } from './rpc.CNYWPa97.js';
12
+ import { s as setupInspect } from './inspector.D6o1NPo1.js';
13
+ import { V as VitestEvaluatedModules } from './index.CAmut2NG.js';
12
14
  import { E as EnvironmentTeardownError } from './utils.DYj33du9.js';
13
15
 
14
16
  function isBuiltinEnvironment(env) {
@@ -25,12 +27,18 @@ function createEnvironmentLoader(root, rpc) {
25
27
  hmr: false,
26
28
  sourcemapInterceptor: "prepareStackTrace",
27
29
  transport: new VitestTransport({
30
+ // Vite's evaluator and module graph read the source map from the code
31
+ inlineSourceMap: true,
28
32
  async fetchModule(id, importer, options) {
29
33
  const result = await rpc.fetch(id, importer, "__vitest__", options);
30
- if ("cached" in result) return {
31
- code: readFileSync(result.tmp, "utf-8"),
32
- ...result
33
- };
34
+ if ("cached" in result) {
35
+ const { code, sourceMap } = splitSourceMap(readFileSync(result.tmp, "utf-8"));
36
+ return {
37
+ code,
38
+ sourceMap,
39
+ ...result
40
+ };
41
+ }
34
42
  if (isWindows && "externalize" in result)
35
43
  // TODO: vitest returns paths for external modules, but Vite returns file://
36
44
  // https://github.com/vitejs/vite/pull/20449
@@ -4,6 +4,17 @@ import { pathToFileURL } from 'node:url';
4
4
  const __require = createRequire(import.meta.url);
5
5
  let inspector;
6
6
  let session;
7
+ // separate from `inspector`, which is only set when Vitest opens the inspector itself
8
+ let inspectorUrl;
9
+ function isInspectorOpen() {
10
+ if (inspectorUrl === void 0) try {
11
+ inspectorUrl = __require("node:inspector").url;
12
+ } catch {
13
+ // node can be built without the inspector
14
+ inspectorUrl = null;
15
+ }
16
+ return inspectorUrl?.() !== void 0;
17
+ }
7
18
  /**
8
19
  * Enables debugging inside `worker_threads` and `child_process`.
9
20
  * Should be called as early as possible when worker/process has been set up.
@@ -50,4 +61,4 @@ function shouldKeepOpen(config) {
50
61
  return config.watch && config.isolate === false && config.maxWorkers === 1;
51
62
  }
52
63
 
53
- export { closeInspector as c, setupInspect as s };
64
+ export { closeInspector as c, isInspectorOpen as i, setupInspect as s };
@@ -1,4 +1,5 @@
1
1
  import { builtinModules } from 'node:module';
2
+ import { Buffer } from 'node:buffer';
2
3
 
3
4
  // copied from vite
4
5
  // https://github.com/vitejs/vite/blob/814120f2ad387ca3d1e16c7dd403b04ca4b97f75/packages/vite/src/node/utils.ts#L106
@@ -33,4 +34,33 @@ function toBuiltin(id) {
33
34
  return `node:${id}`;
34
35
  }
35
36
 
36
- export { isBrowserExternal as a, isBuiltin as i, toBuiltin as t };
37
+ let SOURCEMAPPING_URL = "sourceMa";
38
+ SOURCEMAPPING_URL += "ppingURL";
39
+ // the source map is stored after the code in the files that workers read,
40
+ // it is JSON without line breaks, so the last marker is always this one
41
+ const SOURCE_MAP_SEPARATOR = "\n//# vitestSourceMap=";
42
+ function appendSourceMap(content, sourceMap) {
43
+ return `${content}${SOURCE_MAP_SEPARATOR}${sourceMap ?? ""}`;
44
+ }
45
+ function splitSourceMap(content) {
46
+ const index = content.lastIndexOf(SOURCE_MAP_SEPARATOR);
47
+ if (index === -1) return {
48
+ code: content,
49
+ sourceMap: void 0
50
+ };
51
+ return {
52
+ code: content.slice(0, index),
53
+ sourceMap: content.slice(index + 21) || void 0
54
+ };
55
+ }
56
+ // debuggers read the source map from the comment in the compiled script
57
+ function withInlineSourceMap(result) {
58
+ const { code, sourceMap } = result;
59
+ if (code == null || !sourceMap) return result;
60
+ return {
61
+ ...result,
62
+ code: `${code}\n//# ${SOURCEMAPPING_URL}=data:application/json;base64,${Buffer.from(sourceMap).toString("base64")}\n`
63
+ };
64
+ }
65
+
66
+ export { isBrowserExternal as a, appendSourceMap as b, isBuiltin as i, splitSourceMap as s, toBuiltin as t, withInlineSourceMap as w };
@@ -7,8 +7,9 @@ import { p as parse } from './acorn.C1kjbUFw.js';
7
7
  import MagicString from 'magic-string';
8
8
  import { $ } from './tinyrainbow.Do8I1XRG.js';
9
9
  import { distDir } from '../path.js';
10
- import { t as toBuiltin } from './modules.BJuCwlRJ.js';
10
+ import { t as toBuiltin } from './moduleSourceMap.Dp1WduWi.js';
11
11
  import 'node:path';
12
+ import 'node:buffer';
12
13
 
13
14
  const NOW_LENGTH = Date.now().toString().length;
14
15
  const REGEXP_VITEST = new RegExp(`%3Fvitest=\\d{${NOW_LENGTH}}`);
@@ -3,9 +3,11 @@ import { fileURLToPath, pathToFileURL } from 'node:url';
3
3
  import { automockModule, createManualModuleSource, collectModuleExports } from '@vitest/mocker/transforms';
4
4
  import { c as cleanUrl, e as createDefer, i as isAbsolute } from './pathe.M-eThtNZ.zq3TM4NT.js';
5
5
  import { p as parse } from './acorn.C1kjbUFw.js';
6
- import { t as toBuiltin } from './modules.BJuCwlRJ.js';
7
- import { B as BareModuleMocker, n as normalizeModuleId } from './index.Bi0NXYPf.js';
6
+ import { t as toBuiltin } from './moduleSourceMap.Dp1WduWi.js';
7
+ import { B as BareModuleMocker, n as normalizeModuleId } from './index.C7Nn66Gy.js';
8
+ import 'node:buffer';
8
9
  import 'node:fs';
10
+ import './inspector.D6o1NPo1.js';
9
11
  import './utils.DYj33du9.js';
10
12
  import '../path.js';
11
13
  import 'node:path';