vitest 4.0.0-beta.17 → 4.0.0-beta.19

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 (58) hide show
  1. package/dist/browser.d.ts +3 -3
  2. package/dist/browser.js +1 -1
  3. package/dist/{worker-base.js → chunks/base.CtHM3ryk.js} +18 -91
  4. package/dist/chunks/{browser.d.CCG7W26I.d.ts → browser.d.B9iJzZyn.d.ts} +3 -2
  5. package/dist/chunks/{cac.BO_6jvrs.js → cac.DCrQhweU.js} +15 -62
  6. package/dist/chunks/{cli-api.BvCJGado.js → cli-api.BjHteKX0.js} +1322 -55
  7. package/dist/chunks/{config.d.C4PpNy7v.d.ts → config.d.u2CUDWwS.d.ts} +2 -16
  8. package/dist/chunks/{coverage.3htTSxXZ.js → coverage.FU3w4IrQ.js} +39 -1213
  9. package/dist/chunks/{creator.Daoa5_gR.js → creator.DucAaYBz.js} +1 -1
  10. package/dist/chunks/{defaults.CXFFjsi8.js → defaults.BOqNVLsY.js} +0 -1
  11. package/dist/chunks/evaluatedModules.Dg1zASAC.js +17 -0
  12. package/dist/chunks/{global.d.D1pbKXir.d.ts → global.d.BgJSTpgQ.d.ts} +2 -1
  13. package/dist/chunks/{globals.DC4ntO86.js → globals.BGT_RUsD.js} +5 -3
  14. package/dist/chunks/{index.01uBqPwR.js → index.BdSLhLDZ.js} +1 -1
  15. package/dist/chunks/{index.Bt-upxGS.js → index.CbWINfS7.js} +29 -4
  16. package/dist/chunks/{index.DehVUBn4.js → index.CcRZ6fUh.js} +1507 -12
  17. package/dist/chunks/{index.Dnl38iQ_.js → index.RwjEGCQ0.js} +3 -3
  18. package/dist/chunks/init-forks.DSafeltJ.js +54 -0
  19. package/dist/chunks/init-threads.SUtZ-067.js +17 -0
  20. package/dist/chunks/{worker.DVTUM2IW.js → init.B2EESLQM.js} +98 -81
  21. package/dist/chunks/{inspector.Br76Q2Mb.js → inspector.DLZxSeU3.js} +1 -2
  22. package/dist/chunks/{moduleRunner.d.aXWuQhZN.d.ts → moduleRunner.d.YtNsMIoJ.d.ts} +1 -1
  23. package/dist/chunks/{plugin.d.CqKwuCSa.d.ts → plugin.d.BB__S31E.d.ts} +1 -1
  24. package/dist/chunks/{reporters.d.DAyr7w3M.d.ts → reporters.d.C6nGyY9_.d.ts} +1104 -1112
  25. package/dist/chunks/{resolveSnapshotEnvironment.BsJpmVZR.js → resolveSnapshotEnvironment.DJJKMKxb.js} +2 -2
  26. package/dist/chunks/{setup-common.BewgbkTd.js → setup-common.DR1sucx6.js} +1 -1
  27. package/dist/chunks/{startModuleRunner.DPBo3mme.js → startModuleRunner.C2tTvmF9.js} +3 -1
  28. package/dist/chunks/{test.CTuWuHYH.js → test.C3RPt8JR.js} +1 -1
  29. package/dist/chunks/{vi.B2--mG9U.js → vi.BZvkKVkM.js} +1 -1
  30. package/dist/{worker-vm.js → chunks/vm.DBeOXrP9.js} +6 -66
  31. package/dist/chunks/{worker.d.DSgBAZPX.d.ts → worker.d.BFk-vvBU.d.ts} +79 -4
  32. package/dist/cli.js +8 -9
  33. package/dist/config.cjs +0 -1
  34. package/dist/config.d.ts +6 -7
  35. package/dist/config.js +1 -1
  36. package/dist/coverage.d.ts +4 -4
  37. package/dist/coverage.js +2 -13
  38. package/dist/environments.js +1 -1
  39. package/dist/index.d.ts +13 -9
  40. package/dist/index.js +5 -3
  41. package/dist/module-evaluator.d.ts +3 -3
  42. package/dist/module-runner.js +1 -1
  43. package/dist/node.d.ts +79 -15
  44. package/dist/node.js +25 -26
  45. package/dist/reporters.d.ts +4 -4
  46. package/dist/reporters.js +9 -10
  47. package/dist/runners.d.ts +1 -1
  48. package/dist/runners.js +2 -2
  49. package/dist/worker.d.ts +26 -0
  50. package/dist/worker.js +46 -0
  51. package/dist/workers/forks.js +50 -0
  52. package/dist/workers/runVmTests.js +8 -7
  53. package/dist/workers/threads.js +50 -0
  54. package/dist/workers/vmForks.js +35 -0
  55. package/dist/workers/vmThreads.js +35 -0
  56. package/package.json +17 -14
  57. package/worker.d.ts +1 -0
  58. package/dist/chunks/typechecker.DsKAhua5.js +0 -1522
package/dist/browser.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- import { a as SerializedCoverageConfig, S as SerializedConfig } from './chunks/config.d.C4PpNy7v.js';
1
+ import { a as SerializedCoverageConfig, S as SerializedConfig } from './chunks/config.d.u2CUDWwS.js';
2
2
  import { R as RuntimeCoverageModuleLoader } from './chunks/coverage.d.BZtK59WP.js';
3
3
  import { SerializedDiffOptions } from '@vitest/utils/diff';
4
- import { V as VitestModuleRunner } from './chunks/moduleRunner.d.aXWuQhZN.js';
4
+ import { V as VitestModuleRunner } from './chunks/moduleRunner.d.YtNsMIoJ.js';
5
5
  export { collectTests, startTests } from '@vitest/runner';
6
6
  import * as _vitest_spy from '@vitest/spy';
7
7
  export { _vitest_spy as SpyModule };
@@ -15,7 +15,7 @@ import '@vitest/pretty-format';
15
15
  import '@vitest/snapshot';
16
16
  import 'node:vm';
17
17
  import 'vite/module-runner';
18
- import './chunks/worker.d.DSgBAZPX.js';
18
+ import './chunks/worker.d.BFk-vvBU.js';
19
19
  import './chunks/environment.d.CrsxCzP1.js';
20
20
  import '@vitest/mocker';
21
21
  import './chunks/mocker.d.BE_2ls6u.js';
package/dist/browser.js CHANGED
@@ -1,4 +1,4 @@
1
- export { l as loadDiffConfig, b as loadSnapshotSerializers, c as setupCommonEnv, s as startCoverageInsideWorker, a as stopCoverageInsideWorker, t as takeCoverageInsideWorker } from './chunks/setup-common.BewgbkTd.js';
1
+ export { l as loadDiffConfig, b as loadSnapshotSerializers, c as setupCommonEnv, s as startCoverageInsideWorker, a as stopCoverageInsideWorker, t as takeCoverageInsideWorker } from './chunks/setup-common.DR1sucx6.js';
2
2
  export { collectTests, startTests } from '@vitest/runner';
3
3
  import * as spyModule from '@vitest/spy';
4
4
  export { spyModule as SpyModule };
@@ -1,48 +1,21 @@
1
- import { c as createForksRpcOptions, u as unwrapSerializableConfig, a as createThreadsRpcOptions, e as execute, t as teardown$1 } from './chunks/worker.DVTUM2IW.js';
2
- import v8 from 'node:v8';
3
1
  import { runInThisContext } from 'node:vm';
4
2
  import * as spyModule from '@vitest/spy';
5
- import { EvaluatedModules } from 'vite/module-runner';
6
- import { s as startVitestModuleRunner, c as createNodeImportMeta } from './chunks/startModuleRunner.DPBo3mme.js';
3
+ import { V as VitestEvaluatedModules } from './evaluatedModules.Dg1zASAC.js';
4
+ import { s as startVitestModuleRunner, c as createNodeImportMeta } from './startModuleRunner.C2tTvmF9.js';
7
5
  import { performance } from 'node:perf_hooks';
8
6
  import { startTests, collectTests } from '@vitest/runner';
9
- import { a as resolveSnapshotEnvironment, s as setupChaiConfig, r as resolveTestRunner } from './chunks/resolveSnapshotEnvironment.BsJpmVZR.js';
10
- import { c as setupCommonEnv, s as startCoverageInsideWorker, a as stopCoverageInsideWorker } from './chunks/setup-common.BewgbkTd.js';
11
- import { g as globalExpect, v as vi } from './chunks/vi.B2--mG9U.js';
12
- import { c as closeInspector } from './chunks/inspector.Br76Q2Mb.js';
7
+ import { a as resolveSnapshotEnvironment, s as setupChaiConfig, r as resolveTestRunner } from './resolveSnapshotEnvironment.DJJKMKxb.js';
8
+ import { c as setupCommonEnv, s as startCoverageInsideWorker, a as stopCoverageInsideWorker } from './setup-common.DR1sucx6.js';
9
+ import { g as globalExpect, v as vi } from './vi.BZvkKVkM.js';
10
+ import { c as closeInspector } from './inspector.DLZxSeU3.js';
13
11
  import { createRequire } from 'node:module';
14
12
  import timers from 'node:timers';
15
13
  import timersPromises from 'node:timers/promises';
16
14
  import util from 'node:util';
17
15
  import { KNOWN_ASSET_TYPES } from '@vitest/utils/constants';
18
16
  import { getSafeTimers } from '@vitest/utils/timers';
19
- import { i as index } from './chunks/index.Dnl38iQ_.js';
20
- import { g as getWorkerState, r as resetModules, p as provideWorkerState } from './chunks/utils.CG9h5ccR.js';
21
- import '@vitest/utils/source-map';
22
- import 'node:fs';
23
- import 'node:url';
24
- import 'pathe';
25
- import './chunks/index.Bt-upxGS.js';
26
- import 'node:console';
27
- import './chunks/rpc.cD77ENhU.js';
28
- import './chunks/index.Bgo3tNWt.js';
29
- import '@vitest/utils/helpers';
30
- import './path.js';
31
- import 'node:path';
32
- import '@vitest/utils/serialize';
33
- import './module-evaluator.js';
34
- import '@vitest/mocker';
35
- import '@vitest/expect';
36
- import './chunks/test.CTuWuHYH.js';
37
- import './chunks/benchmark.DHKMYAts.js';
38
- import '@vitest/runner/utils';
39
- import '@vitest/utils/error';
40
- import './chunks/coverage.D_JHT54q.js';
41
- import '@vitest/snapshot';
42
- import '@vitest/utils/offset';
43
- import './chunks/_commonjsHelpers.BFTU3MAI.js';
44
- import './chunks/date.-jtEtIeV.js';
45
- import 'expect-type';
17
+ import { i as index } from './index.RwjEGCQ0.js';
18
+ import { g as getWorkerState, r as resetModules, p as provideWorkerState } from './utils.CG9h5ccR.js';
46
19
 
47
20
  // this should only be used in Node
48
21
  let globalSetup = false;
@@ -74,7 +47,7 @@ function resolveAsset(mod, url) {
74
47
  mod.exports = url;
75
48
  }
76
49
  async function setupConsoleLogSpy() {
77
- const { createCustomConsole } = await import('./chunks/console.CTJL2nuH.js');
50
+ const { createCustomConsole } = await import('./console.CTJL2nuH.js');
78
51
  globalThis.console = createCustomConsole();
79
52
  }
80
53
  async function withEnv({ environment }, options, fn) {
@@ -90,30 +63,31 @@ async function withEnv({ environment }, options, fn) {
90
63
  }
91
64
 
92
65
  // browser shouldn't call this!
93
- async function run$1(method, files, config, environment, moduleRunner) {
94
- const workerState = getWorkerState(), isIsolatedThreads = config.pool === "threads" && (config.poolOptions?.threads?.isolate ?? true), isIsolatedForks = config.pool === "forks" && (config.poolOptions?.forks?.isolate ?? true), isolate = isIsolatedThreads || isIsolatedForks;
95
- if (await setupGlobalEnv(config, environment, moduleRunner), await startCoverageInsideWorker(config.coverage, moduleRunner, { isolate }), config.chaiConfig) setupChaiConfig(config.chaiConfig);
66
+ async function run(method, files, config, environment, moduleRunner) {
67
+ const workerState = getWorkerState();
68
+ if (await setupGlobalEnv(config, environment, moduleRunner), await startCoverageInsideWorker(config.coverage, moduleRunner, { isolate: config.isolate }), config.chaiConfig) setupChaiConfig(config.chaiConfig);
96
69
  const runner = await resolveTestRunner(config, moduleRunner);
97
70
  workerState.onCancel.then((reason) => {
98
71
  closeInspector(config), runner.cancel?.(reason);
99
72
  }), workerState.durations.prepare = performance.now() - workerState.durations.prepare, workerState.durations.environment = performance.now(), await withEnv(environment, environment.options || config.environmentOptions || {}, async () => {
100
73
  workerState.durations.environment = performance.now() - workerState.durations.environment;
101
74
  for (const file of files) {
102
- if (isolate) moduleRunner.mocker.reset(), resetModules(workerState.evaluatedModules, true);
75
+ if (config.isolate) moduleRunner.mocker.reset(), resetModules(workerState.evaluatedModules, true);
103
76
  if (workerState.filepath = file.filepath, method === "run") await startTests([file], runner);
104
77
  else await collectTests([file], runner);
105
78
  // mocks should not affect different files
106
79
  vi.resetConfig(), vi.restoreAllMocks();
107
80
  }
108
- await stopCoverageInsideWorker(config.coverage, moduleRunner, { isolate });
81
+ await stopCoverageInsideWorker(config.coverage, moduleRunner, { isolate: config.isolate });
109
82
  }), workerState.environmentTeardownRun = true;
110
83
  }
111
84
 
112
85
  let _moduleRunner;
113
- const evaluatedModules = new EvaluatedModules(), moduleExecutionInfo = /* @__PURE__ */ new Map();
86
+ const evaluatedModules = new VitestEvaluatedModules(), moduleExecutionInfo = /* @__PURE__ */ new Map();
114
87
  function startModuleRunner(options) {
115
88
  return _moduleRunner || (_moduleRunner = startVitestModuleRunner(options), _moduleRunner);
116
89
  }
90
+ /** @experimental */
117
91
  async function runBaseTests(method, state) {
118
92
  const { ctx } = state;
119
93
  if (state.evaluatedModules = evaluatedModules, state.moduleExecutionInfo = moduleExecutionInfo, provideWorkerState(globalThis, state), ctx.invalidates) ctx.invalidates.forEach((filepath) => {
@@ -145,57 +119,10 @@ async function runBaseTests(method, state) {
145
119
  } catch (error) {
146
120
  throw new Error(`Failed to load custom "defines": ${error.message}`);
147
121
  }
148
- await run$1(method, fileSpecs, ctx.config, {
122
+ await run(method, fileSpecs, ctx.config, {
149
123
  environment: state.environment,
150
124
  options: ctx.environment.options
151
125
  }, executor);
152
126
  }
153
127
 
154
- class ForksBaseWorker {
155
- getRpcOptions() {
156
- return createForksRpcOptions(v8);
157
- }
158
- async executeTests(method, state) {
159
- // TODO: don't rely on reassigning process.exit
160
- // https://github.com/vitest-dev/vitest/pull/4441#discussion_r1443771486
161
- const exit = process.exit;
162
- state.ctx.config = unwrapSerializableConfig(state.ctx.config);
163
- try {
164
- await runBaseTests(method, state);
165
- } finally {
166
- process.exit = exit;
167
- }
168
- }
169
- runTests(state) {
170
- return this.executeTests("run", state);
171
- }
172
- collectTests(state) {
173
- return this.executeTests("collect", state);
174
- }
175
- }
176
- const worker$1 = new ForksBaseWorker();
177
-
178
- class ThreadsBaseWorker {
179
- getRpcOptions(ctx) {
180
- return createThreadsRpcOptions(ctx);
181
- }
182
- runTests(state) {
183
- return runBaseTests("run", state);
184
- }
185
- collectTests(state) {
186
- return runBaseTests("collect", state);
187
- }
188
- }
189
- const worker = new ThreadsBaseWorker();
190
-
191
- async function run(ctx) {
192
- await execute("run", ctx, ctx.pool === "forks" ? worker$1 : worker);
193
- }
194
- async function collect(ctx) {
195
- await execute("collect", ctx, ctx.pool === "forks" ? worker$1 : worker);
196
- }
197
- async function teardown() {
198
- await teardown$1();
199
- }
200
-
201
- export { collect, run, teardown };
128
+ export { runBaseTests as r };
@@ -1,4 +1,5 @@
1
- import { T as TestExecutionMethod } from './worker.d.DSgBAZPX.js';
1
+ import { FileSpecification } from '@vitest/runner';
2
+ import { T as TestExecutionMethod } from './worker.d.BFk-vvBU.js';
2
3
 
3
4
  type SerializedTestSpecification = [project: {
4
5
  name: string | undefined;
@@ -10,7 +11,7 @@ type SerializedTestSpecification = [project: {
10
11
 
11
12
  interface BrowserTesterOptions {
12
13
  method: TestExecutionMethod;
13
- files: string[];
14
+ files: FileSpecification[];
14
15
  providedContext: string;
15
16
  }
16
17
 
@@ -3,7 +3,7 @@ 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.DehVUBn4.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.17";
622
+ var version = "4.0.0-beta.19";
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
  }
@@ -901,43 +884,13 @@ const cliOptionsConfig = {
901
884
  argument: "<pool>",
902
885
  subcommands: null
903
886
  },
904
- poolOptions: {
905
- description: "Specify pool options",
906
- argument: "<options>",
907
- subcommands: {
908
- threads: {
909
- description: "Specify threads pool options",
910
- argument: "<options>",
911
- subcommands: poolThreadsCommands
912
- },
913
- vmThreads: {
914
- description: "Specify VM threads pool options",
915
- argument: "<options>",
916
- subcommands: {
917
- ...poolThreadsCommands,
918
- memoryLimit: {
919
- description: "Memory limit for VM threads pool. If you see memory leaks, try to tinker this value.",
920
- argument: "<limit>"
921
- }
922
- }
923
- },
924
- forks: {
925
- description: "Specify forks pool options",
926
- argument: "<options>",
927
- subcommands: poolForksCommands
928
- },
929
- vmForks: {
930
- description: "Specify VM forks pool options",
931
- argument: "<options>",
932
- subcommands: {
933
- ...poolForksCommands,
934
- memoryLimit: {
935
- description: "Memory limit for VM forks pool. If you see memory leaks, try to tinker this value.",
936
- argument: "<limit>"
937
- }
938
- }
939
- }
940
- }
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>"
941
894
  },
942
895
  fileParallelism: { description: "Should all test files run in parallel. Use `--no-file-parallelism` to disable (default: `true`)" },
943
896
  maxWorkers: {
@@ -1341,22 +1294,22 @@ function normalizeCliOptions(cliFilters, argv) {
1341
1294
  }
1342
1295
  async function start(mode, cliFilters, options) {
1343
1296
  try {
1344
- const { startVitest } = await import('./cli-api.BvCJGado.js').then(function (n) { return n.h; }), ctx = await startVitest(mode, cliFilters.map(normalize), normalizeCliOptions(cliFilters, options));
1297
+ const { startVitest } = await import('./cli-api.BjHteKX0.js').then(function (n) { return n.p; }), ctx = await startVitest(mode, cliFilters.map(normalize), normalizeCliOptions(cliFilters, options));
1345
1298
  if (!ctx.shouldKeepServer()) await ctx.exit();
1346
1299
  } catch (e) {
1347
- const { errorBanner } = await import('./index.DehVUBn4.js').then(function (n) { return n.u; });
1300
+ const { errorBanner } = await import('./index.CcRZ6fUh.js').then(function (n) { return n.u; });
1348
1301
  if (console.error(`\n${errorBanner("Startup Error")}`), console.error(e), console.error("\n\n"), process.exitCode == null) process.exitCode = 1;
1349
1302
  process.exit();
1350
1303
  }
1351
1304
  }
1352
1305
  async function init(project) {
1353
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);
1354
- const { create } = await import('./creator.Daoa5_gR.js');
1307
+ const { create } = await import('./creator.DucAaYBz.js');
1355
1308
  await create();
1356
1309
  }
1357
1310
  async function collect(mode, cliFilters, options) {
1358
1311
  try {
1359
- const { prepareVitest, processCollected, outputFileList } = await import('./cli-api.BvCJGado.js').then(function (n) { return n.h; }), ctx = await prepareVitest(mode, {
1312
+ const { prepareVitest, processCollected, outputFileList } = await import('./cli-api.BjHteKX0.js').then(function (n) { return n.p; }), ctx = await prepareVitest(mode, {
1360
1313
  ...normalizeCliOptions(cliFilters, options),
1361
1314
  watch: false,
1362
1315
  run: true
@@ -1374,7 +1327,7 @@ async function collect(mode, cliFilters, options) {
1374
1327
  }
1375
1328
  await ctx.close();
1376
1329
  } catch (e) {
1377
- const { errorBanner } = await import('./index.DehVUBn4.js').then(function (n) { return n.u; });
1330
+ const { errorBanner } = await import('./index.CcRZ6fUh.js').then(function (n) { return n.u; });
1378
1331
  if (console.error(`\n${errorBanner("Collect Error")}`), console.error(e), console.error("\n\n"), process.exitCode == null) process.exitCode = 1;
1379
1332
  process.exit();
1380
1333
  }