vitest 4.0.0-beta.9 → 4.0.1

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 (83) hide show
  1. package/LICENSE.md +86 -102
  2. package/browser/context.d.ts +7 -0
  3. package/browser/context.js +20 -0
  4. package/dist/browser.d.ts +24 -7
  5. package/dist/browser.js +15 -5
  6. package/dist/chunks/{base.CA5N8Af0.js → base.BYPMk0VN.js} +36 -36
  7. package/dist/chunks/{benchmark.CJUa-Hsa.js → benchmark.DHKMYAts.js} +2 -2
  8. package/dist/chunks/{browser.d.DtfyY9yS.d.ts → browser.d.B9iJzZyn.d.ts} +3 -3
  9. package/dist/chunks/{cac.Dt7e1TIu.js → cac.DrF4Gm0S.js} +47 -73
  10. package/dist/chunks/{cli-api.eAzsLIxz.js → cli-api.W2Q-JQoO.js} +1524 -296
  11. package/dist/chunks/{config.d.DacWrqWe.d.ts → config.d.u2CUDWwS.d.ts} +5 -19
  12. package/dist/chunks/{console.7h5kHUIf.js → console.CTJL2nuH.js} +4 -6
  13. package/dist/chunks/{coverage.CDRAMTt7.js → coverage.FU3w4IrQ.js} +125 -1108
  14. package/dist/chunks/{creator.KEg6n5IC.js → creator.DucAaYBz.js} +10 -37
  15. package/dist/chunks/{defaults.CXFFjsi8.js → defaults.BOqNVLsY.js} +0 -1
  16. package/dist/chunks/environment.d.CrsxCzP1.d.ts +29 -0
  17. package/dist/chunks/evaluatedModules.Dg1zASAC.js +17 -0
  18. package/dist/chunks/{global.d.K6uBQHzY.d.ts → global.d.BgJSTpgQ.d.ts} +2 -17
  19. package/dist/chunks/{globals.CJrTTbxC.js → globals.BGT_RUsD.js} +11 -7
  20. package/dist/chunks/{index.BjKEiSn0.js → index.BdSLhLDZ.js} +3 -3
  21. package/dist/chunks/{index.DfviD7lX.js → index.CbWINfS7.js} +49 -21
  22. package/dist/chunks/{index.BIP7prJq.js → index.CcRZ6fUh.js} +1493 -114
  23. package/dist/chunks/{index.X0nbfr6-.js → index.Dc3xnDvT.js} +48 -289
  24. package/dist/chunks/{index.C832ioot.js → index.RwjEGCQ0.js} +4 -4
  25. package/dist/chunks/init-forks.WglB-sfY.js +54 -0
  26. package/dist/chunks/init-threads.Czek6eA5.js +17 -0
  27. package/dist/chunks/init.94FWN9pW.js +213 -0
  28. package/dist/chunks/{inspector.CvQD-Nie.js → inspector.DLZxSeU3.js} +2 -6
  29. package/dist/chunks/{moduleRunner.d.DxTLreRD.d.ts → moduleRunner.d.YtNsMIoJ.d.ts} +9 -14
  30. package/dist/chunks/{node.CyipiPvJ.js → node.BwAWWjHZ.js} +3 -4
  31. package/dist/chunks/{plugin.d.CIk0YiKb.d.ts → plugin.d.DQU1R5px.d.ts} +1 -1
  32. package/dist/chunks/{reporters.d.DmP-iHLr.d.ts → reporters.d.BMKt7f6I.d.ts} +1064 -1021
  33. package/dist/chunks/{resolveSnapshotEnvironment.Bvv2zr69.js → resolveSnapshotEnvironment.DJJKMKxb.js} +7 -8
  34. package/dist/chunks/{rpc.BKr6mtxz.js → rpc.cD77ENhU.js} +13 -14
  35. package/dist/chunks/{setup-common.B7I37Tji.js → setup-common.DR1sucx6.js} +6 -6
  36. package/dist/chunks/{startModuleRunner.BDRvKSdz.js → startModuleRunner.iF1E9Bt4.js} +126 -110
  37. package/dist/chunks/{test.BAlBebnP.js → test.C3RPt8JR.js} +7 -7
  38. package/dist/chunks/{utils.D2R2NiOH.js → utils.CG9h5ccR.js} +2 -5
  39. package/dist/chunks/{vi.BB37KeLx.js → vi.BZvkKVkM.js} +61 -164
  40. package/dist/chunks/{vm.CjLTDaST.js → vm.CuMWYx_F.js} +20 -29
  41. package/dist/chunks/{worker.d.B2r4Ln6p.d.ts → worker.d.BFk-vvBU.d.ts} +42 -6
  42. package/dist/cli.js +12 -11
  43. package/dist/config.cjs +0 -1
  44. package/dist/config.d.ts +11 -13
  45. package/dist/config.js +1 -1
  46. package/dist/coverage.d.ts +7 -6
  47. package/dist/coverage.js +3 -14
  48. package/dist/environments.d.ts +3 -6
  49. package/dist/environments.js +1 -1
  50. package/dist/index.d.ts +20 -25
  51. package/dist/index.js +11 -7
  52. package/dist/module-evaluator.d.ts +5 -4
  53. package/dist/module-evaluator.js +11 -13
  54. package/dist/module-runner.js +5 -5
  55. package/dist/node.d.ts +82 -25
  56. package/dist/node.js +23 -20
  57. package/dist/reporters.d.ts +10 -9
  58. package/dist/reporters.js +12 -11
  59. package/dist/runners.d.ts +1 -1
  60. package/dist/runners.js +9 -7
  61. package/dist/snapshot.js +3 -3
  62. package/dist/suite.js +4 -3
  63. package/dist/worker.d.ts +26 -0
  64. package/dist/worker.js +45 -165
  65. package/dist/workers/forks.js +26 -43
  66. package/dist/workers/runVmTests.js +16 -12
  67. package/dist/workers/threads.js +26 -31
  68. package/dist/workers/vmForks.js +26 -39
  69. package/dist/workers/vmThreads.js +26 -29
  70. package/package.json +48 -32
  71. package/worker.d.ts +1 -0
  72. package/browser.d.ts +0 -1
  73. package/dist/chunks/environment.d.2fYMoz3o.d.ts +0 -66
  74. package/dist/chunks/moduleTransport.I-bgQy0S.js +0 -19
  75. package/dist/chunks/resolver.Bx6lE0iq.js +0 -119
  76. package/dist/chunks/typechecker.DB-fIMaH.js +0 -805
  77. package/dist/chunks/utils.C2YI6McM.js +0 -52
  78. package/dist/chunks/worker.d.DJ6qxO2w.d.ts +0 -8
  79. package/dist/workers.d.ts +0 -38
  80. package/dist/workers.js +0 -49
  81. package/execute.d.ts +0 -1
  82. package/utils.d.ts +0 -1
  83. package/workers.d.ts +0 -1
@@ -1,9 +1,9 @@
1
- import { toArray } from '@vitest/utils';
1
+ import { toArray } from '@vitest/utils/helpers';
2
2
  import { EventEmitter } from 'events';
3
3
  import { normalize } from 'pathe';
4
4
  import c from 'tinyrainbow';
5
5
  import { a as defaultPort, d as defaultBrowserPort } from './constants.D_Q9UYh-.js';
6
- import { R as ReportersMap } from './index.BIP7prJq.js';
6
+ import { R as ReportersMap } from './index.CcRZ6fUh.js';
7
7
 
8
8
  function toArr(any) {
9
9
  return any == null ? [] : Array.isArray(any) ? any : [any];
@@ -619,7 +619,7 @@ class CAC extends EventEmitter {
619
619
 
620
620
  const cac = (name = "") => new CAC(name);
621
621
 
622
- var version = "4.0.0-beta.9";
622
+ var version = "4.0.1";
623
623
 
624
624
  const apiConfig = (port) => ({
625
625
  port: {
@@ -632,24 +632,7 @@ const apiConfig = (port) => ({
632
632
  },
633
633
  strictPort: { description: "Set to true to exit if port is already in use, instead of automatically trying the next available port" },
634
634
  middlewareMode: null
635
- }), poolThreadsCommands = {
636
- isolate: { description: "Isolate tests in threads pool (default: `true`)" },
637
- singleThread: { description: "Run tests inside a single thread (default: `false`)" },
638
- maxThreads: {
639
- description: "Maximum number or percentage of threads to run tests in",
640
- argument: "<workers>"
641
- },
642
- useAtomics: { description: "Use Atomics to synchronize threads. This can improve performance in some cases, but might cause segfault in older Node versions (default: `false`)" },
643
- execArgv: null
644
- }, poolForksCommands = {
645
- isolate: { description: "Isolate tests in forks pool (default: `true`)" },
646
- singleFork: { description: "Run tests inside a single child_process (default: `false`)" },
647
- maxForks: {
648
- description: "Maximum number or percentage of processes to run tests in",
649
- argument: "<workers>"
650
- },
651
- execArgv: null
652
- };
635
+ });
653
636
  function watermarkTransform(value) {
654
637
  return typeof value === "string" ? value.split(",").map(Number) : value;
655
638
  }
@@ -758,7 +741,14 @@ const cliOptionsConfig = {
758
741
  argument: "",
759
742
  subcommands: {
760
743
  perFile: { description: "Check thresholds per file. See `--coverage.thresholds.lines`, `--coverage.thresholds.functions`, `--coverage.thresholds.branches` and `--coverage.thresholds.statements` for the actual thresholds (default: `false`)" },
761
- autoUpdate: { description: "Update threshold values: \"lines\", \"functions\", \"branches\" and \"statements\" to configuration file when current coverage is above the configured thresholds (default: `false`)" },
744
+ autoUpdate: {
745
+ description: "Update threshold values: \"lines\", \"functions\", \"branches\" and \"statements\" to configuration file when current coverage is above the configured thresholds (default: `false`)",
746
+ argument: "<boolean|function>",
747
+ subcommands: null,
748
+ transform(value) {
749
+ return value === "true" || value === "yes" || value === true ? true : value === "false" || value === "no" || value === false ? false : value;
750
+ }
751
+ },
762
752
  lines: {
763
753
  description: "Threshold for lines. Visit [istanbuljs](https://github.com/istanbuljs/nyc#coverage-thresholds) for more information. This option is not available for custom providers",
764
754
  argument: "<number>"
@@ -848,12 +838,19 @@ const cliOptionsConfig = {
848
838
  provider: {
849
839
  description: "Provider used to run browser tests. Some browsers are only available for specific providers. Can be \"webdriverio\", \"playwright\", \"preview\", or the path to a custom provider. Visit [`browser.provider`](https://vitest.dev/guide/browser/config.html#browser-provider) for more information (default: `\"preview\"`)",
850
840
  argument: "<name>",
851
- subcommands: null
852
- },
853
- providerOptions: {
854
- description: "Options that are passed down to a browser provider. Visit [`browser.providerOptions`](https://vitest.dev/config/#browser-provideroptions) for more information",
855
- argument: "<options>",
856
- subcommands: null
841
+ subcommands: null,
842
+ transform(value) {
843
+ const supported = [
844
+ "playwright",
845
+ "webdriverio",
846
+ "preview"
847
+ ];
848
+ if (typeof value !== "string" || !supported.includes(value)) throw new Error(`Unsupported browser provider: ${value}. Supported providers are: ${supported.join(", ")}`);
849
+ return {
850
+ name: value,
851
+ _cli: true
852
+ };
853
+ }
857
854
  },
858
855
  isolate: { description: "Run every browser test file in isolation. To disable isolation, use `--browser.isolate=false` (default: `true`)" },
859
856
  ui: { description: "Show Vitest UI when running tests (default: `!process.env.CI`)" },
@@ -863,6 +860,14 @@ const cliOptionsConfig = {
863
860
  argument: "<timeout>"
864
861
  },
865
862
  trackUnhandledErrors: { description: "Control if Vitest catches uncaught exceptions so they can be reported (default: `true`)" },
863
+ trace: {
864
+ description: "Enable trace view mode. Supported: \"on\", \"off\", \"on-first-retry\", \"on-all-retries\", \"retain-on-failure\".",
865
+ argument: "<mode>",
866
+ subcommands: null,
867
+ transform(value) {
868
+ return { mode: value };
869
+ }
870
+ },
866
871
  orchestratorScripts: null,
867
872
  commands: null,
868
873
  viewport: null,
@@ -879,43 +884,13 @@ const cliOptionsConfig = {
879
884
  argument: "<pool>",
880
885
  subcommands: null
881
886
  },
882
- poolOptions: {
883
- description: "Specify pool options",
884
- argument: "<options>",
885
- subcommands: {
886
- threads: {
887
- description: "Specify threads pool options",
888
- argument: "<options>",
889
- subcommands: poolThreadsCommands
890
- },
891
- vmThreads: {
892
- description: "Specify VM threads pool options",
893
- argument: "<options>",
894
- subcommands: {
895
- ...poolThreadsCommands,
896
- memoryLimit: {
897
- description: "Memory limit for VM threads pool. If you see memory leaks, try to tinker this value.",
898
- argument: "<limit>"
899
- }
900
- }
901
- },
902
- forks: {
903
- description: "Specify forks pool options",
904
- argument: "<options>",
905
- subcommands: poolForksCommands
906
- },
907
- vmForks: {
908
- description: "Specify VM forks pool options",
909
- argument: "<options>",
910
- subcommands: {
911
- ...poolForksCommands,
912
- memoryLimit: {
913
- description: "Memory limit for VM forks pool. If you see memory leaks, try to tinker this value.",
914
- argument: "<limit>"
915
- }
916
- }
917
- }
918
- }
887
+ execArgv: {
888
+ description: "Pass additional arguments to `node` process when spawning `worker_threads` or `child_process`.",
889
+ argument: "<option>"
890
+ },
891
+ vmMemoryLimit: {
892
+ description: "Memory limit for VM pools. If you see memory leaks, try to tinker this value.",
893
+ argument: "<limit>"
919
894
  },
920
895
  fileParallelism: { description: "Should all test files run in parallel. Use `--no-file-parallelism` to disable (default: `true`)" },
921
896
  maxWorkers: {
@@ -1279,11 +1254,10 @@ function createCLI(options = {}) {
1279
1254
  }), cli.command("run [...filters]", void 0, options).action(run), cli.command("related [...filters]", void 0, options).action(runRelated), cli.command("watch [...filters]", void 0, options).action(watch), cli.command("dev [...filters]", void 0, options).action(watch), addCliOptions(cli.command("bench [...filters]", void 0, options).action(benchmark), benchCliOptionsConfig), cli.command("init <project>", void 0, options).action(init), addCliOptions(cli.command("list [...filters]", void 0, options).action((filters, options) => collect("test", filters, options)), collectCliOptionsConfig), cli.command("[...filters]", void 0, options).action((filters, options) => start("test", filters, options)), cli;
1280
1255
  }
1281
1256
  function removeQuotes(str) {
1282
- return typeof str === "string" ? str.startsWith("\"") && str.endsWith("\"") || str.startsWith(`'`) && str.endsWith(`'`) ? str.slice(1, -1) : str : Array.isArray(str) ? str.map(removeQuotes) : str;
1257
+ return typeof str === "string" ? str[0] === "\"" && str.endsWith("\"") || str.startsWith(`'`) && str.endsWith(`'`) ? str.slice(1, -1) : str : Array.isArray(str) ? str.map(removeQuotes) : str;
1283
1258
  }
1284
1259
  function splitArgv(argv) {
1285
- const reg = /(['"])(?:(?!\1).)+\1/g;
1286
- return argv = argv.replace(reg, (match) => match.replace(/\s/g, "\0")), argv.split(" ").map((arg) => {
1260
+ return argv = argv.replace(/(['"])(?:(?!\1).)+\1/g, (match) => match.replace(/\s/g, "\0")), argv.split(" ").map((arg) => {
1287
1261
  return arg = arg.replace(/\0/g, " "), removeQuotes(arg);
1288
1262
  });
1289
1263
  }
@@ -1320,22 +1294,22 @@ function normalizeCliOptions(cliFilters, argv) {
1320
1294
  }
1321
1295
  async function start(mode, cliFilters, options) {
1322
1296
  try {
1323
- const { startVitest } = await import('./cli-api.eAzsLIxz.js').then(function (n) { return n.j; }), ctx = await startVitest(mode, cliFilters.map(normalize), normalizeCliOptions(cliFilters, options));
1297
+ const { startVitest } = await import('./cli-api.W2Q-JQoO.js').then(function (n) { return n.p; }), ctx = await startVitest(mode, cliFilters.map(normalize), normalizeCliOptions(cliFilters, options));
1324
1298
  if (!ctx.shouldKeepServer()) await ctx.exit();
1325
1299
  } catch (e) {
1326
- const { errorBanner } = await import('./index.BIP7prJq.js').then(function (n) { return n.u; });
1300
+ const { errorBanner } = await import('./index.CcRZ6fUh.js').then(function (n) { return n.u; });
1327
1301
  if (console.error(`\n${errorBanner("Startup Error")}`), console.error(e), console.error("\n\n"), process.exitCode == null) process.exitCode = 1;
1328
1302
  process.exit();
1329
1303
  }
1330
1304
  }
1331
1305
  async function init(project) {
1332
1306
  if (project !== "browser") console.error(/* @__PURE__ */ new Error("Only the \"browser\" project is supported. Use \"vitest init browser\" to create a new project.")), process.exit(1);
1333
- const { create } = await import('./creator.KEg6n5IC.js');
1307
+ const { create } = await import('./creator.DucAaYBz.js');
1334
1308
  await create();
1335
1309
  }
1336
1310
  async function collect(mode, cliFilters, options) {
1337
1311
  try {
1338
- const { prepareVitest, processCollected, outputFileList } = await import('./cli-api.eAzsLIxz.js').then(function (n) { return n.j; }), ctx = await prepareVitest(mode, {
1312
+ const { prepareVitest, processCollected, outputFileList } = await import('./cli-api.W2Q-JQoO.js').then(function (n) { return n.p; }), ctx = await prepareVitest(mode, {
1339
1313
  ...normalizeCliOptions(cliFilters, options),
1340
1314
  watch: false,
1341
1315
  run: true
@@ -1353,7 +1327,7 @@ async function collect(mode, cliFilters, options) {
1353
1327
  }
1354
1328
  await ctx.close();
1355
1329
  } catch (e) {
1356
- const { errorBanner } = await import('./index.BIP7prJq.js').then(function (n) { return n.u; });
1330
+ const { errorBanner } = await import('./index.CcRZ6fUh.js').then(function (n) { return n.u; });
1357
1331
  if (console.error(`\n${errorBanner("Collect Error")}`), console.error(e), console.error("\n\n"), process.exitCode == null) process.exitCode = 1;
1358
1332
  process.exit();
1359
1333
  }