vitest 4.0.0-beta.8 → 4.0.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 (85) 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 +26 -9
  5. package/dist/browser.js +17 -7
  6. package/dist/chunks/base.CtHM3ryk.js +128 -0
  7. package/dist/chunks/{benchmark.UW6Ezvxy.js → benchmark.DHKMYAts.js} +2 -2
  8. package/dist/chunks/{browser.d.DOMmqJQx.d.ts → browser.d.B9iJzZyn.d.ts} +3 -3
  9. package/dist/chunks/{cac.By1HvRIk.js → cac.B99MQg-w.js} +47 -91
  10. package/dist/chunks/{cli-api.C-JHgQgp.js → cli-api.PwHwIMss.js} +1544 -310
  11. package/dist/chunks/{config.d._GBBbReY.d.ts → config.d.u2CUDWwS.d.ts} +6 -19
  12. package/dist/chunks/{console.B0quX7yH.js → console.CTJL2nuH.js} +4 -6
  13. package/dist/chunks/{coverage.DarITf6U.js → coverage.FU3w4IrQ.js} +128 -1142
  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.lgsmH00r.js → globals.BGT_RUsD.js} +12 -9
  20. package/dist/chunks/{index.BuwjkI-q.js → index.BdSLhLDZ.js} +3 -3
  21. package/dist/chunks/{index.DfviD7lX.js → index.CbWINfS7.js} +49 -21
  22. package/dist/chunks/{index.AzwzFtyi.js → index.CcRZ6fUh.js} +1493 -114
  23. package/dist/chunks/{index.X0nbfr6-.js → index.Dc3xnDvT.js} +48 -289
  24. package/dist/chunks/{index.AR8aAkCC.js → index.RwjEGCQ0.js} +7 -8
  25. package/dist/chunks/init-forks.DSafeltJ.js +54 -0
  26. package/dist/chunks/init-threads.SUtZ-067.js +17 -0
  27. package/dist/chunks/init.B2EESLQM.js +213 -0
  28. package/dist/chunks/{inspector.CvQD-Nie.js → inspector.DLZxSeU3.js} +2 -6
  29. package/dist/chunks/{moduleRunner.d.CX4DuqOx.d.ts → moduleRunner.d.YtNsMIoJ.d.ts} +12 -14
  30. package/dist/chunks/{node.BOqcT2jW.js → node.BwAWWjHZ.js} +3 -4
  31. package/dist/chunks/{plugin.d.CHe6slQs.d.ts → plugin.d.DQU1R5px.d.ts} +1 -1
  32. package/dist/chunks/{reporters.d.37tJQ2uV.d.ts → reporters.d.BMKt7f6I.d.ts} +1066 -1030
  33. package/dist/chunks/{index.CsFXYRkW.js → resolveSnapshotEnvironment.DJJKMKxb.js} +18 -24
  34. package/dist/chunks/{rpc.RpPylpp0.js → rpc.cD77ENhU.js} +13 -14
  35. package/dist/chunks/{setup-common.hLGRxhC8.js → setup-common.DR1sucx6.js} +8 -8
  36. package/dist/chunks/{startModuleRunner.C8TW8zTN.js → startModuleRunner.C2tTvmF9.js} +131 -110
  37. package/dist/chunks/test.C3RPt8JR.js +214 -0
  38. package/dist/chunks/{utils.C7__0Iv5.js → utils.CG9h5ccR.js} +3 -15
  39. package/dist/chunks/{vi.BfdOiD4j.js → vi.BZvkKVkM.js} +73 -176
  40. package/dist/chunks/{vm.BHBje7cC.js → vm.DBeOXrP9.js} +29 -33
  41. package/dist/chunks/{worker.d.DYlqbejz.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 +12 -14
  45. package/dist/config.js +1 -1
  46. package/dist/coverage.d.ts +8 -7
  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 +24 -30
  51. package/dist/index.js +12 -11
  52. package/dist/module-evaluator.d.ts +6 -4
  53. package/dist/module-evaluator.js +14 -16
  54. package/dist/module-runner.js +5 -5
  55. package/dist/node.d.ts +83 -27
  56. package/dist/node.js +23 -20
  57. package/dist/reporters.d.ts +11 -10
  58. package/dist/reporters.js +12 -11
  59. package/dist/runners.d.ts +1 -1
  60. package/dist/runners.js +14 -216
  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 -166
  65. package/dist/workers/forks.js +41 -35
  66. package/dist/workers/runVmTests.js +25 -22
  67. package/dist/workers/threads.js +41 -23
  68. package/dist/workers/vmForks.js +26 -39
  69. package/dist/workers/vmThreads.js +26 -29
  70. package/package.json +48 -35
  71. package/worker.d.ts +1 -0
  72. package/browser.d.ts +0 -1
  73. package/dist/chunks/base.BXI97p6t.js +0 -39
  74. package/dist/chunks/environment.d.2fYMoz3o.d.ts +0 -66
  75. package/dist/chunks/moduleTransport.I-bgQy0S.js +0 -19
  76. package/dist/chunks/resolver.Bx6lE0iq.js +0 -119
  77. package/dist/chunks/runBaseTests.D6sfuWBM.js +0 -99
  78. package/dist/chunks/typechecker.DSo_maXz.js +0 -762
  79. package/dist/chunks/utils.C2YI6McM.js +0 -52
  80. package/dist/chunks/worker.d.BKu8cnnX.d.ts +0 -8
  81. package/dist/workers.d.ts +0 -38
  82. package/dist/workers.js +0 -31
  83. package/execute.d.ts +0 -1
  84. package/utils.d.ts +0 -1
  85. 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.AzwzFtyi.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.8";
622
+ var version = "4.0.0";
623
623
 
624
624
  const apiConfig = (port) => ({
625
625
  port: {
@@ -632,32 +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
- minThreads: {
643
- description: "Minimum number or percentage of threads to run tests in",
644
- argument: "<workers>"
645
- },
646
- useAtomics: { description: "Use Atomics to synchronize threads. This can improve performance in some cases, but might cause segfault in older Node versions (default: `false`)" },
647
- execArgv: null
648
- }, poolForksCommands = {
649
- isolate: { description: "Isolate tests in forks pool (default: `true`)" },
650
- singleFork: { description: "Run tests inside a single child_process (default: `false`)" },
651
- maxForks: {
652
- description: "Maximum number or percentage of processes to run tests in",
653
- argument: "<workers>"
654
- },
655
- minForks: {
656
- description: "Minimum number or percentage of processes to run tests in",
657
- argument: "<workers>"
658
- },
659
- execArgv: null
660
- };
635
+ });
661
636
  function watermarkTransform(value) {
662
637
  return typeof value === "string" ? value.split(",").map(Number) : value;
663
638
  }
@@ -766,7 +741,14 @@ const cliOptionsConfig = {
766
741
  argument: "",
767
742
  subcommands: {
768
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`)" },
769
- 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
+ },
770
752
  lines: {
771
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",
772
754
  argument: "<number>"
@@ -856,12 +838,19 @@ const cliOptionsConfig = {
856
838
  provider: {
857
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\"`)",
858
840
  argument: "<name>",
859
- subcommands: null
860
- },
861
- providerOptions: {
862
- description: "Options that are passed down to a browser provider. Visit [`browser.providerOptions`](https://vitest.dev/config/#browser-provideroptions) for more information",
863
- argument: "<options>",
864
- 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
+ }
865
854
  },
866
855
  isolate: { description: "Run every browser test file in isolation. To disable isolation, use `--browser.isolate=false` (default: `true`)" },
867
856
  ui: { description: "Show Vitest UI when running tests (default: `!process.env.CI`)" },
@@ -871,6 +860,14 @@ const cliOptionsConfig = {
871
860
  argument: "<timeout>"
872
861
  },
873
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
+ },
874
871
  orchestratorScripts: null,
875
872
  commands: null,
876
873
  viewport: null,
@@ -887,53 +884,19 @@ const cliOptionsConfig = {
887
884
  argument: "<pool>",
888
885
  subcommands: null
889
886
  },
890
- poolOptions: {
891
- description: "Specify pool options",
892
- argument: "<options>",
893
- subcommands: {
894
- threads: {
895
- description: "Specify threads pool options",
896
- argument: "<options>",
897
- subcommands: poolThreadsCommands
898
- },
899
- vmThreads: {
900
- description: "Specify VM threads pool options",
901
- argument: "<options>",
902
- subcommands: {
903
- ...poolThreadsCommands,
904
- memoryLimit: {
905
- description: "Memory limit for VM threads pool. If you see memory leaks, try to tinker this value.",
906
- argument: "<limit>"
907
- }
908
- }
909
- },
910
- forks: {
911
- description: "Specify forks pool options",
912
- argument: "<options>",
913
- subcommands: poolForksCommands
914
- },
915
- vmForks: {
916
- description: "Specify VM forks pool options",
917
- argument: "<options>",
918
- subcommands: {
919
- ...poolForksCommands,
920
- memoryLimit: {
921
- description: "Memory limit for VM forks pool. If you see memory leaks, try to tinker this value.",
922
- argument: "<limit>"
923
- }
924
- }
925
- }
926
- }
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>"
927
894
  },
928
895
  fileParallelism: { description: "Should all test files run in parallel. Use `--no-file-parallelism` to disable (default: `true`)" },
929
896
  maxWorkers: {
930
897
  description: "Maximum number or percentage of workers to run tests in",
931
898
  argument: "<workers>"
932
899
  },
933
- minWorkers: {
934
- description: "Minimum number or percentage of workers to run tests in",
935
- argument: "<workers>"
936
- },
937
900
  environment: {
938
901
  description: "Specify runner environment, if not running in the browser (default: `node`)",
939
902
  argument: "<name>",
@@ -1291,11 +1254,10 @@ function createCLI(options = {}) {
1291
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;
1292
1255
  }
1293
1256
  function removeQuotes(str) {
1294
- 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;
1295
1258
  }
1296
1259
  function splitArgv(argv) {
1297
- const reg = /(['"])(?:(?!\1).)+\1/g;
1298
- 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) => {
1299
1261
  return arg = arg.replace(/\0/g, " "), removeQuotes(arg);
1300
1262
  });
1301
1263
  }
@@ -1332,28 +1294,22 @@ function normalizeCliOptions(cliFilters, argv) {
1332
1294
  }
1333
1295
  async function start(mode, cliFilters, options) {
1334
1296
  try {
1335
- process.title = "node (vitest)";
1336
- } catch {}
1337
- try {
1338
- const { startVitest } = await import('./cli-api.C-JHgQgp.js').then(function (n) { return n.j; }), ctx = await startVitest(mode, cliFilters.map(normalize), normalizeCliOptions(cliFilters, options));
1297
+ const { startVitest } = await import('./cli-api.PwHwIMss.js').then(function (n) { return n.p; }), ctx = await startVitest(mode, cliFilters.map(normalize), normalizeCliOptions(cliFilters, options));
1339
1298
  if (!ctx.shouldKeepServer()) await ctx.exit();
1340
1299
  } catch (e) {
1341
- const { errorBanner } = await import('./index.AzwzFtyi.js').then(function (n) { return n.u; });
1300
+ const { errorBanner } = await import('./index.CcRZ6fUh.js').then(function (n) { return n.u; });
1342
1301
  if (console.error(`\n${errorBanner("Startup Error")}`), console.error(e), console.error("\n\n"), process.exitCode == null) process.exitCode = 1;
1343
1302
  process.exit();
1344
1303
  }
1345
1304
  }
1346
1305
  async function init(project) {
1347
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);
1348
- const { create } = await import('./creator.KEg6n5IC.js');
1307
+ const { create } = await import('./creator.DucAaYBz.js');
1349
1308
  await create();
1350
1309
  }
1351
1310
  async function collect(mode, cliFilters, options) {
1352
1311
  try {
1353
- process.title = "node (vitest)";
1354
- } catch {}
1355
- try {
1356
- const { prepareVitest, processCollected, outputFileList } = await import('./cli-api.C-JHgQgp.js').then(function (n) { return n.j; }), ctx = await prepareVitest(mode, {
1312
+ const { prepareVitest, processCollected, outputFileList } = await import('./cli-api.PwHwIMss.js').then(function (n) { return n.p; }), ctx = await prepareVitest(mode, {
1357
1313
  ...normalizeCliOptions(cliFilters, options),
1358
1314
  watch: false,
1359
1315
  run: true
@@ -1371,7 +1327,7 @@ async function collect(mode, cliFilters, options) {
1371
1327
  }
1372
1328
  await ctx.close();
1373
1329
  } catch (e) {
1374
- const { errorBanner } = await import('./index.AzwzFtyi.js').then(function (n) { return n.u; });
1330
+ const { errorBanner } = await import('./index.CcRZ6fUh.js').then(function (n) { return n.u; });
1375
1331
  if (console.error(`\n${errorBanner("Collect Error")}`), console.error(e), console.error("\n\n"), process.exitCode == null) process.exitCode = 1;
1376
1332
  process.exit();
1377
1333
  }