vitest 3.2.0-beta.3 → 3.2.0

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 (65) hide show
  1. package/LICENSE.md +29 -0
  2. package/dist/browser.d.ts +1 -1
  3. package/dist/browser.js +2 -2
  4. package/dist/chunks/{base.D4119yLM.js → base.Cg0miDlQ.js} +10 -14
  5. package/dist/chunks/{benchmark.Cf_PACH1.js → benchmark.CYdenmiT.js} +4 -6
  6. package/dist/chunks/{cac.DWaWHIIE.js → cac.6rXCxFY1.js} +66 -136
  7. package/dist/chunks/{cli-api.CnmEXkxs.js → cli-api.Cej3MBjA.js} +1250 -1335
  8. package/dist/chunks/{console.Cwr-MFPV.js → console.CtFJOzRO.js} +24 -45
  9. package/dist/chunks/{coverage.0iPg4Wrz.js → coverage.DVF1vEu8.js} +4 -12
  10. package/dist/chunks/{coverage.C73DaDgS.js → coverage.EIiagJJP.js} +484 -1003
  11. package/dist/chunks/{creator.C8WKy2eW.js → creator.GK6I-cL4.js} +29 -76
  12. package/dist/chunks/{date.ByMsSlOr.js → date.Bq6ZW5rf.js} +3 -8
  13. package/dist/chunks/{defaults.DpVH7vbg.js → defaults.B7q_naMc.js} +1 -1
  14. package/dist/chunks/{env.Dq0hM4Xv.js → env.D4Lgay0q.js} +1 -1
  15. package/dist/chunks/{execute.B3q-2LPV.js → execute.B7h3T_Hc.js} +104 -220
  16. package/dist/chunks/{git.DXfdBEfR.js → git.BVQ8w_Sw.js} +1 -3
  17. package/dist/chunks/{global.d.BNLIi6yo.d.ts → global.d.MAmajcmJ.d.ts} +2 -0
  18. package/dist/chunks/{globals.CI21aWXF.js → globals.DEHgCU4V.js} +5 -5
  19. package/dist/chunks/{index.Bter3jj9.js → index.BZ0g1JD2.js} +366 -628
  20. package/dist/chunks/{index.CbT4iuwc.js → index.BbB8_kAK.js} +22 -24
  21. package/dist/chunks/{index.JOzufsrU.js → index.CIyJn3t1.js} +37 -82
  22. package/dist/chunks/{index.DNgLEKsQ.js → index.CdQS2e2Q.js} +2 -2
  23. package/dist/chunks/{index.2jgTs_Q5.js → index.CmSc2RE5.js} +69 -107
  24. package/dist/chunks/{inspector.BFsh5KO0.js → inspector.C914Efll.js} +1 -1
  25. package/dist/chunks/{node.Be-ntJnD.js → node.fjCdwEIl.js} +1 -1
  26. package/dist/chunks/{reporters.d.Bt4IGtsa.d.ts → reporters.d.C1ogPriE.d.ts} +24 -4
  27. package/dist/chunks/{rpc.BKExFSRG.js → rpc.Iovn4oWe.js} +9 -19
  28. package/dist/chunks/{runBaseTests.B_M1TTsK.js → runBaseTests.Dd85QTll.js} +18 -31
  29. package/dist/chunks/{setup-common.CF-O-dZX.js → setup-common.Dd054P77.js} +15 -42
  30. package/dist/chunks/{typechecker.BgzF-6iO.js → typechecker.DRKU1-1g.js} +106 -186
  31. package/dist/chunks/{utils.DPCq3gzW.js → utils.CAioKnHs.js} +6 -14
  32. package/dist/chunks/{utils.BlI4TC7Y.js → utils.XdZDrNZV.js} +5 -13
  33. package/dist/chunks/{vi.pkoYCV6A.js → vi.bdSIJ99Y.js} +118 -267
  34. package/dist/chunks/{vite.d.B-Kx3KCF.d.ts → vite.d.DqE4-hhK.d.ts} +1 -1
  35. package/dist/chunks/{vm.DPYem2so.js → vm.BThCzidc.js} +98 -214
  36. package/dist/chunks/{worker.d.Bl1O4kuf.d.ts → worker.d.DvqK5Vmu.d.ts} +1 -1
  37. package/dist/chunks/{worker.d.BKbBp2ga.d.ts → worker.d.tQu2eJQy.d.ts} +3 -1
  38. package/dist/cli.js +4 -4
  39. package/dist/config.cjs +1 -1
  40. package/dist/config.d.ts +4 -4
  41. package/dist/config.js +2 -2
  42. package/dist/coverage.d.ts +2 -2
  43. package/dist/coverage.js +5 -5
  44. package/dist/environments.js +1 -1
  45. package/dist/execute.d.ts +1 -1
  46. package/dist/execute.js +1 -1
  47. package/dist/index.d.ts +11 -10
  48. package/dist/index.js +5 -5
  49. package/dist/node.d.ts +7 -7
  50. package/dist/node.js +12 -14
  51. package/dist/reporters.d.ts +2 -2
  52. package/dist/reporters.js +4 -4
  53. package/dist/runners.d.ts +5 -2
  54. package/dist/runners.js +51 -80
  55. package/dist/snapshot.js +2 -2
  56. package/dist/suite.js +2 -2
  57. package/dist/worker.js +36 -42
  58. package/dist/workers/forks.js +4 -4
  59. package/dist/workers/runVmTests.js +15 -21
  60. package/dist/workers/threads.js +4 -4
  61. package/dist/workers/vmForks.js +6 -6
  62. package/dist/workers/vmThreads.js +6 -6
  63. package/dist/workers.d.ts +2 -2
  64. package/dist/workers.js +10 -10
  65. package/package.json +16 -14
@@ -23,11 +23,14 @@ function convertTasksToEvents(file, onTask) {
23
23
  suite.result,
24
24
  suite.meta
25
25
  ]);
26
- events.push([suite.id, "suite-prepare"]);
26
+ events.push([
27
+ suite.id,
28
+ "suite-prepare",
29
+ void 0
30
+ ]);
27
31
  suite.tasks.forEach((task) => {
28
- if (task.type === "suite") {
29
- visit(task);
30
- } else {
32
+ if (task.type === "suite") visit(task);
33
+ else {
31
34
  onTask?.(task);
32
35
  if (suite.mode !== "skip" && suite.mode !== "todo") {
33
36
  packs.push([
@@ -35,11 +38,31 @@ function convertTasksToEvents(file, onTask) {
35
38
  task.result,
36
39
  task.meta
37
40
  ]);
38
- events.push([task.id, "test-prepare"], [task.id, "test-finished"]);
41
+ events.push([
42
+ task.id,
43
+ "test-prepare",
44
+ void 0
45
+ ]);
46
+ task.annotations.forEach((annotation) => {
47
+ events.push([
48
+ task.id,
49
+ "test-annotation",
50
+ { annotation }
51
+ ]);
52
+ });
53
+ events.push([
54
+ task.id,
55
+ "test-finished",
56
+ void 0
57
+ ]);
39
58
  }
40
59
  }
41
60
  });
42
- events.push([suite.id, "suite-finished"]);
61
+ events.push([
62
+ suite.id,
63
+ "suite-finished",
64
+ void 0
65
+ ]);
43
66
  }
44
67
  visit(file);
45
68
  return {
@@ -50,12 +73,8 @@ function convertTasksToEvents(file, onTask) {
50
73
 
51
74
  const REGEXP_WRAP_PREFIX = "$$vitest:";
52
75
  function getOutputFile(config, reporter) {
53
- if (!config?.outputFile) {
54
- return;
55
- }
56
- if (typeof config.outputFile === "string") {
57
- return config.outputFile;
58
- }
76
+ if (!config?.outputFile) return;
77
+ if (typeof config.outputFile === "string") return config.outputFile;
59
78
  return config.outputFile[reporter];
60
79
  }
61
80
  /**
@@ -65,16 +84,12 @@ function wrapSerializableConfig(config) {
65
84
  let testNamePattern = config.testNamePattern;
66
85
  let defines = config.defines;
67
86
  // v8 serialize does not support regex
68
- if (testNamePattern && typeof testNamePattern !== "string") {
69
- testNamePattern = `${REGEXP_WRAP_PREFIX}${testNamePattern.toString()}`;
70
- }
87
+ if (testNamePattern && typeof testNamePattern !== "string") testNamePattern = `${REGEXP_WRAP_PREFIX}${testNamePattern.toString()}`;
71
88
  // v8 serialize drops properties with undefined value
72
- if (defines) {
73
- defines = {
74
- keys: Object.keys(defines),
75
- original: defines
76
- };
77
- }
89
+ if (defines) defines = {
90
+ keys: Object.keys(defines),
91
+ original: defines
92
+ };
78
93
  return {
79
94
  ...config,
80
95
  testNamePattern,
@@ -360,9 +375,7 @@ base.MethodDefinition = base.PropertyDefinition = base.Property = function (node
360
375
 
361
376
  async function collectTests(ctx, filepath) {
362
377
  const request = await ctx.vitenode.transformRequest(filepath, filepath);
363
- if (!request) {
364
- return null;
365
- }
378
+ if (!request) return null;
366
379
  const ast = await parseAstAsync(request.code);
367
380
  const testFilepath = relative(ctx.config.root, filepath);
368
381
  const projectName = ctx.name;
@@ -383,57 +396,39 @@ async function collectTests(ctx, filepath) {
383
396
  file.file = file;
384
397
  const definitions = [];
385
398
  const getName = (callee) => {
386
- if (!callee) {
387
- return null;
388
- }
389
- if (callee.type === "Identifier") {
390
- return callee.name;
391
- }
392
- if (callee.type === "CallExpression") {
393
- return getName(callee.callee);
394
- }
395
- if (callee.type === "TaggedTemplateExpression") {
396
- return getName(callee.tag);
397
- }
399
+ if (!callee) return null;
400
+ if (callee.type === "Identifier") return callee.name;
401
+ if (callee.type === "CallExpression") return getName(callee.callee);
402
+ if (callee.type === "TaggedTemplateExpression") return getName(callee.tag);
398
403
  if (callee.type === "MemberExpression") {
399
404
  if (callee.object?.type === "Identifier" && [
400
405
  "it",
401
406
  "test",
402
407
  "describe",
403
408
  "suite"
404
- ].includes(callee.object.name)) {
405
- return callee.object?.name;
406
- }
409
+ ].includes(callee.object.name)) return callee.object?.name;
407
410
  // direct call as `__vite_ssr_exports_0__.test()`
408
- if (callee.object?.name?.startsWith("__vite_ssr_")) {
409
- return getName(callee.property);
410
- }
411
+ if (callee.object?.name?.startsWith("__vite_ssr_")) return getName(callee.property);
411
412
  // call as `__vite_ssr__.test.skip()`
412
413
  return getName(callee.object?.property);
413
414
  }
414
415
  // unwrap (0, ...)
415
416
  if (callee.type === "SequenceExpression" && callee.expressions.length === 2) {
416
417
  const [e0, e1] = callee.expressions;
417
- if (e0.type === "Literal" && e0.value === 0) {
418
- return getName(e1);
419
- }
418
+ if (e0.type === "Literal" && e0.value === 0) return getName(e1);
420
419
  }
421
420
  return null;
422
421
  };
423
422
  ancestor(ast, { CallExpression(node) {
424
423
  const { callee } = node;
425
424
  const name = getName(callee);
426
- if (!name) {
427
- return;
428
- }
425
+ if (!name) return;
429
426
  if (![
430
427
  "it",
431
428
  "test",
432
429
  "describe",
433
430
  "suite"
434
- ].includes(name)) {
435
- return;
436
- }
431
+ ].includes(name)) return;
437
432
  const property = callee?.property?.name;
438
433
  let mode = !property || property === name ? "run" : property;
439
434
  // they will be picked up in the next iteration
@@ -442,26 +437,18 @@ async function collectTests(ctx, filepath) {
442
437
  "for",
443
438
  "skipIf",
444
439
  "runIf"
445
- ].includes(mode)) {
446
- return;
447
- }
440
+ ].includes(mode)) return;
448
441
  let start;
449
442
  const end = node.end;
450
443
  // .each
451
- if (callee.type === "CallExpression") {
452
- start = callee.end;
453
- } else if (callee.type === "TaggedTemplateExpression") {
454
- start = callee.end + 1;
455
- } else {
456
- start = node.start;
457
- }
444
+ if (callee.type === "CallExpression") start = callee.end;
445
+ else if (callee.type === "TaggedTemplateExpression") start = callee.end + 1;
446
+ else start = node.start;
458
447
  const { arguments: [messageNode] } = node;
459
448
  const isQuoted = messageNode?.type === "Literal" || messageNode?.type === "TemplateLiteral";
460
449
  const message = isQuoted ? request.code.slice(messageNode.start + 1, messageNode.end - 1) : request.code.slice(messageNode.start, messageNode.end);
461
450
  // cannot statically analyze, so we always skip it
462
- if (mode === "skipIf" || mode === "runIf") {
463
- mode = "skip";
464
- }
451
+ if (mode === "skipIf" || mode === "runIf") mode = "skip";
465
452
  definitions.push({
466
453
  start,
467
454
  end,
@@ -473,18 +460,15 @@ async function collectTests(ctx, filepath) {
473
460
  } });
474
461
  let lastSuite = file;
475
462
  const updateLatestSuite = (index) => {
476
- while (lastSuite.suite && lastSuite.end < index) {
477
- lastSuite = lastSuite.suite;
478
- }
463
+ while (lastSuite.suite && lastSuite.end < index) lastSuite = lastSuite.suite;
479
464
  return lastSuite;
480
465
  };
481
466
  definitions.sort((a, b) => a.start - b.start).forEach((definition) => {
482
467
  const latestSuite = updateLatestSuite(definition.start);
483
468
  let mode = definition.mode;
484
- if (latestSuite.mode !== "run") {
485
- // inherit suite mode, if it's set
486
- mode = latestSuite.mode;
487
- }
469
+ if (latestSuite.mode !== "run")
470
+ // inherit suite mode, if it's set
471
+ mode = latestSuite.mode;
488
472
  if (definition.type === "suite") {
489
473
  const task = {
490
474
  type: definition.type,
@@ -514,6 +498,7 @@ async function collectTests(ctx, filepath) {
514
498
  name: definition.name,
515
499
  end: definition.end,
516
500
  start: definition.start,
501
+ annotations: [],
517
502
  meta: { typecheck: true }
518
503
  };
519
504
  definition.task = task;
@@ -521,7 +506,7 @@ async function collectTests(ctx, filepath) {
521
506
  });
522
507
  calculateSuiteHash(file);
523
508
  const hasOnly = someTasksAreOnly(file);
524
- interpretTaskModes(file, ctx.config.testNamePattern, undefined, hasOnly, false, ctx.config.allowOnly);
509
+ interpretTaskModes(file, ctx.config.testNamePattern, void 0, hasOnly, false, ctx.config.allowOnly);
525
510
  return {
526
511
  file,
527
512
  parsed: request.code,
@@ -535,28 +520,18 @@ const newLineRegExp = /\r?\n/;
535
520
  const errCodeRegExp = /error TS(?<errCode>\d+)/;
536
521
  async function makeTscErrorInfo(errInfo) {
537
522
  const [errFilePathPos = "", ...errMsgRawArr] = errInfo.split(":");
538
- if (!errFilePathPos || errMsgRawArr.length === 0 || errMsgRawArr.join("").length === 0) {
539
- return ["unknown filepath", null];
540
- }
523
+ if (!errFilePathPos || errMsgRawArr.length === 0 || errMsgRawArr.join("").length === 0) return ["unknown filepath", null];
541
524
  const errMsgRaw = errMsgRawArr.join("").trim();
542
525
  // get filePath, line, col
543
526
  const [errFilePath, errPos] = errFilePathPos.slice(0, -1).split("(");
544
- if (!errFilePath || !errPos) {
545
- return ["unknown filepath", null];
546
- }
527
+ if (!errFilePath || !errPos) return ["unknown filepath", null];
547
528
  const [errLine, errCol] = errPos.split(",");
548
- if (!errLine || !errCol) {
549
- return [errFilePath, null];
550
- }
529
+ if (!errLine || !errCol) return [errFilePath, null];
551
530
  // get errCode, errMsg
552
531
  const execArr = errCodeRegExp.exec(errMsgRaw);
553
- if (!execArr) {
554
- return [errFilePath, null];
555
- }
532
+ if (!execArr) return [errFilePath, null];
556
533
  const errCodeStr = execArr.groups?.errCode ?? "";
557
- if (!errCodeStr) {
558
- return [errFilePath, null];
559
- }
534
+ if (!errCodeStr) return [errFilePath, null];
560
535
  const line = Number(errLine);
561
536
  const col = Number(errCol);
562
537
  const errCode = Number(errCodeStr);
@@ -569,33 +544,24 @@ async function makeTscErrorInfo(errInfo) {
569
544
  }];
570
545
  }
571
546
  async function getRawErrsMapFromTsCompile(tscErrorStdout) {
572
- const rawErrsMap = new Map();
547
+ const rawErrsMap = /* @__PURE__ */ new Map();
573
548
  // Merge details line with main line (i.e. which contains file path)
574
549
  const infos = await Promise.all(tscErrorStdout.split(newLineRegExp).reduce((prev, next) => {
575
- if (!next) {
576
- return prev;
577
- } else if (!next.startsWith(" ")) {
578
- prev.push(next);
579
- } else {
580
- prev[prev.length - 1] += `\n${next}`;
581
- }
550
+ if (!next) return prev;
551
+ else if (!next.startsWith(" ")) prev.push(next);
552
+ else prev[prev.length - 1] += `\n${next}`;
582
553
  return prev;
583
554
  }, []).map((errInfoLine) => makeTscErrorInfo(errInfoLine)));
584
555
  infos.forEach(([errFilePath, errInfo]) => {
585
- if (!errInfo) {
586
- return;
587
- }
588
- if (!rawErrsMap.has(errFilePath)) {
589
- rawErrsMap.set(errFilePath, [errInfo]);
590
- } else {
591
- rawErrsMap.get(errFilePath)?.push(errInfo);
592
- }
556
+ if (!errInfo) return;
557
+ if (!rawErrsMap.has(errFilePath)) rawErrsMap.set(errFilePath, [errInfo]);
558
+ else rawErrsMap.get(errFilePath)?.push(errInfo);
593
559
  });
594
560
  return rawErrsMap;
595
561
  }
596
562
 
597
563
  function createIndexMap(source) {
598
- const map = new Map();
564
+ const map = /* @__PURE__ */ new Map();
599
565
  let index = 0;
600
566
  let line = 1;
601
567
  let column = 1;
@@ -604,9 +570,7 @@ function createIndexMap(source) {
604
570
  if (char === "\n" || char === "\r\n") {
605
571
  line++;
606
572
  column = 0;
607
- } else {
608
- column++;
609
- }
573
+ } else column++;
610
574
  }
611
575
  return map;
612
576
  }
@@ -656,9 +620,7 @@ class Typechecker {
656
620
  }
657
621
  async collectTests() {
658
622
  const tests = (await Promise.all(this.getFiles().map((filepath) => this.collectFileTests(filepath)))).reduce((acc, data) => {
659
- if (!data) {
660
- return acc;
661
- }
623
+ if (!data) return acc;
662
624
  acc[data.filepath] = data;
663
625
  return acc;
664
626
  }, {});
@@ -666,17 +628,11 @@ class Typechecker {
666
628
  return tests;
667
629
  }
668
630
  markPassed(file) {
669
- if (!file.result?.state) {
670
- file.result = { state: "pass" };
671
- }
631
+ if (!file.result?.state) file.result = { state: "pass" };
672
632
  const markTasks = (tasks) => {
673
633
  for (const task of tasks) {
674
- if ("tasks" in task) {
675
- markTasks(task.tasks);
676
- }
677
- if (!task.result?.state && (task.mode === "run" || task.mode === "queued")) {
678
- task.result = { state: "pass" };
679
- }
634
+ if ("tasks" in task) markTasks(task.tasks);
635
+ if (!task.result?.state && (task.mode === "run" || task.mode === "queued")) task.result = { state: "pass" };
680
636
  }
681
637
  };
682
638
  markTasks(file.tasks);
@@ -684,9 +640,7 @@ class Typechecker {
684
640
  async prepareResults(output) {
685
641
  const typeErrors = await this.parseTscLikeOutput(output);
686
642
  const testFiles = new Set(this.getFiles());
687
- if (!this._tests) {
688
- this._tests = await this.collectTests();
689
- }
643
+ if (!this._tests) this._tests = await this.collectTests();
690
644
  const sourceErrors = [];
691
645
  const files = [];
692
646
  testFiles.forEach((path) => {
@@ -703,11 +657,8 @@ class Typechecker {
703
657
  const indexMap = createIndexMap(parsed);
704
658
  const markState = (task, state) => {
705
659
  task.result = { state: task.mode === "run" || task.mode === "only" ? state : task.mode };
706
- if (task.suite) {
707
- markState(task.suite, state);
708
- } else if (task.file && task !== task.file) {
709
- markState(task.file, state);
710
- }
660
+ if (task.suite) markState(task.suite, state);
661
+ else if (task.file && task !== task.file) markState(task.file, state);
711
662
  };
712
663
  errors.forEach(({ error, originalError }) => {
713
664
  const processedPos = traceMap ? findGeneratedPosition(traceMap, {
@@ -728,19 +679,14 @@ class Typechecker {
728
679
  };
729
680
  errors.push(error);
730
681
  if (state === "fail") {
731
- if (suite.suite) {
732
- markState(suite.suite, "fail");
733
- } else if (suite.file && suite !== suite.file) {
734
- markState(suite.file, "fail");
735
- }
682
+ if (suite.suite) markState(suite.suite, "fail");
683
+ else if (suite.file && suite !== suite.file) markState(suite.file, "fail");
736
684
  }
737
685
  });
738
686
  this.markPassed(file);
739
687
  });
740
688
  typeErrors.forEach((errors, path) => {
741
- if (!testFiles.has(path)) {
742
- sourceErrors.push(...errors.map(({ error }) => error));
743
- }
689
+ if (!testFiles.has(path)) sourceErrors.push(...errors.map(({ error }) => error));
744
690
  });
745
691
  return {
746
692
  files,
@@ -750,7 +696,7 @@ class Typechecker {
750
696
  }
751
697
  async parseTscLikeOutput(output) {
752
698
  const errorsMap = await getRawErrsMapFromTsCompile(output);
753
- const typesErrors = new Map();
699
+ const typesErrors = /* @__PURE__ */ new Map();
754
700
  errorsMap.forEach((errors, path) => {
755
701
  const filepath = resolve(this.project.config.root, path);
756
702
  const suiteErrors = errors.map((info) => {
@@ -769,11 +715,9 @@ class Typechecker {
769
715
  originalError: info,
770
716
  error: {
771
717
  name: error.name,
772
- nameStr: String(error.name),
773
718
  message: errMsg,
774
719
  stacks: error.stacks,
775
- stack: "",
776
- stackStr: ""
720
+ stack: ""
777
721
  }
778
722
  };
779
723
  });
@@ -783,12 +727,10 @@ class Typechecker {
783
727
  }
784
728
  async stop() {
785
729
  this.process?.kill();
786
- this.process = undefined;
730
+ this.process = void 0;
787
731
  }
788
732
  async ensurePackageInstalled(ctx, checker) {
789
- if (checker !== "tsc" && checker !== "vue-tsc") {
790
- return;
791
- }
733
+ if (checker !== "tsc" && checker !== "vue-tsc") return;
792
734
  const packageName = checker === "tsc" ? "typescript" : "vue-tsc";
793
735
  await ctx.packageInstaller.ensureInstalled(packageName, ctx.config.root);
794
736
  }
@@ -809,15 +751,9 @@ class Typechecker {
809
751
  join(process.versions.pnp ? join(nodeos__default.tmpdir(), this.project.hash) : distDir, "tsconfig.tmp.tsbuildinfo")
810
752
  ];
811
753
  // use builtin watcher because it's faster
812
- if (watch) {
813
- args.push("--watch");
814
- }
815
- if (typecheck.allowJs) {
816
- args.push("--allowJs", "--checkJs");
817
- }
818
- if (typecheck.tsconfig) {
819
- args.push("-p", resolve(root, typecheck.tsconfig));
820
- }
754
+ if (watch) args.push("--watch");
755
+ if (typecheck.allowJs) args.push("--allowJs", "--checkJs");
756
+ if (typecheck.tsconfig) args.push("-p", resolve(root, typecheck.tsconfig));
821
757
  this._output = "";
822
758
  this._startTime = performance.now();
823
759
  const child = x(typecheck.checker, args, {
@@ -838,9 +774,7 @@ class Typechecker {
838
774
  child.process.stdout.on("data", (chunk) => {
839
775
  dataReceived = true;
840
776
  this._output += chunk;
841
- if (!watch) {
842
- return;
843
- }
777
+ if (!watch) return;
844
778
  if (this._output.includes("File change detected") && !rerunTriggered) {
845
779
  this._onWatcherRerun?.();
846
780
  this._startTime = performance.now();
@@ -867,31 +801,23 @@ class Typechecker {
867
801
  this._onParseStart?.();
868
802
  child.process?.off("error", onError);
869
803
  clearTimeout(timeout);
870
- if (process.platform === "win32") {
871
- // on Windows, the process might be spawned but fail to start
872
- // we wait for a potential error here. if "close" event didn't trigger,
873
- // we resolve the promise
874
- setTimeout(() => {
875
- resolve({ result: child });
876
- }, 200);
877
- } else {
804
+ if (process.platform === "win32")
805
+ // on Windows, the process might be spawned but fail to start
806
+ // we wait for a potential error here. if "close" event didn't trigger,
807
+ // we resolve the promise
808
+ setTimeout(() => {
878
809
  resolve({ result: child });
879
- }
810
+ }, 200);
811
+ else resolve({ result: child });
812
+ });
813
+ if (process.platform === "win32") child.process.once("close", (code) => {
814
+ if (code != null && code !== 0 && !dataReceived) onError(new Error(`The ${typecheck.checker} command exited with code ${code}.`));
880
815
  });
881
- if (process.platform === "win32") {
882
- child.process.once("close", (code) => {
883
- if (code != null && code !== 0 && !dataReceived) {
884
- onError(new Error(`The ${typecheck.checker} command exited with code ${code}.`));
885
- }
886
- });
887
- }
888
816
  child.process.once("error", onError);
889
817
  });
890
818
  }
891
819
  async start() {
892
- if (this.process) {
893
- return;
894
- }
820
+ if (this.process) return;
895
821
  const { watch } = this.project.config;
896
822
  const { result: child } = await this.spawn();
897
823
  if (!watch) {
@@ -926,25 +852,19 @@ function findGeneratedPosition(traceMap, { line, column, source }) {
926
852
  column,
927
853
  source
928
854
  });
929
- if (found.line !== null) {
930
- return found;
931
- }
855
+ if (found.line !== null) return found;
932
856
  // find the next source token position when the exact error position doesn't exist in source map.
933
857
  // this can happen, for example, when the type error is in the comment "// @ts-expect-error"
934
858
  // and comments are stripped away in the generated code.
935
859
  const mappings = [];
936
860
  eachMapping(traceMap, (m) => {
937
- if (m.source === source && m.originalLine !== null && m.originalColumn !== null && (line === m.originalLine ? column < m.originalColumn : line < m.originalLine)) {
938
- mappings.push(m);
939
- }
861
+ if (m.source === source && m.originalLine !== null && m.originalColumn !== null && (line === m.originalLine ? column < m.originalColumn : line < m.originalLine)) mappings.push(m);
940
862
  });
941
863
  const next = mappings.sort((a, b) => a.originalLine === b.originalLine ? a.originalColumn - b.originalColumn : a.originalLine - b.originalLine).at(0);
942
- if (next) {
943
- return {
944
- line: next.generatedLine,
945
- column: next.generatedColumn
946
- };
947
- }
864
+ if (next) return {
865
+ line: next.generatedLine,
866
+ column: next.generatedColumn
867
+ };
948
868
  return {
949
869
  line: null,
950
870
  column: null
@@ -17,11 +17,9 @@ function createThreadsRpcOptions({ port }) {
17
17
  };
18
18
  }
19
19
  function disposeInternalListeners() {
20
- for (const fn of dispose) {
21
- try {
22
- fn();
23
- } catch {}
24
- }
20
+ for (const fn of dispose) try {
21
+ fn();
22
+ } catch {}
25
23
  dispose.length = 0;
26
24
  }
27
25
  function createForksRpcOptions(nodeV8) {
@@ -34,9 +32,7 @@ function createForksRpcOptions(nodeV8) {
34
32
  on(fn) {
35
33
  const handler = (message, ...extras) => {
36
34
  // Do not react on Tinypool's internal messaging
37
- if (message?.__tinypool_worker_message__) {
38
- return;
39
- }
35
+ if (message?.__tinypool_worker_message__) return;
40
36
  return fn(message, ...extras);
41
37
  };
42
38
  processOn("message", handler);
@@ -50,17 +46,13 @@ function createForksRpcOptions(nodeV8) {
50
46
  function unwrapSerializableConfig(config) {
51
47
  if (config.testNamePattern && typeof config.testNamePattern === "string") {
52
48
  const testNamePattern = config.testNamePattern;
53
- if (testNamePattern.startsWith(REGEXP_WRAP_PREFIX)) {
54
- config.testNamePattern = parseRegexp(testNamePattern.slice(REGEXP_WRAP_PREFIX.length));
55
- }
49
+ if (testNamePattern.startsWith(REGEXP_WRAP_PREFIX)) config.testNamePattern = parseRegexp(testNamePattern.slice(REGEXP_WRAP_PREFIX.length));
56
50
  }
57
51
  if (config.defines && Array.isArray(config.defines.keys) && config.defines.original) {
58
52
  const { keys, original } = config.defines;
59
53
  const defines = {};
60
54
  // Apply all keys from the original. Entries which had undefined value are missing from original now
61
- for (const key of keys) {
62
- defines[key] = original[key];
63
- }
55
+ for (const key of keys) defines[key] = original[key];
64
56
  config.defines = defines;
65
57
  }
66
58
  return config;
@@ -5,7 +5,7 @@ function getWorkerState() {
5
5
  // @ts-expect-error untyped global
6
6
  const workerState = globalThis[NAME_WORKER_STATE];
7
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";
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
9
  throw new Error(errorMsg);
10
10
  }
11
11
  return workerState;
@@ -40,9 +40,7 @@ function resetModules(modules, resetMocks = false) {
40
40
  ...!resetMocks ? [/^mock:/] : []
41
41
  ];
42
42
  modules.forEach((mod, path) => {
43
- if (skipPaths.some((re) => re.test(path))) {
44
- return;
45
- }
43
+ if (skipPaths.some((re) => re.test(path))) return;
46
44
  modules.invalidateModule(mod);
47
45
  });
48
46
  }
@@ -56,16 +54,10 @@ async function waitForImportsToResolve() {
56
54
  const promises = [];
57
55
  let resolvingCount = 0;
58
56
  for (const mod of state.moduleCache.values()) {
59
- if (mod.promise && !mod.evaluated) {
60
- promises.push(mod.promise);
61
- }
62
- if (mod.resolving) {
63
- resolvingCount++;
64
- }
65
- }
66
- if (!promises.length && !resolvingCount) {
67
- return;
57
+ if (mod.promise && !mod.evaluated) promises.push(mod.promise);
58
+ if (mod.resolving) resolvingCount++;
68
59
  }
60
+ if (!promises.length && !resolvingCount) return;
69
61
  await Promise.allSettled(promises);
70
62
  await waitForImportsToResolve();
71
63
  }