vitest 4.0.0-beta.11 → 4.0.0-beta.12

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 (55) hide show
  1. package/LICENSE.md +4 -101
  2. package/dist/browser.d.ts +3 -3
  3. package/dist/browser.js +2 -2
  4. package/dist/chunks/{benchmark.LXhJ0F0X.js → benchmark.DHKMYAts.js} +1 -1
  5. package/dist/chunks/{browser.d.Dx7DO_Ce.d.ts → browser.d.D9YV3JvA.d.ts} +1 -1
  6. package/dist/chunks/{cac.elvK37c9.js → cac.r1gel_VZ.js} +16 -9
  7. package/dist/chunks/{cli-api.C7plPyhs.js → cli-api.CpywZzJV.js} +95 -148
  8. package/dist/chunks/{config.d.B_LthbQq.d.ts → config.d.DGazh2r6.d.ts} +3 -1
  9. package/dist/chunks/{console.CiTi59Jy.js → console.CTJL2nuH.js} +3 -5
  10. package/dist/chunks/{coverage.CG6Uhorw.js → coverage.CiB0fs_7.js} +44 -62
  11. package/dist/chunks/{creator.08Gi-vCA.js → creator.DfXDsUyL.js} +6 -8
  12. package/dist/chunks/{global.d.BK3X7FW1.d.ts → global.d.BcFPD2LN.d.ts} +0 -13
  13. package/dist/chunks/{globals.BjvYA-AD.js → globals.DC4ntO86.js} +5 -5
  14. package/dist/chunks/{index.DIWhzsUh.js → index.Bt-upxGS.js} +6 -12
  15. package/dist/chunks/{index.BwBttQPf.js → index.CHrBLuEH.js} +33 -38
  16. package/dist/chunks/{index.X0nbfr6-.js → index.Dc3xnDvT.js} +48 -289
  17. package/dist/chunks/{index.AZOjjqWP.js → index.Dnl38iQ_.js} +2 -2
  18. package/dist/chunks/{index.BhY64fF0.js → index.uLUz1RDt.js} +1 -1
  19. package/dist/chunks/{inspector.CvQD-Nie.js → inspector.Br76Q2Mb.js} +1 -4
  20. package/dist/chunks/{moduleRunner.d.BNa-CL9e.d.ts → moduleRunner.d.CeYc7nZ0.d.ts} +1 -1
  21. package/dist/chunks/{node.BsdMi6DV.js → node.BwAWWjHZ.js} +2 -3
  22. package/dist/chunks/{plugin.d.C5phQR6o.d.ts → plugin.d.XreRXLXS.d.ts} +1 -1
  23. package/dist/chunks/{reporters.d.CVzhsTvK.d.ts → reporters.d.CJVTaaWb.d.ts} +39 -3
  24. package/dist/chunks/{resolveSnapshotEnvironment.DQVamkje.js → resolveSnapshotEnvironment.BsJpmVZR.js} +7 -8
  25. package/dist/chunks/{rpc.jKGRSXIH.js → rpc.cD77ENhU.js} +12 -13
  26. package/dist/chunks/{setup-common.NAWRuMRP.js → setup-common.BewgbkTd.js} +5 -5
  27. package/dist/chunks/{startModuleRunner.oAuCu1yL.js → startModuleRunner.DPBo3mme.js} +40 -48
  28. package/dist/chunks/{test.KC5tH8hC.js → test.CTuWuHYH.js} +5 -5
  29. package/dist/chunks/{typechecker.gXq-5P3n.js → typechecker.BfOQ86_a.js} +54 -77
  30. package/dist/chunks/{utils.DGKhod2J.js → utils.CG9h5ccR.js} +1 -4
  31. package/dist/chunks/{vi.CiJ0Laa6.js → vi.B2--mG9U.js} +35 -144
  32. package/dist/chunks/{worker.rPGLlbkW.js → worker.DVTUM2IW.js} +11 -15
  33. package/dist/chunks/{worker.d.B_Fd9M_w.d.ts → worker.d.buwuBpBt.d.ts} +1 -1
  34. package/dist/cli.js +3 -3
  35. package/dist/config.d.ts +6 -6
  36. package/dist/coverage.d.ts +5 -5
  37. package/dist/coverage.js +3 -3
  38. package/dist/environments.js +1 -1
  39. package/dist/index.d.ts +8 -8
  40. package/dist/index.js +5 -5
  41. package/dist/module-evaluator.d.ts +3 -3
  42. package/dist/module-evaluator.js +10 -12
  43. package/dist/module-runner.js +2 -2
  44. package/dist/node.d.ts +8 -8
  45. package/dist/node.js +10 -10
  46. package/dist/reporters.d.ts +5 -5
  47. package/dist/reporters.js +3 -3
  48. package/dist/runners.d.ts +1 -1
  49. package/dist/runners.js +6 -6
  50. package/dist/snapshot.js +2 -2
  51. package/dist/suite.js +2 -2
  52. package/dist/worker-base.js +30 -32
  53. package/dist/worker-vm.js +19 -30
  54. package/dist/workers/runVmTests.js +10 -10
  55. package/package.json +18 -19
@@ -28,8 +28,8 @@ const _UNC_REGEX = /^[/\\]{2}/, _IS_ABSOLUTE_RE = /^[/\\](?![/\\])|^[/\\]{2}(?!\
28
28
  for (const seg of segments) {
29
29
  if (!seg) continue;
30
30
  if (path.length > 0) {
31
- const pathTrailing = path[path.length - 1] === "/", segLeading = seg[0] === "/", both = pathTrailing && segLeading;
32
- if (both) path += seg.slice(1);
31
+ const pathTrailing = path[path.length - 1] === "/", segLeading = seg[0] === "/";
32
+ if (pathTrailing && segLeading) path += seg.slice(1);
33
33
  else path += pathTrailing || segLeading ? seg : `/${seg}`;
34
34
  } else path += seg;
35
35
  }
@@ -114,17 +114,14 @@ function findMockRedirect(root, mockPath, external) {
114
114
  const baseOriginal = basename(path);
115
115
  function findFile(mockFolder, baseOriginal) {
116
116
  const files = readdirSync(mockFolder);
117
- for (const file of files) {
118
- const baseFile = basename(file, extname(file));
119
- if (baseFile === baseOriginal) {
120
- const path = resolve(mockFolder, file);
121
- // if the same name, return the file
122
- if (statSync(path).isFile()) return path;
123
- {
124
- // find folder/index.{js,ts}
125
- const indexFile = findFile(path, "index");
126
- if (indexFile) return indexFile;
127
- }
117
+ for (const file of files) if (basename(file, extname(file)) === baseOriginal) {
118
+ const path = resolve(mockFolder, file);
119
+ // if the same name, return the file
120
+ if (statSync(path).isFile()) return path;
121
+ {
122
+ // find folder/index.{js,ts}
123
+ const indexFile = findFile(path, "index");
124
+ if (indexFile) return indexFile;
128
125
  }
129
126
  }
130
127
  return null;
@@ -278,7 +275,7 @@ class VitestMocker {
278
275
  if (prop === "then") {
279
276
  if (target instanceof Promise) return target.then.bind(target);
280
277
  } else if (!(prop in target)) {
281
- if (this.filterPublicKeys.includes(prop)) return void 0;
278
+ if (this.filterPublicKeys.includes(prop)) return;
282
279
  throw this.createError(`[vitest] No "${String(prop)}" export is defined on the "${mock.raw}" mock. Did you forget to return it from "vi.mock"?
283
280
  If you need to partially mock a module, you can use "importOriginal" helper inside:
284
281
  `, `vi.mock(import("${mock.raw}"), async (importOriginal) => {
@@ -302,8 +299,7 @@ If you need to partially mock a module, you can use "importOriginal" helper insi
302
299
  return `mock:${dep}`;
303
300
  }
304
301
  getDependencyMock(id) {
305
- const registry = this.getMockerRegistry();
306
- return registry.getById(fixLeadingSlashes(id));
302
+ return this.getMockerRegistry().getById(fixLeadingSlashes(id));
307
303
  }
308
304
  findMockRedirect(mockPath, external) {
309
305
  return findMockRedirect(this.root, mockPath, external);
@@ -318,8 +314,7 @@ If you need to partially mock a module, you can use "importOriginal" helper insi
318
314
  }, object, mockExports);
319
315
  }
320
316
  unmockPath(id) {
321
- const registry = this.getMockerRegistry();
322
- registry.deleteById(id), this.invalidateModuleById(id);
317
+ this.getMockerRegistry().deleteById(id), this.invalidateModuleById(id);
323
318
  }
324
319
  mockPath(originalId, id, url, external, mockType, factory) {
325
320
  const registry = this.getMockerRegistry();
@@ -334,8 +329,8 @@ If you need to partially mock a module, you can use "importOriginal" helper insi
334
329
  this.invalidateModuleById(id);
335
330
  }
336
331
  async importActual(rawId, importer, callstack) {
337
- const { url } = await this.resolveId(rawId, importer), node = await this.moduleRunner.fetchModule(url, importer), result = await this.moduleRunner.cachedRequest(node.url, node, callstack || [importer], void 0, true);
338
- return result;
332
+ const { url } = await this.resolveId(rawId, importer), node = await this.moduleRunner.fetchModule(url, importer);
333
+ return await this.moduleRunner.cachedRequest(node.url, node, callstack || [importer], void 0, true);
339
334
  }
340
335
  async importMock(rawId, importer) {
341
336
  const { id, url, external } = await this.resolveId(rawId, importer);
@@ -420,11 +415,8 @@ const prefixedBuiltins = new Set([
420
415
  // C:\root\id.js -> /id.js
421
416
  // TODO: expose this in vite/module-runner
422
417
  function normalizeModuleId(file) {
423
- if (prefixedBuiltins.has(file)) return file;
424
- // unix style, but Windows path still starts with the drive letter to check the root
425
- const unixFile = slash(file).replace(/^\/@fs\//, isWindows$1 ? "" : "/").replace(/^node:/, "").replace(/^\/+/, "/");
426
418
  // if it's not in the root, keep it as a path, not a URL
427
- return unixFile.replace(/^file:\//, "/");
419
+ return prefixedBuiltins.has(file) ? file : slash(file).replace(/^\/@fs\//, isWindows$1 ? "" : "/").replace(/^node:/, "").replace(/^\/+/, "/").replace(/^file:\//, "/");
428
420
  }
429
421
  const windowsSlashRE = /\\/g;
430
422
  function slash(p) {
@@ -446,17 +438,27 @@ class VitestTransport {
446
438
  const { name, data } = event.data;
447
439
  if (name !== "fetchModule") return { error: /* @__PURE__ */ new Error(`Unknown method: ${name}. Expected "fetchModule".`) };
448
440
  try {
449
- const result = await this.options.fetchModule(...data);
450
- return { result };
441
+ return { result: await this.options.fetchModule(...data) };
451
442
  } catch (error) {
452
443
  return { error };
453
444
  }
454
445
  }
455
446
  }
456
447
 
457
- // eslint-disable-next-line ts/ban-ts-comment
458
- // @ts-ignore
459
- const createNodeImportMeta = viteModuleRunner.createNodeImportMeta;
448
+ const createNodeImportMeta = (modulePath) => {
449
+ if (!viteModuleRunner.createDefaultImportMeta) throw new Error(`createNodeImportMeta is not supported in this version of Vite.`);
450
+ const defaultMeta = viteModuleRunner.createDefaultImportMeta(modulePath), href = defaultMeta.url, importMetaResolver = createImportMetaResolver();
451
+ return {
452
+ ...defaultMeta,
453
+ main: false,
454
+ resolve(id, parent) {
455
+ return (importMetaResolver ?? defaultMeta.resolve)(id, parent ?? href);
456
+ }
457
+ };
458
+ };
459
+ function createImportMetaResolver() {
460
+ if (import.meta.resolve) return (specifier, importer) => import.meta.resolve(specifier, importer);
461
+ }
460
462
  // @ts-expect-error overriding private method
461
463
  class VitestModuleRunner extends viteModuleRunner.ModuleRunner {
462
464
  mocker;
@@ -491,11 +493,10 @@ class VitestModuleRunner extends viteModuleRunner.ModuleRunner {
491
493
  }
492
494
  async import(rawId) {
493
495
  const resolved = await this.vitestOptions.transport.resolveId(rawId);
494
- return resolved ? super.import(resolved.url) : super.import(rawId);
496
+ return super.import(resolved ? resolved.url : rawId);
495
497
  }
496
498
  async fetchModule(url, importer) {
497
- const module = await this.cachedModule(url, importer);
498
- return module;
499
+ return await this.cachedModule(url, importer);
499
500
  }
500
501
  _cachedRequest(url, module, callstack = [], metadata) {
501
502
  // @ts-expect-error "cachedRequest" is private
@@ -564,10 +565,10 @@ const dispose = [];
564
565
  function listenForErrors(state) {
565
566
  dispose.forEach((fn) => fn()), dispose.length = 0;
566
567
  function catchError(err, type, event) {
567
- const worker = state(), listeners = process.listeners(event);
568
+ const worker = state();
568
569
  // if there is another listener, assume that it's handled by user code
569
570
  // one is Vitest's own listener
570
- if (listeners.length > 1) return;
571
+ if (process.listeners(event).length > 1) return;
571
572
  const error = serializeValue(err);
572
573
  if (typeof error === "object" && error != null) {
573
574
  if (error.VITEST_TEST_NAME = worker.current?.type === "test" ? worker.current.name : void 0, worker.filepath) error.VITEST_TEST_PATH = worker.filepath;
@@ -614,10 +615,7 @@ function startVitestModuleRunner(options) {
614
615
  if (isWindows) {
615
616
  if (id[1] === ":") {
616
617
  // The drive letter is different for whatever reason, we need to normalize it to CWD
617
- if (id[0] !== cwd[0] && id[0].toUpperCase() === cwd[0].toUpperCase()) {
618
- const isUpperCase = cwd[0].toUpperCase() === cwd[0];
619
- id = (isUpperCase ? id[0].toUpperCase() : id[0].toLowerCase()) + id.slice(1);
620
- }
618
+ if (id[0] !== cwd[0] && id[0].toUpperCase() === cwd[0].toUpperCase()) id = (cwd[0].toUpperCase() === cwd[0] ? id[0].toUpperCase() : id[0].toLowerCase()) + id.slice(1);
621
619
  // always mark absolute windows paths, otherwise Vite will externalize it
622
620
  id = `/@id/${id}`;
623
621
  }
@@ -642,14 +640,10 @@ function startVitestModuleRunner(options) {
642
640
  type: "builtin"
643
641
  };
644
642
  const result = await rpc().fetch(id, importer, environment(), options);
645
- if ("cached" in result) {
646
- const code = readFileSync(result.tmp, "utf-8");
647
- return {
648
- code,
649
- ...result
650
- };
651
- }
652
- return result;
643
+ return "cached" in result ? {
644
+ code: readFileSync(result.tmp, "utf-8"),
645
+ ...result
646
+ } : result;
653
647
  } catch (cause) {
654
648
  // rethrow vite error if it cannot load the module because it's not resolved
655
649
  if (typeof cause === "object" && cause != null && cause.code === "ERR_LOAD_URL" || typeof cause?.message === "string" && cause.message.includes("Failed to load url") || typeof cause?.message === "string" && cause.message.startsWith("Cannot find module '")) {
@@ -669,8 +663,6 @@ function startVitestModuleRunner(options) {
669
663
  vm,
670
664
  createImportMeta: options.createImportMeta
671
665
  });
672
- // await moduleRunner.import('/@vite/env')
673
- // await moduleRunner.mocker.initializeSpyModule()
674
666
  return moduleRunner;
675
667
  }
676
668
  function toBuiltin(id) {
@@ -1,14 +1,14 @@
1
1
  import { updateTask } from '@vitest/runner';
2
2
  import { createDefer } from '@vitest/utils/helpers';
3
3
  import { getSafeTimers } from '@vitest/utils/timers';
4
- import { a as getBenchOptions, g as getBenchFn } from './benchmark.LXhJ0F0X.js';
5
- import { g as getWorkerState } from './utils.DGKhod2J.js';
4
+ import { a as getBenchOptions, g as getBenchFn } from './benchmark.DHKMYAts.js';
5
+ import { g as getWorkerState } from './utils.CG9h5ccR.js';
6
6
  import { setState, GLOBAL_EXPECT, getState } from '@vitest/expect';
7
7
  import { getTests, getNames, getTestName } from '@vitest/runner/utils';
8
8
  import { processError } from '@vitest/utils/error';
9
9
  import { normalize } from 'pathe';
10
- import { a as getSnapshotClient, i as inject, c as createExpect, v as vi } from './vi.CiJ0Laa6.js';
11
- import { r as rpc } from './rpc.jKGRSXIH.js';
10
+ import { a as getSnapshotClient, i as inject, c as createExpect, v as vi } from './vi.B2--mG9U.js';
11
+ import { r as rpc } from './rpc.cD77ENhU.js';
12
12
 
13
13
  function createBenchmarkResult(name) {
14
14
  return {
@@ -37,7 +37,7 @@ async function runBenchmarkSuite(suite, runner) {
37
37
  }, updateTask$1("suite-prepare", suite);
38
38
  const addBenchTaskListener = (task, benchmark) => {
39
39
  task.addEventListener("complete", (e) => {
40
- const task = e.task, taskRes = task.result, result = benchmark.result.benchmark;
40
+ const taskRes = e.task.result, result = benchmark.result.benchmark;
41
41
  benchmark.result.state = "pass", Object.assign(result, taskRes);
42
42
  // compute extra stats and free raw samples as early as possible
43
43
  const samples = result.samples;
@@ -30,9 +30,7 @@ function wrapSerializableConfig(config) {
30
30
  };
31
31
  }
32
32
  function createDefinesScript(define) {
33
- if (!define) return "";
34
- const serializedDefine = serializeDefine(define);
35
- return serializedDefine === "{}" ? "" : `
33
+ return !define || serializeDefine(define) === "{}" ? "" : `
36
34
  const defines = ${serializeDefine(define)}
37
35
  Object.keys(defines).forEach((key) => {
38
36
  const segments = key.split('.')
@@ -244,16 +242,6 @@ const urlRegex = /^([\w+.-]+:)\/\/([^@/#?]*@)?([^:/#?]*)(:\d+)?(\/[^#?]*)?(\?[^#
244
242
  * 4. Hash, including "#", optional.
245
243
  */
246
244
  const fileRegex = /^file:(?:\/\/((?![a-z]:)[^/#?]*)?)?(\/?[^#?]*)(\?[^#]*)?(#.*)?/i;
247
- var UrlType;
248
- (function (UrlType) {
249
- UrlType[UrlType["Empty"] = 1] = "Empty";
250
- UrlType[UrlType["Hash"] = 2] = "Hash";
251
- UrlType[UrlType["Query"] = 3] = "Query";
252
- UrlType[UrlType["RelativePath"] = 4] = "RelativePath";
253
- UrlType[UrlType["AbsolutePath"] = 5] = "AbsolutePath";
254
- UrlType[UrlType["SchemeRelative"] = 6] = "SchemeRelative";
255
- UrlType[UrlType["Absolute"] = 7] = "Absolute";
256
- })(UrlType || (UrlType = {}));
257
245
  function isAbsoluteUrl(input) {
258
246
  return schemeRegex.test(input);
259
247
  }
@@ -287,21 +275,21 @@ function makeUrl(scheme, user, host, port, path, query, hash) {
287
275
  path,
288
276
  query,
289
277
  hash,
290
- type: UrlType.Absolute,
278
+ type: 7 /* Absolute */,
291
279
  };
292
280
  }
293
281
  function parseUrl(input) {
294
282
  if (isSchemeRelativeUrl(input)) {
295
283
  const url = parseAbsoluteUrl('http:' + input);
296
284
  url.scheme = '';
297
- url.type = UrlType.SchemeRelative;
285
+ url.type = 6 /* SchemeRelative */;
298
286
  return url;
299
287
  }
300
288
  if (isAbsolutePath(input)) {
301
289
  const url = parseAbsoluteUrl('http://foo.com' + input);
302
290
  url.scheme = '';
303
291
  url.host = '';
304
- url.type = UrlType.AbsolutePath;
292
+ url.type = 5 /* AbsolutePath */;
305
293
  return url;
306
294
  }
307
295
  if (isFileUrl(input))
@@ -313,11 +301,11 @@ function parseUrl(input) {
313
301
  url.host = '';
314
302
  url.type = input
315
303
  ? input.startsWith('?')
316
- ? UrlType.Query
304
+ ? 3 /* Query */
317
305
  : input.startsWith('#')
318
- ? UrlType.Hash
319
- : UrlType.RelativePath
320
- : UrlType.Empty;
306
+ ? 2 /* Hash */
307
+ : 4 /* RelativePath */
308
+ : 1 /* Empty */;
321
309
  return url;
322
310
  }
323
311
  function stripPathFilename(path) {
@@ -345,7 +333,7 @@ function mergePaths(url, base) {
345
333
  * "foo/.". We need to normalize to a standard representation.
346
334
  */
347
335
  function normalizePath(url, type) {
348
- const rel = type <= UrlType.RelativePath;
336
+ const rel = type <= 4 /* RelativePath */;
349
337
  const pieces = url.path.split('/');
350
338
  // We need to preserve the first piece always, so that we output a leading slash. The item at
351
339
  // pieces[0] is an empty string.
@@ -406,27 +394,27 @@ function resolve(input, base) {
406
394
  return '';
407
395
  const url = parseUrl(input);
408
396
  let inputType = url.type;
409
- if (base && inputType !== UrlType.Absolute) {
397
+ if (base && inputType !== 7 /* Absolute */) {
410
398
  const baseUrl = parseUrl(base);
411
399
  const baseType = baseUrl.type;
412
400
  switch (inputType) {
413
- case UrlType.Empty:
401
+ case 1 /* Empty */:
414
402
  url.hash = baseUrl.hash;
415
403
  // fall through
416
- case UrlType.Hash:
404
+ case 2 /* Hash */:
417
405
  url.query = baseUrl.query;
418
406
  // fall through
419
- case UrlType.Query:
420
- case UrlType.RelativePath:
407
+ case 3 /* Query */:
408
+ case 4 /* RelativePath */:
421
409
  mergePaths(url, baseUrl);
422
410
  // fall through
423
- case UrlType.AbsolutePath:
411
+ case 5 /* AbsolutePath */:
424
412
  // The host, user, and port are joined, you can't copy one without the others.
425
413
  url.user = baseUrl.user;
426
414
  url.host = baseUrl.host;
427
415
  url.port = baseUrl.port;
428
416
  // fall through
429
- case UrlType.SchemeRelative:
417
+ case 6 /* SchemeRelative */:
430
418
  // The input doesn't have a schema at least, so we need to copy at least that over.
431
419
  url.scheme = baseUrl.scheme;
432
420
  }
@@ -438,10 +426,10 @@ function resolve(input, base) {
438
426
  switch (inputType) {
439
427
  // This is impossible, because of the empty checks at the start of the function.
440
428
  // case UrlType.Empty:
441
- case UrlType.Hash:
442
- case UrlType.Query:
429
+ case 2 /* Hash */:
430
+ case 3 /* Query */:
443
431
  return queryHash;
444
- case UrlType.RelativePath: {
432
+ case 4 /* RelativePath */: {
445
433
  // The first char is always a "/", and we need it to be relative.
446
434
  const path = url.path.slice(1);
447
435
  if (!path)
@@ -454,7 +442,7 @@ function resolve(input, base) {
454
442
  }
455
443
  return path + queryHash;
456
444
  }
457
- case UrlType.AbsolutePath:
445
+ case 5 /* AbsolutePath */:
458
446
  return url.path + queryHash;
459
447
  default:
460
448
  return url.scheme + '//' + url.user + url.host + url.port + url.path + queryHash;
@@ -518,6 +506,32 @@ function sortComparator(a, b) {
518
506
  return a[COLUMN] - b[COLUMN];
519
507
  }
520
508
 
509
+ // src/by-source.ts
510
+ function buildBySources(decoded, memos) {
511
+ const sources = memos.map(() => []);
512
+ for (let i = 0; i < decoded.length; i++) {
513
+ const line = decoded[i];
514
+ for (let j = 0; j < line.length; j++) {
515
+ const seg = line[j];
516
+ if (seg.length === 1) continue;
517
+ const sourceIndex2 = seg[SOURCES_INDEX];
518
+ const sourceLine = seg[SOURCE_LINE];
519
+ const sourceColumn = seg[SOURCE_COLUMN];
520
+ const source = sources[sourceIndex2];
521
+ const segs = source[sourceLine] || (source[sourceLine] = []);
522
+ segs.push([sourceColumn, i, seg[COLUMN]]);
523
+ }
524
+ }
525
+ for (let i = 0; i < sources.length; i++) {
526
+ const source = sources[i];
527
+ for (let j = 0; j < source.length; j++) {
528
+ const line = source[j];
529
+ if (line) line.sort(sortComparator);
530
+ }
531
+ }
532
+ return sources;
533
+ }
534
+
521
535
  // src/binary-search.ts
522
536
  var found = false;
523
537
  function binarySearch(haystack, needle, low, high) {
@@ -576,41 +590,6 @@ function memoizedBinarySearch(haystack, needle, state, key) {
576
590
  return state.lastIndex = binarySearch(haystack, needle, low, high);
577
591
  }
578
592
 
579
- // src/by-source.ts
580
- function buildBySources(decoded, memos) {
581
- const sources = memos.map(buildNullArray);
582
- for (let i = 0; i < decoded.length; i++) {
583
- const line = decoded[i];
584
- for (let j = 0; j < line.length; j++) {
585
- const seg = line[j];
586
- if (seg.length === 1) continue;
587
- const sourceIndex2 = seg[SOURCES_INDEX];
588
- const sourceLine = seg[SOURCE_LINE];
589
- const sourceColumn = seg[SOURCE_COLUMN];
590
- const originalSource = sources[sourceIndex2];
591
- const originalLine = originalSource[sourceLine] || (originalSource[sourceLine] = []);
592
- const memo = memos[sourceIndex2];
593
- let index = upperBound(
594
- originalLine,
595
- sourceColumn,
596
- memoizedBinarySearch(originalLine, sourceColumn, memo, sourceLine)
597
- );
598
- memo.lastIndex = ++index;
599
- insert(originalLine, index, [sourceColumn, i, seg[COLUMN]]);
600
- }
601
- }
602
- return sources;
603
- }
604
- function insert(array, index, value) {
605
- for (let i = array.length; i > index; i--) {
606
- array[i] = array[i - 1];
607
- }
608
- array[index] = value;
609
- }
610
- function buildNullArray() {
611
- return { __proto__: null };
612
- }
613
-
614
593
  // src/types.ts
615
594
  function parse(map) {
616
595
  return typeof map === "string" ? JSON.parse(map) : map;
@@ -735,7 +714,7 @@ function traceSegmentInternal(segments, memo, line, column, bias) {
735
714
  return index;
736
715
  }
737
716
  function generatedPosition(map, source, line, column, bias, all) {
738
- var _a;
717
+ var _a, _b;
739
718
  line--;
740
719
  if (line < 0) throw new Error(LINE_GTR_ZERO);
741
720
  if (column < 0) throw new Error(COL_GTR_EQ_ZERO);
@@ -743,13 +722,11 @@ function generatedPosition(map, source, line, column, bias, all) {
743
722
  let sourceIndex2 = sources.indexOf(source);
744
723
  if (sourceIndex2 === -1) sourceIndex2 = resolvedSources.indexOf(source);
745
724
  if (sourceIndex2 === -1) return all ? [] : GMapping(null, null);
746
- const generated = (_a = cast(map))._bySources || (_a._bySources = buildBySources(
747
- decodedMappings(map),
748
- cast(map)._bySourceMemos = sources.map(memoizedState)
749
- ));
725
+ const bySourceMemos = (_a = cast(map))._bySourceMemos || (_a._bySourceMemos = sources.map(memoizedState));
726
+ const generated = (_b = cast(map))._bySources || (_b._bySources = buildBySources(decodedMappings(map), bySourceMemos));
750
727
  const segments = generated[sourceIndex2][line];
751
728
  if (segments == null) return all ? [] : GMapping(null, null);
752
- const memo = cast(map)._bySourceMemos[sourceIndex2];
729
+ const memo = bySourceMemos[sourceIndex2];
753
730
  const index = traceSegmentInternal(segments, memo, line, column, bias);
754
731
  if (index === -1) return GMapping(null, null);
755
732
  const segment = segments[index];
@@ -1092,7 +1069,7 @@ async function collectTests(ctx, filepath) {
1092
1069
  if (callee.type === "CallExpression") start = callee.end;
1093
1070
  else if (callee.type === "TaggedTemplateExpression") start = callee.end + 1;
1094
1071
  else start = node.start;
1095
- const { arguments: [messageNode] } = node, isQuoted = messageNode?.type === "Literal" || messageNode?.type === "TemplateLiteral", message = isQuoted ? request.code.slice(messageNode.start + 1, messageNode.end - 1) : request.code.slice(messageNode.start, messageNode.end);
1072
+ const { arguments: [messageNode] } = node, message = messageNode?.type === "Literal" || messageNode?.type === "TemplateLiteral" ? request.code.slice(messageNode.start + 1, messageNode.end - 1) : request.code.slice(messageNode.start, messageNode.end);
1096
1073
  // cannot statically analyze, so we always skip it
1097
1074
  if (mode === "skipIf" || mode === "runIf") mode = "skip";
1098
1075
  definitions.push({
@@ -1180,13 +1157,13 @@ async function makeTscErrorInfo(errInfo) {
1180
1157
  }];
1181
1158
  }
1182
1159
  async function getRawErrsMapFromTsCompile(tscErrorStdout) {
1183
- const rawErrsMap = /* @__PURE__ */ new Map(), infos = await Promise.all(tscErrorStdout.split(newLineRegExp).reduce((prev, next) => {
1160
+ const rawErrsMap = /* @__PURE__ */ new Map();
1161
+ return (await Promise.all(tscErrorStdout.split(newLineRegExp).reduce((prev, next) => {
1184
1162
  if (!next) return prev;
1185
1163
  if (next[0] !== " ") prev.push(next);
1186
1164
  else prev[prev.length - 1] += `\n${next}`;
1187
1165
  return prev;
1188
- }, []).map((errInfoLine) => makeTscErrorInfo(errInfoLine)));
1189
- return infos.forEach(([errFilePath, errInfo]) => {
1166
+ }, []).map((errInfoLine) => makeTscErrorInfo(errInfoLine)))).forEach(([errFilePath, errInfo]) => {
1190
1167
  if (errInfo) if (!rawErrsMap.has(errFilePath)) rawErrsMap.set(errFilePath, [errInfo]);
1191
1168
  else rawErrsMap.get(errFilePath)?.push(errInfo);
1192
1169
  }), rawErrsMap;
@@ -4,10 +4,7 @@ const NAME_WORKER_STATE = "__vitest_worker__";
4
4
  function getWorkerState() {
5
5
  // @ts-expect-error untyped global
6
6
  const workerState = globalThis[NAME_WORKER_STATE];
7
- if (!workerState) {
8
- const errorMsg = "Vitest failed to access its internal state.\n\nOne of the following is possible:\n- \"vitest\" is imported directly without running \"vitest\" command\n- \"vitest\" is imported inside \"globalSetup\" (to fix this, use \"setupFiles\" instead, because \"globalSetup\" runs in a different context)\n- \"vitest\" is imported inside Vite / Vitest config file\n- Otherwise, it might be a Vitest bug. Please report it to https://github.com/vitest-dev/vitest/issues\n";
9
- throw new Error(errorMsg);
10
- }
7
+ if (!workerState) throw new Error("Vitest failed to access its internal state.\n\nOne of the following is possible:\n- \"vitest\" is imported directly without running \"vitest\" command\n- \"vitest\" is imported inside \"globalSetup\" (to fix this, use \"setupFiles\" instead, because \"globalSetup\" runs in a different context)\n- \"vitest\" is imported inside Vite / Vitest config file\n- Otherwise, it might be a Vitest bug. Please report it to https://github.com/vitest-dev/vitest/issues\n");
11
8
  return workerState;
12
9
  }
13
10
  function provideWorkerState(context, state) {