vitest 5.0.0-beta.5 → 5.0.0-beta.7

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 (76) hide show
  1. package/LICENSE.md +165 -1
  2. package/dist/browser.d.ts +27 -14
  3. package/dist/browser.js +11 -14
  4. package/dist/chunks/{artifact.C0OHWdod.js → artifact.DC5WoEgy.js} +1310 -13
  5. package/dist/chunks/{base.BPbmtl-C.js → base.B0fUxpj9.js} +17 -13
  6. package/dist/chunks/{browser.d.B-p-y0sB.d.ts → browser.d.BFOby8YL.d.ts} +3 -3
  7. package/dist/chunks/{cac.DYQRhgb-.js → cac.B41kXwyU.js} +22 -24
  8. package/dist/chunks/check.Cz_-YojU.js +15 -0
  9. package/dist/chunks/cli-api.bqNN5viV.js +519 -0
  10. package/dist/chunks/{config.d.Bkl6J5iR.d.ts → config.d.DsC1jkby.d.ts} +877 -27
  11. package/dist/chunks/{console.DjVIMaXT.js → console.omGxyKMT.js} +5 -5
  12. package/dist/chunks/{coverage.CTzCuANN.js → coverage.BVb1JqW7.js} +7 -2
  13. package/dist/chunks/coverage.BfSEMtie.js +26 -0
  14. package/dist/chunks/coverage.d.ByaAMV4A.d.ts +88 -0
  15. package/dist/chunks/{creator.CJiHagNv.js → creator.BzMFaPC-.js} +54 -30
  16. package/dist/chunks/{defaults.CUUnbOrq.js → defaults.BJUmAuaO.js} +3 -2
  17. package/dist/chunks/display.CYwyMF4S.js +192 -0
  18. package/dist/chunks/{env.BKKtU2WC.js → env.DzFJjrmK.js} +1 -1
  19. package/dist/chunks/{environment.d.CrsxCzP1.d.ts → environment.d.4-rzQgpt.d.ts} +1 -1
  20. package/dist/chunks/globals.sd6Qutmc.js +28 -0
  21. package/dist/chunks/{cli-api.SMst4llK.js → index.5krd73UD.js} +14591 -13056
  22. package/dist/chunks/{index.CXzZ7KB8.js → index.CLtI1k_4.js} +627 -214
  23. package/dist/chunks/{index.DzNNaFWy.js → index.DxR-nMjO.js} +63 -10
  24. package/dist/chunks/index.DzTmMrSM.js +940 -0
  25. package/dist/chunks/{index.DugGyGng.js → index.JaztIWgW.js} +6 -5
  26. package/dist/chunks/{init-forks.CDWjf0q6.js → init-forks.CXzT841o.js} +1 -1
  27. package/dist/chunks/{init-threads.B-vZ8N2q.js → init-threads.Ch-Bw5j3.js} +1 -1
  28. package/dist/chunks/{init.gslB1aqB.js → init.CfiYZpFg.js} +41 -25
  29. package/dist/chunks/{native.DPzPHdi5.js → native.BUCvPRKp.js} +3 -4
  30. package/dist/chunks/{nativeModuleMocker.CrcWvO03.js → nativeModuleMocker.Uot80PXb.js} +2 -3
  31. package/dist/chunks/{index.CesbTg1C.js → nativeModuleRunner.BDnwGb8g.js} +39 -3
  32. package/dist/chunks/{node.C9I1sbE9.js → node.BPMnm_Q2.js} +1 -1
  33. package/dist/chunks/offset.Dy-5Fdfn.js +24 -0
  34. package/dist/chunks/pathe.M-eThtNZ.CbK_Vbae.js +489 -0
  35. package/dist/chunks/{plugin.d.BuiCQSo8.d.ts → plugin.d.BOjbmxWW.d.ts} +1757 -1566
  36. package/dist/chunks/{plugins.DrsmdUE2.js → plugins.CsoX-42X.js} +1 -1
  37. package/dist/chunks/resolver.CERfsKE-.js +48 -0
  38. package/dist/chunks/{rpc.d.BLxNuPAq.d.ts → rpc.d.BeasqWpO.d.ts} +14 -1
  39. package/dist/chunks/{rpc.DZEh5xnQ.js → rpc.iNjF664v.js} +2 -2
  40. package/dist/chunks/setup-common.vxjAyUtK.js +36 -0
  41. package/dist/chunks/setup.DasACXvo.js +5409 -0
  42. package/dist/chunks/source-map.DZdIqpIJ.js +1776 -0
  43. package/dist/chunks/spy.B8mHA9qu.js +422 -0
  44. package/dist/chunks/{task-utils.d.CLWcZaUf.d.ts → task-utils.d.BKHiHxSN.d.ts} +20 -2
  45. package/dist/chunks/tinyrainbow.Ht9iggcq.js +95 -0
  46. package/dist/chunks/{utils.DKODp04v.js → utils.CO-iLyCr.js} +41 -42
  47. package/dist/chunks/{vm._FqKqltU.js → vm.DoQh8CN9.js} +110 -11
  48. package/dist/chunks/{worker.d.Cb0Z-SnE.d.ts → worker.d.s_RdeZtI.d.ts} +14 -11
  49. package/dist/cli.js +4 -5
  50. package/dist/config.cjs +2 -1
  51. package/dist/config.d.ts +19 -17
  52. package/dist/config.js +2 -2
  53. package/dist/index.d.ts +241 -31
  54. package/dist/index.js +11 -16
  55. package/dist/module-evaluator.d.ts +40 -8
  56. package/dist/module-evaluator.js +73 -22
  57. package/dist/node.d.ts +225 -86
  58. package/dist/node.js +30 -66
  59. package/dist/runtime.d.ts +6 -11
  60. package/dist/runtime.js +4 -5
  61. package/dist/spy.js +1 -1
  62. package/dist/task-utils.js +1 -2
  63. package/dist/worker.d.ts +5 -10
  64. package/dist/worker.js +24 -36
  65. package/dist/workers/forks.js +21 -33
  66. package/dist/workers/runVmTests.js +15 -20
  67. package/dist/workers/threads.js +21 -33
  68. package/dist/workers/vmForks.js +13 -15
  69. package/dist/workers/vmThreads.js +13 -15
  70. package/package.json +20 -20
  71. package/dist/chunks/_commonjsHelpers.D26ty3Ew.js +0 -6
  72. package/dist/chunks/coverage.d.Dn6XbyQq.d.ts +0 -43
  73. package/dist/chunks/globals.D2wDMk06.js +0 -33
  74. package/dist/chunks/index.6dZyLbho.js +0 -6918
  75. package/dist/chunks/nativeModuleRunner.WlMdOB52.js +0 -36
  76. package/dist/chunks/setup-common.DRlwpHsL.js +0 -64
@@ -1,21 +1,21 @@
1
1
  import { runInThisContext } from 'node:vm';
2
- import * as spyModule from '@vitest/spy';
3
- import { r as resolveTestRunner, a as resolveSnapshotEnvironment, d as detectAsyncLeaks, s as setupChaiConfig } from './index.DugGyGng.js';
4
- import { l as loadEnvironment, e as emitModuleRunner, a as listenForErrors } from './init.gslB1aqB.js';
5
- import { N as NativeModuleRunner } from './nativeModuleRunner.WlMdOB52.js';
2
+ import { s as spyModule } from './spy.B8mHA9qu.js';
3
+ import { r as resolveTestRunner, a as resolveSnapshotEnvironment, d as detectAsyncLeaks, s as setupChaiConfig } from './index.JaztIWgW.js';
4
+ import { l as loadEnvironment, e as emitModuleRunner, a as listenForErrors } from './init.CfiYZpFg.js';
6
5
  import { Traces } from '../traces.js';
7
- import { V as VitestEvaluatedModules } from './rpc.DZEh5xnQ.js';
8
- import { s as startVitestModuleRunner, c as createNodeImportMeta } from './index.DzNNaFWy.js';
6
+ import { V as VitestEvaluatedModules } from './rpc.iNjF664v.js';
7
+ import { s as startVitestModuleRunner, c as createNodeImportMeta } from './index.DxR-nMjO.js';
9
8
  import { performance as performance$1 } from 'node:perf_hooks';
10
- import { s as setupCommonEnv, b as startCoverageInsideWorker, c as stopCoverageInsideWorker } from './setup-common.DRlwpHsL.js';
11
- import { i as index, g as globalExpect, v as vi } from './index.CXzZ7KB8.js';
9
+ import { s as startCoverageInsideWorker, a as stopCoverageInsideWorker } from './coverage.BfSEMtie.js';
10
+ import { i as index, g as globalExpect, v as vi } from './index.CLtI1k_4.js';
12
11
  import { c as closeInspector } from './inspector.CvyFGlXm.js';
13
- import { s as startTests, p as publicCollect } from './artifact.C0OHWdod.js';
12
+ import { s as startTests, p as publicCollect } from './artifact.DC5WoEgy.js';
14
13
  import { createRequire } from 'node:module';
15
14
  import timers from 'node:timers';
16
15
  import timersPromises from 'node:timers/promises';
17
16
  import util from 'node:util';
18
- import { KNOWN_ASSET_TYPES } from '@vitest/utils/constants';
17
+ import { K as KNOWN_ASSET_TYPES } from './pathe.M-eThtNZ.CbK_Vbae.js';
18
+ import { s as setupCommonEnv, b as setupEnv } from './setup-common.vxjAyUtK.js';
19
19
  import { g as getWorkerState, r as resetModules, p as provideWorkerState, a as getSafeWorkerState } from './utils.DYj33du9.js';
20
20
 
21
21
  // this should only be used in Node
@@ -57,7 +57,7 @@ function resolveAsset(mod, url) {
57
57
  mod.exports = url;
58
58
  }
59
59
  async function setupConsoleLogSpy() {
60
- const { createCustomConsole } = await import('./console.DjVIMaXT.js');
60
+ const { createCustomConsole } = await import('./console.omGxyKMT.js');
61
61
  globalThis.console = createCustomConsole();
62
62
  }
63
63
 
@@ -114,7 +114,7 @@ async function startModuleRunner(options) {
114
114
  let mocker;
115
115
  if (options.state.config.experimental.nodeLoader !== false) {
116
116
  // this additionally imports acorn/magic-string
117
- const { NativeModuleMocker } = await import('./nativeModuleMocker.CrcWvO03.js');
117
+ const { NativeModuleMocker } = await import('./nativeModuleMocker.Uot80PXb.js');
118
118
  mocker = new NativeModuleMocker({
119
119
  async resolveId(id, importer) {
120
120
  // TODO: use import.meta.resolve instead
@@ -129,6 +129,9 @@ async function startModuleRunner(options) {
129
129
  spyModule
130
130
  });
131
131
  }
132
+ // imported lazily (pulls in `local-pkg`) so it stays out of the default
133
+ // worker startup graph; only the `viteModuleRunner: false` path needs it
134
+ const { NativeModuleRunner } = await import('./nativeModuleRunner.BDnwGb8g.js').then(function (n) { return n.n; });
132
135
  _moduleRunner = new NativeModuleRunner(root, mocker);
133
136
  return _moduleRunner;
134
137
  }
@@ -140,11 +143,12 @@ let _environmentTime;
140
143
  /** @experimental */
141
144
  async function setupBaseEnvironment(context) {
142
145
  if (context.config.experimental.viteModuleRunner === false) {
143
- const { setupNodeLoaderHooks } = await import('./native.DPzPHdi5.js');
146
+ const { setupNodeLoaderHooks } = await import('./native.BUCvPRKp.js');
144
147
  await setupNodeLoaderHooks(context);
145
148
  }
146
149
  const startTime = performance.now();
147
150
  const { environment: { name: environmentName, options: environmentOptions }, rpc, config } = context;
151
+ setupEnv(config.env, context.metaEnv);
148
152
  // we could load @vite/env, but it would take ~8ms, while this takes ~0,02ms
149
153
  if (context.config.serializedDefines) try {
150
154
  runInThisContext(`(() =>{\n${context.config.serializedDefines}})()`, {
@@ -1,6 +1,6 @@
1
- import { aH as FileSpecification } from './config.d.Bkl6J5iR.js';
2
- import { O as OTELCarrier } from './rpc.d.BLxNuPAq.js';
3
- import { T as TestExecutionMethod } from './worker.d.Cb0Z-SnE.js';
1
+ import { be as FileSpecification } from './config.d.DsC1jkby.js';
2
+ import { O as OTELCarrier } from './rpc.d.BeasqWpO.js';
3
+ import { T as TestExecutionMethod } from './worker.d.s_RdeZtI.js';
4
4
 
5
5
  type SerializedTestSpecification = [project: {
6
6
  name: string | undefined;
@@ -1,8 +1,7 @@
1
- import { toArray } from '@vitest/utils/helpers';
1
+ import { n as normalize, t as toArray } from './pathe.M-eThtNZ.CbK_Vbae.js';
2
2
  import { EventEmitter } from 'events';
3
- import { normalize } from 'pathe';
4
- import { disableDefaultColors } from 'tinyrainbow';
5
- import { i as isForceColor } from './env.BKKtU2WC.js';
3
+ import { m } from './tinyrainbow.Ht9iggcq.js';
4
+ import { a as isForceColor } from './env.DzFJjrmK.js';
6
5
  import { a as defaultPort, d as defaultBrowserPort } from './constants.-juJ8b_4.js';
7
6
  import assert from 'node:assert';
8
7
  import { isAgent } from 'std-env';
@@ -621,7 +620,7 @@ class CAC extends EventEmitter {
621
620
 
622
621
  const cac = (name = "") => new CAC(name);
623
622
 
624
- var version = "5.0.0-beta.5";
623
+ var version = "5.0.0-beta.7";
625
624
 
626
625
  const apiConfig = (port) => ({
627
626
  port: {
@@ -681,7 +680,7 @@ const cliOptionsConfig = {
681
680
  open: { description: "Open UI automatically (default: `!process.env.CI`)" },
682
681
  api: {
683
682
  argument: "[port]",
684
- description: `Specify server port. Note if the port is already being used, Vite will automatically try the next available port so this may not be the actual port the server ends up listening on. If true will be set to ${defaultPort}`,
683
+ description: `Specify server port. Note if the port is already being used, Vite will automatically try the next available port so this may not be the actual port the server ends up listening on. If true will be set to ${defaultPort} or ${defaultBrowserPort} in browser mode`,
685
684
  subcommands: apiConfig(defaultPort),
686
685
  transform(portOrOptions) {
687
686
  if (typeof portOrOptions === "number") return { port: portOrOptions };
@@ -699,6 +698,7 @@ const cliOptionsConfig = {
699
698
  }
700
699
  },
701
700
  hideSkippedTests: { description: "Hide logs for skipped tests" },
701
+ reporter: null,
702
702
  reporters: {
703
703
  alias: "reporter",
704
704
  description: `Specify reporters (default, agent, minimal, blob, verbose, dot, json, tap, tap-flat, junit, tree, hanging-process, github-actions)`,
@@ -848,6 +848,7 @@ const cliOptionsConfig = {
848
848
  },
849
849
  isolate: { description: "Run every test file in isolation. To disable isolation, use `--no-isolate` (default: `true`)" },
850
850
  globals: { description: "Inject apis globally" },
851
+ injectCjsGlobals: { description: "Inject CommonJS variables (`module`, `exports`, `require`, `__filename`, `__dirname`) into every test module. To disable, use `--no-inject-cjs-globals` (default: `true`)" },
851
852
  dom: { description: "Mock browser API with happy-dom" },
852
853
  browser: {
853
854
  description: "Run tests in the browser. Equivalent to `--browser.enabled` (default: `false`)",
@@ -866,22 +867,16 @@ const cliOptionsConfig = {
866
867
  argument: "<name>"
867
868
  },
868
869
  headless: { description: "Run the browser in headless mode (i.e. without opening the GUI (Graphical User Interface)). If you are running Vitest in CI, it will be enabled by default (default: `process.env.CI`)" },
869
- api: {
870
- description: "Specify options for the browser API server. Does not affect the --api option",
871
- argument: "[port]",
872
- subcommands: apiConfig(defaultBrowserPort)
873
- },
874
- isolate: { description: "Run every browser test file in isolation. To disable isolation, use `--browser.isolate=false` (default: `true`)" },
875
870
  ui: { description: "Show Vitest UI when running tests (default: `!process.env.CI`)" },
876
871
  detailsPanelPosition: {
877
872
  description: "Default position for the details panel in browser mode. Either `right` (horizontal split) or `bottom` (vertical split) (default: `right`)",
878
873
  argument: "<position>"
879
874
  },
880
- fileParallelism: { description: "Should browser test files run in parallel. Use `--browser.fileParallelism=false` to disable (default: `true`)" },
881
875
  connectTimeout: {
882
876
  description: "If connection to the browser takes longer, the test suite will fail (default: `60_000`)",
883
877
  argument: "<timeout>"
884
878
  },
879
+ dependencySourcemaps: { description: "Serve sourcemaps of dependencies to the browser in headless runs, used by devtools when debugging into `node_modules`. Reported test errors are source-mapped either way. Use `--browser.dependencySourcemaps=false` to speed up test runs if you don't step into dependency code (default: `true`)" },
885
880
  trackUnhandledErrors: { description: "Control if Vitest catches uncaught exceptions so they can be reported (default: `true`)" },
886
881
  trace: {
887
882
  description: "Enable trace view mode. Supported: \"on\", \"off\", \"on-first-retry\", \"on-all-retries\", \"retain-on-failure\".",
@@ -1160,6 +1155,11 @@ const cliOptionsConfig = {
1160
1155
  description: "Maximum number of concurrent tests and suites during test file execution (default: `5`)",
1161
1156
  argument: "<number>"
1162
1157
  },
1158
+ fsModuleCache: { description: "Cache transformed modules on the file system and reuse them between reruns (default: `false`)" },
1159
+ fsModuleCachePath: {
1160
+ description: "Directory where the `fsModuleCache` is stored (default: `node_modules/.vitest-cache`)",
1161
+ argument: "<path>"
1162
+ },
1163
1163
  expect: {
1164
1164
  description: "Configuration options for `expect()` matches",
1165
1165
  argument: "",
@@ -1218,7 +1218,7 @@ const cliOptionsConfig = {
1218
1218
  description: "List all available tags instead of running tests. `--list-tags=json` will output tags in JSON format, unless there are no tags.",
1219
1219
  argument: "[type]"
1220
1220
  },
1221
- clearCache: { description: "Delete all Vitest caches, including `experimental.fsModuleCache`, without running any tests. This will reduce the performance in the subsequent test run." },
1221
+ clearCache: { description: "Delete all Vitest caches, including the `fsModuleCache`, without running any tests. This will reduce the performance in the subsequent test run." },
1222
1222
  tagsFilter: {
1223
1223
  description: "Run only tests with the specified tags. You can use logical operators `&&` (and), `||` (or) and `!` (not) to create complex expressions, see [Test Tags](https://vitest.dev/guide/test-tags#syntax) for more information.",
1224
1224
  argument: "<expression>",
@@ -1229,8 +1229,6 @@ const cliOptionsConfig = {
1229
1229
  description: "Experimental features.",
1230
1230
  argument: "<features>",
1231
1231
  subcommands: {
1232
- fsModuleCache: { description: "Enable caching of modules on the file system between reruns." },
1233
- fsModuleCachePath: null,
1234
1232
  openTelemetry: null,
1235
1233
  importDurations: {
1236
1234
  description: "Configure import duration collection and CLI display. Note that UI's \"Module Graph\" tab can always show import breakdown regardless of the `print` setting.",
@@ -2224,7 +2222,7 @@ function addCliOptions(cli, options) {
2224
2222
  for (const [optionName, option] of Object.entries(options)) if (option) addCommand(cli, optionName, option);
2225
2223
  }
2226
2224
  function createCLI(options = {}) {
2227
- if (isAgent && !isForceColor()) disableDefaultColors();
2225
+ if (isAgent && !isForceColor()) m();
2228
2226
  const cli = cac("vitest");
2229
2227
  cli.version(version);
2230
2228
  addCliOptions(cli, cliOptionsConfig);
@@ -2349,15 +2347,15 @@ function normalizeCliOptions(cliFilters, argv) {
2349
2347
  }
2350
2348
  async function start(cliFilters, options) {
2351
2349
  try {
2352
- const { startVitest } = await import('./cli-api.SMst4llK.js').then(function (n) { return n.y; });
2350
+ const { startVitest } = await import('./cli-api.bqNN5viV.js').then(function (n) { return n.a; });
2353
2351
  const ctx = await startVitest(cliFilters.map(normalize), normalizeCliOptions(cliFilters, options));
2354
2352
  if (!ctx.shouldKeepServer()) await ctx.exit();
2355
2353
  } catch (e) {
2356
- const { errorBanner } = await import('./utils.DKODp04v.js').then(function (n) { return n.u; });
2354
+ const { errorBanner } = await import('./utils.CO-iLyCr.js').then(function (n) { return n.u; });
2357
2355
  console.error(`\n${errorBanner("Startup Error")}`);
2358
2356
  console.error(e);
2359
2357
  console.error("\n\n");
2360
- if (process.exitCode == null) process.exitCode = 1;
2358
+ process.exitCode ??= 1;
2361
2359
  process.exit();
2362
2360
  }
2363
2361
  }
@@ -2366,12 +2364,12 @@ async function init(project) {
2366
2364
  console.error(/* @__PURE__ */ new Error("Only the \"browser\" project is supported. Use \"vitest init browser\" to create a new project."));
2367
2365
  process.exit(1);
2368
2366
  }
2369
- const { create } = await import('./creator.CJiHagNv.js');
2367
+ const { create } = await import('./creator.BzMFaPC-.js');
2370
2368
  await create();
2371
2369
  }
2372
2370
  async function collect(cliFilters, options) {
2373
2371
  try {
2374
- const { prepareVitest, processCollected, outputFileList } = await import('./cli-api.SMst4llK.js').then(function (n) { return n.y; });
2372
+ const { prepareVitest, processCollected, outputFileList } = await import('./cli-api.bqNN5viV.js').then(function (n) { return n.a; });
2375
2373
  const ctx = await prepareVitest({
2376
2374
  ...normalizeCliOptions(cliFilters, options),
2377
2375
  watch: false,
@@ -2393,11 +2391,11 @@ async function collect(cliFilters, options) {
2393
2391
  } else outputFileList(await ctx.getRelevantTestSpecifications(cliFilters.map(normalize)), options);
2394
2392
  await ctx.close();
2395
2393
  } catch (e) {
2396
- const { errorBanner } = await import('./utils.DKODp04v.js').then(function (n) { return n.u; });
2394
+ const { errorBanner } = await import('./utils.CO-iLyCr.js').then(function (n) { return n.u; });
2397
2395
  console.error(`\n${errorBanner("Collect Error")}`);
2398
2396
  console.error(e);
2399
2397
  console.error("\n\n");
2400
- if (process.exitCode == null) process.exitCode = 1;
2398
+ process.exitCode ??= 1;
2401
2399
  process.exit();
2402
2400
  }
2403
2401
  }
@@ -0,0 +1,15 @@
1
+ import crypto from 'node:crypto';
2
+
3
+ function isValidApiRequest(config, req) {
4
+ const url = new URL(req.url ?? "", "http://localhost");
5
+ // validate token. token is injected in ui/tester/orchestrator html, which is cross origin protected.
6
+ try {
7
+ const token = url.searchParams.get("token");
8
+ if (token && crypto.timingSafeEqual(Buffer.from(token), Buffer.from(config.api.token))) return true;
9
+ }
10
+ // an error is thrown when the length is incorrect
11
+ catch {}
12
+ return false;
13
+ }
14
+
15
+ export { isValidApiRequest as i };