vitest 3.2.4 → 4.0.0-beta.10

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 (88) hide show
  1. package/LICENSE.md +2 -2
  2. package/dist/browser.d.ts +13 -16
  3. package/dist/browser.js +6 -5
  4. package/dist/chunks/base.Cjha6usc.js +129 -0
  5. package/dist/chunks/{benchmark.CYdenmiT.js → benchmark.CJUa-Hsa.js} +6 -8
  6. package/dist/chunks/{benchmark.d.BwvBVTda.d.ts → benchmark.d.DAaHLpsq.d.ts} +4 -4
  7. package/dist/chunks/browser.d.yFAklsD1.d.ts +18 -0
  8. package/dist/chunks/{cac.Cb-PYCCB.js → cac.DCxo_nSu.js} +72 -163
  9. package/dist/chunks/{cli-api.BkDphVBG.js → cli-api.BJJXh9BV.js} +1331 -1678
  10. package/dist/chunks/{config.d.D2ROskhv.d.ts → config.d.B_LthbQq.d.ts} +59 -65
  11. package/dist/chunks/{console.CtFJOzRO.js → console.7h5kHUIf.js} +34 -70
  12. package/dist/chunks/{constants.DnKduX2e.js → constants.D_Q9UYh-.js} +1 -9
  13. package/dist/chunks/{coverage.DL5VHqXY.js → coverage.BCU-r2QL.js} +538 -765
  14. package/dist/chunks/{coverage.DVF1vEu8.js → coverage.D_JHT54q.js} +2 -2
  15. package/dist/chunks/{coverage.d.S9RMNXIe.d.ts → coverage.d.BZtK59WP.d.ts} +10 -8
  16. package/dist/chunks/{creator.GK6I-cL4.js → creator.08Gi-vCA.js} +93 -77
  17. package/dist/chunks/{date.Bq6ZW5rf.js → date.-jtEtIeV.js} +6 -17
  18. package/dist/chunks/{defaults.B7q_naMc.js → defaults.CXFFjsi8.js} +2 -42
  19. package/dist/chunks/environment.d.BsToaxti.d.ts +65 -0
  20. package/dist/chunks/{git.BVQ8w_Sw.js → git.BFNcloKD.js} +1 -2
  21. package/dist/chunks/{global.d.MAmajcmJ.d.ts → global.d.BK3X7FW1.d.ts} +7 -32
  22. package/dist/chunks/{globals.DEHgCU4V.js → globals.DG-S3xFe.js} +8 -8
  23. package/dist/chunks/{index.VByaPkjc.js → index.BIP7prJq.js} +472 -803
  24. package/dist/chunks/{index.B521nVV-.js → index.Bgo3tNWt.js} +23 -4
  25. package/dist/chunks/{index.BCWujgDG.js → index.BjKEiSn0.js} +14 -24
  26. package/dist/chunks/{index.CdQS2e2Q.js → index.CMfqw92x.js} +7 -8
  27. package/dist/chunks/{index.CmSc2RE5.js → index.DIWhzsUh.js} +72 -118
  28. package/dist/chunks/{inspector.C914Efll.js → inspector.CvQD-Nie.js} +10 -25
  29. package/dist/chunks/moduleRunner.d.D9nBoC4p.d.ts +201 -0
  30. package/dist/chunks/moduleTransport.I-bgQy0S.js +19 -0
  31. package/dist/chunks/{node.fjCdwEIl.js → node.CyipiPvJ.js} +1 -1
  32. package/dist/chunks/plugin.d.BMVSnsGV.d.ts +9 -0
  33. package/dist/chunks/{reporters.d.BFLkQcL6.d.ts → reporters.d.BUWjmRYq.d.ts} +2086 -2146
  34. package/dist/chunks/resolveSnapshotEnvironment.Bkht6Yor.js +81 -0
  35. package/dist/chunks/resolver.Bx6lE0iq.js +119 -0
  36. package/dist/chunks/rpc.BKr6mtxz.js +65 -0
  37. package/dist/chunks/{setup-common.Dd054P77.js → setup-common.uiMcU3cv.js} +17 -29
  38. package/dist/chunks/startModuleRunner.p67gbNo9.js +665 -0
  39. package/dist/chunks/{suite.d.FvehnV49.d.ts → suite.d.BJWk38HB.d.ts} +1 -1
  40. package/dist/chunks/test.BiqSKISg.js +214 -0
  41. package/dist/chunks/{typechecker.DRKU1-1g.js → typechecker.DB-fIMaH.js} +165 -234
  42. package/dist/chunks/{utils.CAioKnHs.js → utils.C2YI6McM.js} +5 -14
  43. package/dist/chunks/{utils.XdZDrNZV.js → utils.D2R2NiOH.js} +8 -27
  44. package/dist/chunks/{vi.bdSIJ99Y.js → vi.ZPgvtBao.js} +156 -305
  45. package/dist/chunks/{vm.BThCzidc.js → vm.Ca0Y0W5f.js} +116 -226
  46. package/dist/chunks/{worker.d.1GmBbd7G.d.ts → worker.d.BDsXGkwh.d.ts} +31 -32
  47. package/dist/chunks/{worker.d.CKwWzBSj.d.ts → worker.d.BNcX_2mH.d.ts} +1 -1
  48. package/dist/cli.js +10 -10
  49. package/dist/config.cjs +5 -58
  50. package/dist/config.d.ts +72 -71
  51. package/dist/config.js +3 -9
  52. package/dist/coverage.d.ts +31 -24
  53. package/dist/coverage.js +9 -9
  54. package/dist/environments.d.ts +9 -14
  55. package/dist/environments.js +1 -1
  56. package/dist/index.d.ts +52 -213
  57. package/dist/index.js +7 -9
  58. package/dist/module-evaluator.d.ts +13 -0
  59. package/dist/module-evaluator.js +276 -0
  60. package/dist/module-runner.js +15 -0
  61. package/dist/node.d.ts +62 -51
  62. package/dist/node.js +26 -42
  63. package/dist/reporters.d.ts +11 -12
  64. package/dist/reporters.js +12 -12
  65. package/dist/runners.d.ts +3 -4
  66. package/dist/runners.js +13 -231
  67. package/dist/snapshot.js +2 -2
  68. package/dist/suite.d.ts +2 -2
  69. package/dist/suite.js +2 -2
  70. package/dist/worker.js +90 -47
  71. package/dist/workers/forks.js +34 -10
  72. package/dist/workers/runVmTests.js +36 -56
  73. package/dist/workers/threads.js +34 -10
  74. package/dist/workers/vmForks.js +11 -10
  75. package/dist/workers/vmThreads.js +11 -10
  76. package/dist/workers.d.ts +5 -7
  77. package/dist/workers.js +35 -17
  78. package/globals.d.ts +17 -17
  79. package/package.json +32 -31
  80. package/dist/chunks/base.DfmxU-tU.js +0 -38
  81. package/dist/chunks/environment.d.cL3nLXbE.d.ts +0 -119
  82. package/dist/chunks/execute.B7h3T_Hc.js +0 -708
  83. package/dist/chunks/index.CwejwG0H.js +0 -105
  84. package/dist/chunks/rpc.-pEldfrD.js +0 -83
  85. package/dist/chunks/runBaseTests.9Ij9_de-.js +0 -129
  86. package/dist/chunks/vite.d.CMLlLIFP.d.ts +0 -25
  87. package/dist/execute.d.ts +0 -150
  88. package/dist/execute.js +0 -13
package/LICENSE.md CHANGED
@@ -3,7 +3,7 @@ Vitest is released under the MIT license:
3
3
 
4
4
  MIT License
5
5
 
6
- Copyright (c) 2021-Present Vitest Team
6
+ Copyright (c) 2021-Present VoidZero Inc. and Vitest contributors
7
7
 
8
8
  Permission is hereby granted, free of charge, to any person obtaining a copy
9
9
  of this software and associated documentation files (the "Software"), to deal
@@ -329,7 +329,7 @@ Repository: lukeed/kleur
329
329
  ## local-pkg
330
330
  License: MIT
331
331
  By: Anthony Fu
332
- Repository: git+https://github.com/antfu/local-pkg.git
332
+ Repository: git+https://github.com/antfu-collective/local-pkg.git
333
333
 
334
334
  > MIT License
335
335
  >
package/dist/browser.d.ts CHANGED
@@ -1,34 +1,31 @@
1
- import { S as SerializedCoverageConfig, a as SerializedConfig } from './chunks/config.d.D2ROskhv.js';
2
- import { R as RuntimeCoverageModuleLoader } from './chunks/coverage.d.S9RMNXIe.js';
1
+ import { S as SerializedCoverageConfig, a as SerializedConfig } from './chunks/config.d.B_LthbQq.js';
2
+ import { R as RuntimeCoverageModuleLoader } from './chunks/coverage.d.BZtK59WP.js';
3
3
  import { SerializedDiffOptions } from '@vitest/utils/diff';
4
- import { VitestExecutor } from './execute.js';
4
+ import { V as VitestModuleRunner } from './chunks/moduleRunner.d.D9nBoC4p.js';
5
5
  export { collectTests, processError, startTests } from '@vitest/runner';
6
- import * as spy from '@vitest/spy';
7
- export { spy as SpyModule };
8
- export { LoupeOptions, ParsedStack, StringifyOptions, format, getSafeTimers, inspect, stringify } from '@vitest/utils';
6
+ import * as _vitest_spy from '@vitest/spy';
7
+ export { _vitest_spy as SpyModule };
8
+ export { LoupeOptions, ParsedStack, StringifyOptions, format, getSafeTimers, getType, inspect, stringify } from '@vitest/utils';
9
9
  export { TraceMap, originalPositionFor } from '@vitest/utils/source-map';
10
10
  import '@vitest/pretty-format';
11
11
  import '@vitest/snapshot';
12
- import '@vitest/snapshot/environment';
13
- import 'vite-node/client';
14
- import 'vite-node';
15
- import './chunks/worker.d.1GmBbd7G.js';
16
- import './chunks/environment.d.cL3nLXbE.js';
17
- import 'vitest/optional-types.js';
18
12
  import 'node:vm';
13
+ import 'vite/module-runner';
14
+ import './chunks/worker.d.BDsXGkwh.js';
15
+ import './chunks/environment.d.BsToaxti.js';
19
16
  import '@vitest/mocker';
20
17
  import './chunks/mocker.d.BE_2ls6u.js';
21
18
 
22
19
  declare function startCoverageInsideWorker(options: SerializedCoverageConfig | undefined, loader: RuntimeCoverageModuleLoader, runtimeOptions: {
23
- isolate: boolean
20
+ isolate: boolean;
24
21
  }): Promise<unknown>;
25
22
  declare function takeCoverageInsideWorker(options: SerializedCoverageConfig | undefined, loader: RuntimeCoverageModuleLoader): Promise<unknown>;
26
23
  declare function stopCoverageInsideWorker(options: SerializedCoverageConfig | undefined, loader: RuntimeCoverageModuleLoader, runtimeOptions: {
27
- isolate: boolean
24
+ isolate: boolean;
28
25
  }): Promise<unknown>;
29
26
 
30
27
  declare function setupCommonEnv(config: SerializedConfig): Promise<void>;
31
- declare function loadDiffConfig(config: SerializedConfig, executor: VitestExecutor): Promise<SerializedDiffOptions | undefined>;
32
- declare function loadSnapshotSerializers(config: SerializedConfig, executor: VitestExecutor): Promise<void>;
28
+ declare function loadDiffConfig(config: SerializedConfig, moduleRunner: VitestModuleRunner): Promise<SerializedDiffOptions | undefined>;
29
+ declare function loadSnapshotSerializers(config: SerializedConfig, moduleRunner: VitestModuleRunner): Promise<void>;
33
30
 
34
31
  export { loadDiffConfig, loadSnapshotSerializers, setupCommonEnv, startCoverageInsideWorker, stopCoverageInsideWorker, takeCoverageInsideWorker };
package/dist/browser.js CHANGED
@@ -1,8 +1,9 @@
1
- export { l as loadDiffConfig, b as loadSnapshotSerializers, c as setupCommonEnv, s as startCoverageInsideWorker, a as stopCoverageInsideWorker, t as takeCoverageInsideWorker } from './chunks/setup-common.Dd054P77.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.uiMcU3cv.js';
2
2
  export { collectTests, processError, startTests } from '@vitest/runner';
3
- import * as spy from '@vitest/spy';
4
- export { spy as SpyModule };
5
- export { format, getSafeTimers, inspect, stringify } from '@vitest/utils';
3
+ import * as spyModule from '@vitest/spy';
4
+ export { spyModule as SpyModule };
5
+ export { format, getSafeTimers, getType, inspect, stringify } from '@vitest/utils';
6
6
  export { TraceMap, originalPositionFor } from '@vitest/utils/source-map';
7
- import './chunks/coverage.DVF1vEu8.js';
7
+ import './chunks/coverage.D_JHT54q.js';
8
8
  import '@vitest/snapshot';
9
+ import './chunks/utils.D2R2NiOH.js';
@@ -0,0 +1,129 @@
1
+ import { runInThisContext } from 'node:vm';
2
+ import * as spyModule from '@vitest/spy';
3
+ import { EvaluatedModules } from 'vite/module-runner';
4
+ import { s as startVitestModuleRunner, c as createNodeImportMeta } from './startModuleRunner.p67gbNo9.js';
5
+ import { performance } from 'node:perf_hooks';
6
+ import { startTests, collectTests } from '@vitest/runner';
7
+ import { a as resolveSnapshotEnvironment, s as setupChaiConfig, r as resolveTestRunner } from './resolveSnapshotEnvironment.Bkht6Yor.js';
8
+ import { c as setupCommonEnv, s as startCoverageInsideWorker, a as stopCoverageInsideWorker } from './setup-common.uiMcU3cv.js';
9
+ import { g as globalExpect, v as vi } from './vi.ZPgvtBao.js';
10
+ import { c as closeInspector } from './inspector.CvQD-Nie.js';
11
+ import { createRequire } from 'node:module';
12
+ import timers from 'node:timers';
13
+ import timersPromises from 'node:timers/promises';
14
+ import util from 'node:util';
15
+ import { KNOWN_ASSET_TYPES, getSafeTimers } from '@vitest/utils';
16
+ import { i as index } from './index.CMfqw92x.js';
17
+ import { g as getWorkerState, r as resetModules, p as provideWorkerState } from './utils.D2R2NiOH.js';
18
+
19
+ // this should only be used in Node
20
+ let globalSetup = false;
21
+ async function setupGlobalEnv(config, { environment }, moduleRunner) {
22
+ await setupCommonEnv(config), Object.defineProperty(globalThis, "__vitest_index__", {
23
+ value: index,
24
+ enumerable: false
25
+ });
26
+ const state = getWorkerState();
27
+ if (!state.config.snapshotOptions.snapshotEnvironment) state.config.snapshotOptions.snapshotEnvironment = await resolveSnapshotEnvironment(config, moduleRunner);
28
+ if (globalSetup) return;
29
+ globalSetup = true;
30
+ const viteEnvironment = environment.viteEnvironment || environment.name;
31
+ if (viteEnvironment === "client") {
32
+ const _require = createRequire(import.meta.url);
33
+ _require.extensions[".css"] = resolveCss, _require.extensions[".scss"] = resolveCss, _require.extensions[".sass"] = resolveCss, _require.extensions[".less"] = resolveCss, KNOWN_ASSET_TYPES.forEach((type) => {
34
+ _require.extensions[`.${type}`] = resolveAsset;
35
+ }), process.env.SSR = "";
36
+ } else process.env.SSR = "1";
37
+ if (globalThis.__vitest_required__ = {
38
+ util,
39
+ timers,
40
+ timersPromises
41
+ }, !config.disableConsoleIntercept) await setupConsoleLogSpy();
42
+ }
43
+ function resolveCss(mod) {
44
+ mod.exports = "";
45
+ }
46
+ function resolveAsset(mod, url) {
47
+ mod.exports = url;
48
+ }
49
+ async function setupConsoleLogSpy() {
50
+ const { createCustomConsole } = await import('./console.7h5kHUIf.js');
51
+ globalThis.console = createCustomConsole();
52
+ }
53
+ async function withEnv({ environment }, options, fn) {
54
+ globalThis.__vitest_environment__ = environment.name, globalExpect.setState({ environment: environment.name });
55
+ const env = await environment.setup(globalThis, options);
56
+ try {
57
+ await fn();
58
+ } finally {
59
+ // Run possible setTimeouts, e.g. the onces used by ConsoleLogSpy
60
+ const { setTimeout } = getSafeTimers();
61
+ await new Promise((resolve) => setTimeout(resolve)), await env.teardown(globalThis);
62
+ }
63
+ }
64
+
65
+ // browser shouldn't call this!
66
+ async function run(method, files, config, environment, moduleRunner) {
67
+ const workerState = getWorkerState(), isIsolatedThreads = config.pool === "threads" && (config.poolOptions?.threads?.isolate ?? true), isIsolatedForks = config.pool === "forks" && (config.poolOptions?.forks?.isolate ?? true), isolate = isIsolatedThreads || isIsolatedForks;
68
+ if (await setupGlobalEnv(config, environment, moduleRunner), await startCoverageInsideWorker(config.coverage, moduleRunner, { isolate }), config.chaiConfig) setupChaiConfig(config.chaiConfig);
69
+ const runner = await resolveTestRunner(config, moduleRunner);
70
+ workerState.onCancel.then((reason) => {
71
+ closeInspector(config), runner.cancel?.(reason);
72
+ }), workerState.durations.prepare = performance.now() - workerState.durations.prepare, workerState.durations.environment = performance.now(), await withEnv(environment, environment.options || config.environmentOptions || {}, async () => {
73
+ workerState.durations.environment = performance.now() - workerState.durations.environment;
74
+ for (const file of files) {
75
+ if (isolate) moduleRunner.mocker.reset(), resetModules(workerState.evaluatedModules, true);
76
+ if (workerState.filepath = file.filepath, method === "run") await startTests([file], runner);
77
+ else await collectTests([file], runner);
78
+ // mocks should not affect different files
79
+ vi.resetConfig(), vi.restoreAllMocks();
80
+ }
81
+ await stopCoverageInsideWorker(config.coverage, moduleRunner, { isolate });
82
+ }), workerState.environmentTeardownRun = true;
83
+ }
84
+
85
+ let _moduleRunner;
86
+ const evaluatedModules = new EvaluatedModules(), moduleExecutionInfo = /* @__PURE__ */ new Map();
87
+ function startModuleRunner(options) {
88
+ return _moduleRunner || (_moduleRunner = startVitestModuleRunner(options), _moduleRunner);
89
+ }
90
+ async function runBaseTests(method, state) {
91
+ const { ctx } = state;
92
+ if (state.evaluatedModules = evaluatedModules, state.moduleExecutionInfo = moduleExecutionInfo, provideWorkerState(globalThis, state), ctx.invalidates) ctx.invalidates.forEach((filepath) => {
93
+ const modules = state.evaluatedModules.fileToModulesMap.get(filepath) || [];
94
+ modules.forEach((module) => {
95
+ state.evaluatedModules.invalidateModule(module);
96
+ });
97
+ // evaluatedModules.delete(fsPath)
98
+ // evaluatedModules.delete(`mock:${fsPath}`)
99
+ });
100
+ ctx.files.forEach((i) => {
101
+ const filepath = typeof i === "string" ? i : i.filepath, modules = state.evaluatedModules.fileToModulesMap.get(filepath) || [];
102
+ modules.forEach((module) => {
103
+ state.evaluatedModules.invalidateModule(module);
104
+ });
105
+ });
106
+ const executor = startModuleRunner({
107
+ state,
108
+ evaluatedModules: state.evaluatedModules,
109
+ spyModule,
110
+ createImportMeta: createNodeImportMeta
111
+ }), fileSpecs = ctx.files.map((f) => typeof f === "string" ? {
112
+ filepath: f,
113
+ testLocations: void 0
114
+ } : f);
115
+ if (ctx.config.serializedDefines) try {
116
+ runInThisContext(`(() =>{\n${ctx.config.serializedDefines}})()`, {
117
+ lineOffset: 1,
118
+ filename: "virtual:load-defines.js"
119
+ });
120
+ } catch (error) {
121
+ throw new Error(`Failed to load custom "defines": ${error.message}`);
122
+ }
123
+ await run(method, fileSpecs, ctx.config, {
124
+ environment: state.environment,
125
+ options: ctx.environment.options
126
+ }, executor);
127
+ }
128
+
129
+ export { runBaseTests as r };
@@ -1,10 +1,9 @@
1
1
  import { getCurrentSuite } from '@vitest/runner';
2
2
  import { createChainable } from '@vitest/runner/utils';
3
3
  import { noop } from '@vitest/utils';
4
- import { g as getWorkerState } from './utils.XdZDrNZV.js';
4
+ import { g as getWorkerState } from './utils.D2R2NiOH.js';
5
5
 
6
- const benchFns = /* @__PURE__ */ new WeakMap();
7
- const benchOptsMap = /* @__PURE__ */ new WeakMap();
6
+ const benchFns = /* @__PURE__ */ new WeakMap(), benchOptsMap = /* @__PURE__ */ new WeakMap();
8
7
  function getBenchOptions(key) {
9
8
  return benchOptsMap.get(key);
10
9
  }
@@ -17,8 +16,9 @@ const bench = createBenchmark(function(name, fn = noop, options = {}) {
17
16
  ...this,
18
17
  meta: { benchmark: true }
19
18
  });
20
- benchFns.set(task, fn);
21
- benchOptsMap.set(task, options);
19
+ // vitest runner sets mode to `todo` if handler is not passed down
20
+ // but we store handler separetly
21
+ if (benchFns.set(task, fn), benchOptsMap.set(task, options), !this.todo && task.mode === "todo") task.mode = "run";
22
22
  });
23
23
  function createBenchmark(fn) {
24
24
  const benchmark = createChainable([
@@ -26,9 +26,7 @@ function createBenchmark(fn) {
26
26
  "only",
27
27
  "todo"
28
28
  ], fn);
29
- benchmark.skipIf = (condition) => condition ? benchmark.skip : benchmark;
30
- benchmark.runIf = (condition) => condition ? benchmark : benchmark.skip;
31
- return benchmark;
29
+ return benchmark.skipIf = (condition) => condition ? benchmark.skip : benchmark, benchmark.runIf = (condition) => condition ? benchmark : benchmark.skip, benchmark;
32
30
  }
33
31
  function formatName(name) {
34
32
  return typeof name === "string" ? name : typeof name === "function" ? name.name || "<anonymous>" : String(name);
@@ -4,8 +4,8 @@ import { TaskResult, Bench, Options } from 'tinybench';
4
4
 
5
5
  interface Benchmark extends Test {
6
6
  meta: {
7
- benchmark: true
8
- result?: TaskResult
7
+ benchmark: true;
8
+ result?: TaskResult;
9
9
  };
10
10
  }
11
11
  interface BenchmarkResult extends TaskResult {
@@ -17,8 +17,8 @@ interface BenchmarkResult extends TaskResult {
17
17
  type BenchFunction = (this: Bench) => Promise<void> | void;
18
18
  type ChainableBenchmarkAPI = ChainableFunction<"skip" | "only" | "todo", (name: string | Function, fn?: BenchFunction, options?: Options) => void>;
19
19
  type BenchmarkAPI = ChainableBenchmarkAPI & {
20
- skipIf: (condition: any) => ChainableBenchmarkAPI
21
- runIf: (condition: any) => ChainableBenchmarkAPI
20
+ skipIf: (condition: any) => ChainableBenchmarkAPI;
21
+ runIf: (condition: any) => ChainableBenchmarkAPI;
22
22
  };
23
23
 
24
24
  export type { BenchmarkResult as B, BenchFunction as a, Benchmark as b, BenchmarkAPI as c };
@@ -0,0 +1,18 @@
1
+ import { T as TestExecutionMethod } from './worker.d.BDsXGkwh.js';
2
+
3
+ type SerializedTestSpecification = [project: {
4
+ name: string | undefined;
5
+ root: string;
6
+ }, file: string, options: {
7
+ pool: string;
8
+ testLines?: number[] | undefined;
9
+ }];
10
+
11
+ interface BrowserTesterOptions {
12
+ method: TestExecutionMethod;
13
+ files: string[];
14
+ providedContext: string;
15
+ startTime: number;
16
+ }
17
+
18
+ export type { BrowserTesterOptions as B, SerializedTestSpecification as S };