vitest 4.1.12 → 5.1.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 (121) hide show
  1. package/LICENSE.md +192 -10
  2. package/browser/context.d.ts +7 -1
  3. package/browser/context.js +5 -5
  4. package/config.d.ts +0 -2
  5. package/dist/browser.d.ts +52 -21
  6. package/dist/browser.js +12 -13
  7. package/dist/chunks/{acorn.B2iPLyUM.js → acorn.C1kjbUFw.js} +30 -30
  8. package/dist/chunks/{base.B6Opl8PE.js → base.Cof-UHJf.js} +81 -52
  9. package/dist/chunks/{browser.d.BcoexmFG.d.ts → browser.d.C7tWgUvw.d.ts} +17 -14
  10. package/dist/chunks/{cac.DzDtg8hz.js → cac.BYbt0aJp.js} +143 -87
  11. package/dist/chunks/{cli-api.B0Pz1_R7.js → cli-api.COfZo8lK.js} +7160 -7189
  12. package/dist/chunks/config.d.B3YV4t0O.d.ts +3873 -0
  13. package/dist/chunks/{console.3WNpx0tS.js → console.CQZ877Hi.js} +69 -63
  14. package/dist/chunks/{constants.CPYnjOGj.js → constants.DLYM6cZY.js} +2 -2
  15. package/dist/chunks/coverage.9iqXE2gN.js +26 -0
  16. package/dist/chunks/{coverage.CTzCuANN.js → coverage.jGCktcGP.js} +7 -2
  17. package/dist/chunks/{creator.DgVhQm5q.js → creator.DHWmytIK.js} +65 -28
  18. package/dist/chunks/{defaults.9aQKnqFk.js → defaults.B1FCaFfh.js} +16 -9
  19. package/dist/chunks/display.BlTmubjj.js +194 -0
  20. package/dist/chunks/doctor.B-oPbwps.js +465 -0
  21. package/dist/chunks/{env.D4Lgay0q.js → env.BKKtU2WC.js} +2 -1
  22. package/dist/chunks/{environment.d.CrsxCzP1.d.ts → environment.d.BFQtFKdZ.d.ts} +9 -1
  23. package/dist/chunks/globals.ZKtKSkEf.js +29 -0
  24. package/dist/chunks/index.Bi0NXYPf.js +1708 -0
  25. package/dist/chunks/{index.CMESou6r.js → index.BoyTG_B7.js} +82 -81
  26. package/dist/chunks/index.CZzC1gGg.js +8501 -0
  27. package/dist/chunks/index.D0heQG4v.js +1318 -0
  28. package/dist/chunks/index.Di8au7q4.js +15665 -0
  29. package/dist/chunks/{index.Chj8NDwU.js → index.DmDMHCg8.js} +6 -12
  30. package/dist/chunks/{index.DXx9Dtk7.js → index.w_oBZ9N8.js} +25 -12
  31. package/dist/chunks/{init-forks.H5ZuobOQ.js → init-forks.BaDXQSD8.js} +7 -10
  32. package/dist/chunks/{init-threads.6kl1khcL.js → init-threads.ZX_Vov0z.js} +1 -1
  33. package/dist/chunks/{init.k9zZ9sLh.js → init.CO4AB7HZ.js} +113 -38
  34. package/dist/chunks/module-dependencies._2Eei3FO.js +71 -0
  35. package/dist/chunks/{native.DPzPHdi5.js → native.upB-V0CK.js} +50 -37
  36. package/dist/chunks/{nativeModuleMocker.BkNfQMkH.js → nativeModuleMocker.Dh5azSB4.js} +48 -19
  37. package/dist/chunks/{index.BCY_7LL2.js → nativeModuleRunner.9xPIMzi7.js} +110 -42
  38. package/dist/chunks/node.B9mkVmLH.js +47 -0
  39. package/dist/chunks/offset.Dy-5Fdfn.js +24 -0
  40. package/dist/chunks/pathe.M-eThtNZ.zq3TM4NT.js +492 -0
  41. package/dist/chunks/{reporters.d.DtoKVV2s.d.ts → plugin.d.LRFSN46m.d.ts} +2573 -1453
  42. package/dist/chunks/plugins.DPQHVT0p.js +37 -0
  43. package/dist/chunks/rawSnapshot.DqSiqIEx.js +356 -0
  44. package/dist/chunks/resolver.BzpmeQeT.js +48 -0
  45. package/dist/chunks/rpc.Uhkwr2NM.js +93 -0
  46. package/dist/chunks/rpc.d.3FOhdFx8.d.ts +75 -0
  47. package/dist/chunks/run.CjdgFZiW.js +4231 -0
  48. package/dist/chunks/setup-common.CqAQCXzx.js +36 -0
  49. package/dist/chunks/source-map.DakdQc29.js +1788 -0
  50. package/dist/chunks/source-map.d.BkG8YK_3.d.ts +89 -0
  51. package/dist/chunks/spy.DDMXghXv.js +509 -0
  52. package/dist/chunks/task-utils.d.D-gFPNFi.d.ts +144 -0
  53. package/dist/chunks/tinyrainbow.Do8I1XRG.js +88 -0
  54. package/dist/chunks/{utils.BS4fH3nR.js → utils.BBk_icFG.js} +50 -52
  55. package/dist/chunks/{utils.BX5Fg8C4.js → utils.DYj33du9.js} +1 -17
  56. package/dist/chunks/vm.b4MbCAJQ.js +1329 -0
  57. package/dist/chunks/{worker.d.ZpHpO4yb.d.ts → worker.d.CyJRpyfZ.d.ts} +34 -19
  58. package/dist/cli.js +5 -6
  59. package/dist/config.cjs +9 -6
  60. package/dist/config.d.ts +27 -25
  61. package/dist/config.js +3 -3
  62. package/dist/index.d.ts +471 -38
  63. package/dist/index.js +18 -19
  64. package/dist/module-evaluator.d.ts +64 -5
  65. package/dist/module-evaluator.js +122 -62
  66. package/dist/node.d.ts +355 -87
  67. package/dist/node.js +49 -73
  68. package/dist/runtime.d.ts +43 -6
  69. package/dist/runtime.js +7 -9
  70. package/dist/spy.js +1 -1
  71. package/dist/task-utils.js +290 -0
  72. package/dist/{chunks/traces.DT5aQ62U.js → traces.js} +3 -2
  73. package/dist/worker.d.ts +8 -10
  74. package/dist/worker.js +33 -43
  75. package/dist/workers/forks.js +30 -40
  76. package/dist/workers/runVmTests.js +66 -43
  77. package/dist/workers/threads.js +30 -40
  78. package/dist/workers/vmForks.js +19 -20
  79. package/dist/workers/vmThreads.js +19 -20
  80. package/globals.d.ts +19 -19
  81. package/index.cjs +3 -3
  82. package/optional-runtime-types.d.ts +1 -1
  83. package/optional-types.d.ts +1 -1
  84. package/package.json +59 -74
  85. package/suppress-warnings.cjs +1 -1
  86. package/dist/chunks/_commonjsHelpers.D26ty3Ew.js +0 -6
  87. package/dist/chunks/benchmark.CX_oY03V.js +0 -40
  88. package/dist/chunks/benchmark.d.DAaHLpsq.d.ts +0 -24
  89. package/dist/chunks/config.d.A1h_Y6Jt.d.ts +0 -232
  90. package/dist/chunks/coverage.DM_a_rWm.js +0 -1087
  91. package/dist/chunks/coverage.d.BZtK59WP.d.ts +0 -37
  92. package/dist/chunks/evaluatedModules.Dg1zASAC.js +0 -17
  93. package/dist/chunks/global.d.DVsSRdQ5.d.ts +0 -100
  94. package/dist/chunks/globals.Dj1TGiMC.js +0 -31
  95. package/dist/chunks/index.DC7d2Pf8.js +0 -729
  96. package/dist/chunks/index.DdgEv5B1.js +0 -42
  97. package/dist/chunks/index.UpGiHP7g.js +0 -4255
  98. package/dist/chunks/index.og1WyBLx.js +0 -6358
  99. package/dist/chunks/nativeModuleRunner.BIakptoF.js +0 -36
  100. package/dist/chunks/node.COQbm6gK.js +0 -14
  101. package/dist/chunks/plugin.d.DwFIiJ7i.d.ts +0 -38
  102. package/dist/chunks/rpc.MzXet3jl.js +0 -144
  103. package/dist/chunks/rpc.d.B_8sPU0w.d.ts +0 -30
  104. package/dist/chunks/setup-common.DYx3LtFI.js +0 -60
  105. package/dist/chunks/startVitestModuleRunner.DB-7oCpn.js +0 -740
  106. package/dist/chunks/suite.d.udJtyAgw.d.ts +0 -10
  107. package/dist/chunks/test.DNmyFkvJ.js +0 -4430
  108. package/dist/chunks/traces.d.D2T_R8rx.d.ts +0 -60
  109. package/dist/chunks/vm.CXMd5FHa.js +0 -785
  110. package/dist/coverage.d.ts +0 -123
  111. package/dist/coverage.js +0 -27
  112. package/dist/environments.d.ts +0 -22
  113. package/dist/environments.js +0 -5
  114. package/dist/reporters.d.ts +0 -27
  115. package/dist/reporters.js +0 -26
  116. package/dist/runners.d.ts +0 -70
  117. package/dist/runners.js +0 -19
  118. package/dist/snapshot.d.ts +0 -9
  119. package/dist/snapshot.js +0 -6
  120. package/dist/suite.d.ts +0 -5
  121. package/dist/suite.js +0 -8
package/dist/node.js CHANGED
@@ -1,53 +1,21 @@
1
1
  import * as vite from 'vite';
2
- import { resolveConfig as resolveConfig$1, mergeConfig } from 'vite';
3
2
  export { esbuildVersion, isCSSRequest, isFileLoadingAllowed, parseAst, parseAstAsync, rollupVersion, version as viteVersion } from 'vite';
4
- import { V as Vitest, a as VitestPlugin } from './chunks/cli-api.B0Pz1_R7.js';
5
- export { F as ForksPoolWorker, G as GitNotFoundError, b as TestsNotFoundError, T as ThreadsPoolWorker, c as TypecheckPoolWorker, d as VitestPackageInstaller, e as VmForksPoolWorker, f as VmThreadsPoolWorker, g as createDebugger, h as createMethodsRPC, i as createViteLogger, j as createVitest, k as escapeTestName, l as experimental_getRunnerTask, m as getFilePoolName, n as isFileServingAllowed, o as isValidApiRequest, r as registerConsoleShortcuts, p as resolveFsAllow, s as startVitest } from './chunks/cli-api.B0Pz1_R7.js';
6
- export { p as parseCLI } from './chunks/cac.DzDtg8hz.js';
7
- import { r as resolveConfig$2 } from './chunks/coverage.DM_a_rWm.js';
8
- export { B as BaseCoverageProvider, a as BaseSequencer, b as resolveApiServerConfig } from './chunks/coverage.DM_a_rWm.js';
9
- import { slash, deepClone } from '@vitest/utils/helpers';
10
- import { a as any } from './chunks/index.og1WyBLx.js';
11
- import { resolve } from 'pathe';
12
- import { c as configFiles } from './chunks/constants.CPYnjOGj.js';
13
- export { M as AgentReporter, B as BenchmarkReporter, a as BenchmarkReportsMap, D as DefaultReporter, b as DotReporter, G as GithubActionsReporter, H as HangingProcessReporter, J as JUnitReporter, c as JsonReporter, M as MinimalReporter, R as ReportersMap, T as TapFlatReporter, d as TapReporter, V as VerboseBenchmarkReporter, e as VerboseReporter } from './chunks/index.UpGiHP7g.js';
3
+ import { V as Vitest } from './chunks/cli-api.COfZo8lK.js';
4
+ export { M as AgentReporter, B as BaseCoverageProvider, D as DefaultReporter, a as DotReporter, G as GitVCSProvider, b as GithubActionsReporter, H as HangingProcessReporter, J as JUnitReporter, c as JsonReporter, M as MinimalReporter, d as MtimeVCSProvider, R as ReportersMap, T as TapFlatReporter, e as TapReporter, f as VerboseReporter, g as createVitest, h as experimental_getRunnerTask, i as isValidApiRequest, r as registerConsoleShortcuts, s as startVitest } from './chunks/cli-api.COfZo8lK.js';
5
+ export { B as BaseSequencer, a as BrowserConnectionError, F as ForksPoolWorker, G as GitNotFoundError, L as Logger, P as PluginHarness, b as TestsNotFoundError, T as ThreadsPoolWorker, c as TypecheckPoolWorker, V as VitestPackageInstaller, d as VmForksPoolWorker, e as VmThreadsPoolWorker, f as createDebugger, g as createMethodsRPC, h as createViteLogger, i as escapeTestName, j as getFilePoolName, k as isFileServingAllowed, r as resolveApiServerConfig, l as resolveConfig, m as resolveFsAllow } from './chunks/index.Di8au7q4.js';
6
+ export { c as createCLI, p as parseCLI } from './chunks/cac.BYbt0aJp.js';
14
7
  export { distDir, rootDir } from './path.js';
15
- export { generateFileHash } from '@vitest/runner/utils';
8
+ export { generateFileHash } from './task-utils.js';
9
+ export { w as disableDefaultColors } from './chunks/tinyrainbow.Do8I1XRG.js';
16
10
  import 'node:fs';
17
- import './chunks/coverage.CTzCuANN.js';
18
- import 'node:path';
19
- import './chunks/index.BCY_7LL2.js';
20
- import 'node:module';
21
- import 'node:process';
11
+ import './chunks/coverage.jGCktcGP.js';
12
+ import './chunks/pathe.M-eThtNZ.zq3TM4NT.js';
22
13
  import 'node:fs/promises';
23
- import 'node:url';
24
- import 'node:assert';
25
- import 'node:v8';
26
- import 'node:util';
27
14
  import 'node:os';
28
- import '@vitest/snapshot/manager';
29
- import '@vitest/utils/serialize';
30
- import './chunks/nativeModuleRunner.BIakptoF.js';
31
- import 'vite/module-runner';
32
- import './chunks/traces.DT5aQ62U.js';
33
- import 'obug';
34
- import 'tinyrainbow';
35
- import '#module-evaluator';
36
- import 'node:console';
37
- import './chunks/_commonjsHelpers.D26ty3Ew.js';
38
- import './chunks/utils.BS4fH3nR.js';
39
- import './chunks/env.D4Lgay0q.js';
40
- import 'std-env';
41
- import 'node:tty';
42
- import 'node:crypto';
43
- import 'node:events';
44
- import './chunks/index.Chj8NDwU.js';
45
- import './chunks/modules.BJuCwlRJ.js';
46
- import 'node:child_process';
47
- import 'node:worker_threads';
48
- import 'picomatch';
49
- import 'tinyglobby';
15
+ import './chunks/source-map.DakdQc29.js';
16
+ import './chunks/index.D0heQG4v.js';
50
17
  import 'node:perf_hooks';
18
+ import './chunks/index.DmDMHCg8.js';
51
19
  import 'events';
52
20
  import 'https';
53
21
  import 'http';
@@ -58,43 +26,51 @@ import 'stream';
58
26
  import 'url';
59
27
  import 'zlib';
60
28
  import 'buffer';
61
- import './chunks/defaults.9aQKnqFk.js';
29
+ import 'util';
30
+ import './chunks/constants.DLYM6cZY.js';
31
+ import './chunks/modules.BJuCwlRJ.js';
32
+ import 'node:module';
33
+ import 'node:crypto';
34
+ import './chunks/run.CjdgFZiW.js';
35
+ import './chunks/display.BlTmubjj.js';
36
+ import './chunks/nativeModuleRunner.9xPIMzi7.js';
37
+ import 'node:url';
38
+ import 'node:path';
39
+ import 'node:process';
40
+ import 'node:assert';
41
+ import 'node:v8';
42
+ import 'node:util';
43
+ import 'vite/module-runner';
44
+ import './traces.js';
45
+ import './chunks/utils.BBk_icFG.js';
46
+ import 'picomatch';
47
+ import 'tinyglobby';
48
+ import './chunks/defaults.B1FCaFfh.js';
49
+ import './chunks/env.BKKtU2WC.js';
50
+ import 'std-env';
51
+ import 'tinyexec';
52
+ import 'node:readline';
53
+ import './chunks/rawSnapshot.DqSiqIEx.js';
54
+ import './chunks/offset.Dy-5Fdfn.js';
55
+ import './chunks/plugins.DPQHVT0p.js';
62
56
  import 'magic-string';
63
57
  import '@vitest/mocker/node';
64
- import '@vitest/utils/constants';
65
- import '@vitest/utils/resolver';
58
+ import 'node:console';
59
+ import 'node:stream';
60
+ import 'obug';
61
+ import './chunks/resolver.BzpmeQeT.js';
66
62
  import 'es-module-lexer';
67
- import '@vitest/utils/source-map';
68
- import '@vitest/utils/source-map/node';
69
- import 'tinyexec';
70
- import 'node:readline';
63
+ import '#module-evaluator';
64
+ import './chunks/module-dependencies._2Eei3FO.js';
65
+ import 'node:tty';
66
+ import 'node:events';
67
+ import 'node:child_process';
68
+ import 'node:worker_threads';
71
69
  import 'readline';
72
- import 'node:stream';
73
- import '@vitest/utils/display';
74
- import '@vitest/utils/offset';
75
-
76
- // this is only exported as a public function and not used inside vitest
77
- async function resolveConfig(options = {}, viteOverrides = {}) {
78
- const root = slash(resolve(options.root || process.cwd()));
79
- const configPath = options.config === false ? false : options.config ? resolve(root, options.config) : any(configFiles, { cwd: root });
80
- options.config = configPath;
81
- const vitest = new Vitest("test", deepClone(options));
82
- const config = await resolveConfig$1(mergeConfig({
83
- configFile: configPath,
84
- mode: options.mode || "test",
85
- plugins: [await VitestPlugin(options, vitest)]
86
- }, mergeConfig(viteOverrides, { root: options.root })), "serve");
87
- const vitestConfig = resolveConfig$2(vitest, Reflect.get(config, "_vitest"), config);
88
- await vitest.close();
89
- return {
90
- viteConfig: config,
91
- vitestConfig
92
- };
93
- }
94
70
 
95
71
  const version = Vitest.version;
96
72
  const createViteServer = vite.createServer;
97
73
  // rolldownVersion is exported only by rolldown-vite
98
74
  const rolldownVersion = vite.rolldownVersion;
99
75
 
100
- export { VitestPlugin, createViteServer, resolveConfig, rolldownVersion, version };
76
+ export { createViteServer, rolldownVersion, version };
package/dist/runtime.d.ts CHANGED
@@ -1,6 +1,43 @@
1
- export { builtinEnvironments, populateGlobal } from './environments.js';
2
- export { VitestSnapshotEnvironment } from './snapshot.js';
3
- export { E as Environment, a as EnvironmentReturn, V as VmEnvironmentReturn } from './chunks/environment.d.CrsxCzP1.js';
4
- export { VitestRunner, VitestRunnerConfig } from '@vitest/runner';
5
- export { SnapshotEnvironment } from '@vitest/snapshot/environment';
6
- import '@vitest/utils';
1
+ import { E as Environment } from './chunks/environment.d.BFQtFKdZ.js';
2
+ export { a as EnvironmentReturn, V as VmEnvironmentReturn } from './chunks/environment.d.BFQtFKdZ.js';
3
+ import { bu as SnapshotEnvironment, bv as SnapshotEnvironmentOptions } from './chunks/config.d.B3YV4t0O.js';
4
+ export { b as SerializedConfig, V as VitestRunner } from './chunks/config.d.B3YV4t0O.js';
5
+ import 'vitest/optional-runtime-types.js';
6
+ import 'tinybench';
7
+
8
+ declare const environments: {
9
+ node: Environment;
10
+ jsdom: Environment;
11
+ "happy-dom": Environment;
12
+ "edge-runtime": Environment;
13
+ };
14
+
15
+ interface PopulateOptions {
16
+ bindFunctions?: boolean;
17
+ additionalKeys?: string[];
18
+ }
19
+ declare function populateGlobal(global: any, win: any, options?: PopulateOptions): {
20
+ keys: Set<string>;
21
+ skipKeys: string[];
22
+ originals: Map<string | symbol, PropertyDescriptor>;
23
+ };
24
+
25
+ declare class NodeSnapshotEnvironment implements SnapshotEnvironment {
26
+ private options;
27
+ constructor(options?: SnapshotEnvironmentOptions);
28
+ getVersion(): string;
29
+ getHeader(): string;
30
+ resolveRawPath(testPath: string, rawPath: string): Promise<string>;
31
+ resolvePath(filepath: string): Promise<string>;
32
+ prepareDirectory(dirPath: string): Promise<void>;
33
+ saveSnapshotFile(filepath: string, snapshot: string): Promise<void>;
34
+ readSnapshotFile(filepath: string): Promise<string | null>;
35
+ removeSnapshotFile(filepath: string): Promise<void>;
36
+ }
37
+
38
+ declare class VitestNodeSnapshotEnvironment extends NodeSnapshotEnvironment {
39
+ getHeader(): string;
40
+ resolvePath(filepath: string): Promise<string>;
41
+ }
42
+
43
+ export { Environment, SnapshotEnvironment, VitestNodeSnapshotEnvironment as VitestSnapshotEnvironment, environments as builtinEnvironments, populateGlobal };
package/dist/runtime.js CHANGED
@@ -1,24 +1,22 @@
1
1
  import { VitestModuleEvaluator } from './module-evaluator.js';
2
- import { V as VITEST_VM_CONTEXT_SYMBOL, s as startVitestModuleRunner, a as VitestModuleRunner } from './chunks/startVitestModuleRunner.DB-7oCpn.js';
3
- import { g as getWorkerState } from './chunks/utils.BX5Fg8C4.js';
4
- export { e as builtinEnvironments, p as populateGlobal } from './chunks/index.DC7d2Pf8.js';
5
- export { VitestNodeSnapshotEnvironment as VitestSnapshotEnvironment } from './chunks/node.COQbm6gK.js';
2
+ import { V as VITEST_VM_CONTEXT_SYMBOL, s as startVitestModuleRunner, a as VitestModuleRunner } from './chunks/index.Bi0NXYPf.js';
3
+ export { e as builtinEnvironments, p as populateGlobal } from './chunks/index.Bi0NXYPf.js';
4
+ import { g as getWorkerState } from './chunks/utils.DYj33du9.js';
5
+ export { VitestNodeSnapshotEnvironment as VitestSnapshotEnvironment } from './chunks/node.B9mkVmLH.js';
6
6
  import 'node:module';
7
7
  import 'node:url';
8
8
  import 'node:vm';
9
9
  import 'vite/module-runner';
10
- import './chunks/traces.DT5aQ62U.js';
10
+ import './traces.js';
11
11
  import 'node:fs';
12
- import '@vitest/utils/helpers';
12
+ import './chunks/pathe.M-eThtNZ.zq3TM4NT.js';
13
13
  import './chunks/modules.BJuCwlRJ.js';
14
- import 'pathe';
15
14
  import './path.js';
16
15
  import 'node:path';
16
+ import 'node:async_hooks';
17
17
  import '@vitest/mocker';
18
18
  import '@vitest/mocker/redirect';
19
- import '@vitest/utils/timers';
20
19
  import 'node:console';
21
- import '@vitest/snapshot/environment';
22
20
 
23
21
  /**
24
22
  * @internal
package/dist/spy.js CHANGED
@@ -1 +1 @@
1
- export * from '@vitest/spy';
1
+ export { c as clearAllMocks, d as createMockInstance, f as fn, i as isMockFunction, b as resetAllMocks, r as restoreAllMocks, a as spyOn } from './chunks/spy.DDMXghXv.js';
@@ -0,0 +1,290 @@
1
+ import { t as toArray, a as relative } from './chunks/pathe.M-eThtNZ.zq3TM4NT.js';
2
+
3
+ /* @__NO_SIDE_EFFECTS__ */
4
+ function isTestCase(s) {
5
+ return s.type === "test";
6
+ }
7
+ /* @__NO_SIDE_EFFECTS__ */
8
+ function getTests(suite) {
9
+ const tests = [];
10
+ const arraySuites = toArray(suite);
11
+ for (const s of arraySuites) if (/* @__PURE__ */ isTestCase(s)) tests.push(s);
12
+ else for (const task of s.tasks) if (/* @__PURE__ */ isTestCase(task)) tests.push(task);
13
+ else {
14
+ const taskTests = /* @__PURE__ */ getTests(task);
15
+ for (const test of taskTests) tests.push(test);
16
+ }
17
+ return tests;
18
+ }
19
+ /* @__NO_SIDE_EFFECTS__ */
20
+ function getTasks(tasks = []) {
21
+ return toArray(tasks).flatMap((s) => /* @__PURE__ */ isTestCase(s) ? [s] : [s, .../* @__PURE__ */ getTasks(s.tasks)]);
22
+ }
23
+ /* @__NO_SIDE_EFFECTS__ */
24
+ function getSuites(suite) {
25
+ return toArray(suite).flatMap((s) => s.type === "suite" ? [s, .../* @__PURE__ */ getSuites(s.tasks)] : []);
26
+ }
27
+ /* @__NO_SIDE_EFFECTS__ */
28
+ function hasFailed(suite) {
29
+ return toArray(suite).some((s) => s.result?.state === "fail" || s.type === "suite" && /* @__PURE__ */ hasFailed(s.tasks));
30
+ }
31
+ /* @__NO_SIDE_EFFECTS__ */
32
+ function getNames(task) {
33
+ const names = [task.name];
34
+ let current = task;
35
+ while (current?.suite) {
36
+ current = current.suite;
37
+ if (current?.name) names.unshift(current.name);
38
+ }
39
+ if (current !== task.file) names.unshift(task.file.name);
40
+ return names;
41
+ }
42
+ /* @__NO_SIDE_EFFECTS__ */
43
+ function getFullName(task, separator = " > ") {
44
+ return (/* @__PURE__ */ getNames(task)).join(separator);
45
+ }
46
+ /* @__NO_SIDE_EFFECTS__ */
47
+ function getTestName(task, separator = " > ") {
48
+ return (/* @__PURE__ */ getNames(task)).slice(1).join(separator);
49
+ }
50
+ /* @__NO_SIDE_EFFECTS__ */
51
+ function createTaskName(names, separator = " > ") {
52
+ return names.filter((name) => name !== void 0).join(separator);
53
+ }
54
+ /* @__NO_SIDE_EFFECTS__ */
55
+ function isSnapshotMatchError(error) {
56
+ return typeof error?.message === "string" && /Snapshot .* mismatched/.test(error.message);
57
+ }
58
+ /* @__NO_SIDE_EFFECTS__ */
59
+ function hasFailedSnapshot(suite) {
60
+ return (/* @__PURE__ */ getTests(suite)).some((s) => {
61
+ return s.result?.errors?.some(isSnapshotMatchError);
62
+ });
63
+ }
64
+ /* @__NO_SIDE_EFFECTS__ */
65
+ function convertTasksToEvents(file, onTask) {
66
+ const packs = [];
67
+ const events = [];
68
+ function visit(suite) {
69
+ onTask?.(suite);
70
+ packs.push([
71
+ suite.id,
72
+ suite.result,
73
+ suite.meta
74
+ ]);
75
+ events.push([
76
+ suite.id,
77
+ "suite-prepare",
78
+ void 0
79
+ ]);
80
+ suite.tasks.forEach((task) => {
81
+ if (task.type === "suite") visit(task);
82
+ else {
83
+ onTask?.(task);
84
+ if (suite.mode !== "skip" && suite.mode !== "todo") {
85
+ packs.push([
86
+ task.id,
87
+ task.result,
88
+ task.meta
89
+ ]);
90
+ events.push([
91
+ task.id,
92
+ "test-prepare",
93
+ void 0
94
+ ]);
95
+ task.annotations.forEach((annotation) => {
96
+ events.push([
97
+ task.id,
98
+ "test-annotation",
99
+ { annotation }
100
+ ]);
101
+ });
102
+ task.artifacts.forEach((artifact) => {
103
+ events.push([
104
+ task.id,
105
+ "test-artifact",
106
+ { artifact }
107
+ ]);
108
+ });
109
+ events.push([
110
+ task.id,
111
+ "test-finished",
112
+ void 0
113
+ ]);
114
+ }
115
+ }
116
+ });
117
+ events.push([
118
+ suite.id,
119
+ "suite-finished",
120
+ void 0
121
+ ]);
122
+ }
123
+ visit(file);
124
+ return {
125
+ packs,
126
+ events
127
+ };
128
+ }
129
+ /* @__NO_SIDE_EFFECTS__ */
130
+ function createFileTask(filepath, root, projectName, pool, viteEnvironment, meta) {
131
+ const path = relative(root, filepath);
132
+ // this can be called outside of the test run, so worker might not be there
133
+ // @ts-expect-error injected global
134
+ const workerState = globalThis.__vitest_worker__;
135
+ const file = {
136
+ id: /* @__PURE__ */ generateFileHash(path, projectName, meta),
137
+ name: path,
138
+ fullName: path,
139
+ type: "suite",
140
+ mode: "queued",
141
+ filepath,
142
+ tasks: [],
143
+ meta: Object.assign(Object.create(null), meta),
144
+ projectName,
145
+ file: void 0,
146
+ pool,
147
+ viteEnvironment,
148
+ concurrencyId: workerState?.ctx.concurrencyId ?? 0,
149
+ workerId: workerState?.ctx.workerId ?? 0
150
+ };
151
+ file.file = file;
152
+ return file;
153
+ }
154
+ /**
155
+ * Generate a unique ID for a file based on its path and project name
156
+ * @param file File relative to the root of the project to keep ID the same between different machines
157
+ * @param projectName The name of the test project
158
+ */
159
+ /* @__NO_SIDE_EFFECTS__ */
160
+ function generateFileHash(file, projectName, meta) {
161
+ return /* @__PURE__ */ generateHash([
162
+ file,
163
+ projectName || "",
164
+ meta?.typecheck ? "__typecheck__" : "",
165
+ meta?.__vitest_label__ || ""
166
+ ].join("\0"));
167
+ }
168
+ /* @__NO_SIDE_EFFECTS__ */
169
+ function generateHash(str) {
170
+ let hash = 0;
171
+ if (str.length === 0) return `${hash}`;
172
+ for (let i = 0; i < str.length; i++) {
173
+ const char = str.charCodeAt(i);
174
+ hash = (hash << 5) - hash + char;
175
+ hash = hash & hash;
176
+ }
177
+ return `${hash}`;
178
+ }
179
+ function calculateSuiteHash(parent) {
180
+ parent.tasks.forEach((t, idx) => {
181
+ t.id = `${parent.id}_${idx}`;
182
+ if (t.type === "suite") calculateSuiteHash(t);
183
+ });
184
+ }
185
+ /**
186
+ * If any tasks been marked as `only`, mark all other tasks as `skip`.
187
+ */
188
+ function interpretTaskModes(file, namePattern, testLocations, testIds, testNames, testTagsFilter, onlyMode, parentIsOnly, allowOnly) {
189
+ const matchedLocations = [];
190
+ const testLocationsSet = testLocations !== void 0 && testLocations.length !== 0 ? new Set(testLocations) : void 0;
191
+ const testIdsSet = testIds ? new Set(testIds) : void 0;
192
+ const testNamesSet = testNames ? new Set(testNames) : void 0;
193
+ const traverseSuite = (suite, parentIsOnly, parentMatchedWithLocation) => {
194
+ const suiteIsOnly = parentIsOnly || suite.mode === "only";
195
+ // Check if any tasks in this suite have `.only` - if so, only those should run.
196
+ // `containsOnly` is computed during collection (in the runtime/AST collectors).
197
+ const hasSomeTasksOnly = !!(onlyMode && suite.containsOnly);
198
+ suite.tasks.forEach((t) => {
199
+ // Check if either the parent suite or the task itself are marked as included
200
+ // If there are tasks with `.only` in this suite, only include those (not all tasks from describe.only)
201
+ const includeTask = hasSomeTasksOnly ? t.mode === "only" || t.type === "suite" && !!t.containsOnly : suiteIsOnly || t.mode === "only";
202
+ if (onlyMode) {
203
+ if (t.type === "suite" && (includeTask || t.containsOnly)) {
204
+ // Don't skip this suite
205
+ if (t.mode === "only") {
206
+ checkAllowOnly(t, allowOnly);
207
+ t.mode = "run";
208
+ }
209
+ } else if (t.mode === "run" && !includeTask) t.mode = "skip";
210
+ else if (t.mode === "only") {
211
+ checkAllowOnly(t, allowOnly);
212
+ t.mode = "run";
213
+ }
214
+ }
215
+ let hasLocationMatch = parentMatchedWithLocation;
216
+ // Match test location against provided locations, only run if present
217
+ // in `testLocations`. Note: if `includeTaskLocation` is not enabled,
218
+ // all test will be skipped.
219
+ if (testLocationsSet !== void 0) {
220
+ if (t.location && testLocationsSet.has(t.location.line)) {
221
+ t.mode = "run";
222
+ matchedLocations.push(t.location.line);
223
+ hasLocationMatch = true;
224
+ } else if (parentMatchedWithLocation) t.mode = "run";
225
+ else if (t.type === "test") t.mode = "skip";
226
+ }
227
+ if (t.type === "test") {
228
+ // oxlint-disable-next-line unicorn/prefer-regexp-test -- namePattern can be a string
229
+ if (namePattern && !t.fullTestName.match(namePattern)) t.mode = "skip";
230
+ if (testIdsSet && !testIdsSet.has(t.id)) t.mode = "skip";
231
+ if (testNamesSet && !testNamesSet.has(t.fullTestName)) t.mode = "skip";
232
+ if (testTagsFilter && !testTagsFilter(t.tags || [])) t.mode = "skip";
233
+ } else if (t.type === "suite") {
234
+ if (t.mode === "skip") skipAllTasks(t);
235
+ else if (t.mode === "todo") todoAllTasks(t);
236
+ else traverseSuite(t, includeTask, hasLocationMatch);
237
+ }
238
+ });
239
+ // if all subtasks are skipped, mark as skip
240
+ if (suite.mode === "run" || suite.mode === "queued") {
241
+ if (suite.tasks.length && suite.tasks.every((i) => i.mode !== "run" && i.mode !== "queued")) suite.mode = "skip";
242
+ }
243
+ };
244
+ traverseSuite(file, parentIsOnly, false);
245
+ const nonMatching = testLocations?.filter((loc) => !matchedLocations.includes(loc));
246
+ if (nonMatching && nonMatching.length !== 0) {
247
+ const message = nonMatching.length === 1 ? `line ${nonMatching[0]}` : `lines ${nonMatching.join(", ")}`;
248
+ if (file.result === void 0) file.result = {
249
+ state: "fail",
250
+ errors: []
251
+ };
252
+ if (file.result.errors === void 0) file.result.errors = [];
253
+ const error = /* @__PURE__ */ new Error(`No test found in ${file.name} in ${message}`);
254
+ file.result.errors.push({
255
+ name: error.name,
256
+ message: error.message,
257
+ stack: error.stack
258
+ });
259
+ }
260
+ }
261
+ function skipAllTasks(suite) {
262
+ suite.tasks.forEach((t) => {
263
+ if (t.mode === "run" || t.mode === "queued") {
264
+ t.mode = "skip";
265
+ if (t.type === "suite") skipAllTasks(t);
266
+ }
267
+ });
268
+ }
269
+ function todoAllTasks(suite) {
270
+ suite.tasks.forEach((t) => {
271
+ if (t.mode === "run" || t.mode === "queued") {
272
+ t.mode = "todo";
273
+ if (t.type === "suite") todoAllTasks(t);
274
+ }
275
+ });
276
+ }
277
+ function checkAllowOnly(task, allowOnly) {
278
+ if (allowOnly) return;
279
+ const error = /* @__PURE__ */ new Error("[Vitest] Unexpected .only modifier. Remove it or pass --allowOnly argument to bypass this error");
280
+ task.result = {
281
+ state: "fail",
282
+ errors: [{
283
+ name: error.name,
284
+ message: error.message,
285
+ stack: error.stack
286
+ }]
287
+ };
288
+ }
289
+
290
+ export { calculateSuiteHash, convertTasksToEvents, createFileTask, createTaskName, generateFileHash, generateHash, getFullName, getNames, getSuites, getTasks, getTestName, getTests, hasFailed, hasFailedSnapshot, interpretTaskModes, isSnapshotMatchError, isTestCase };
@@ -13,7 +13,7 @@ class Traces {
13
13
  constructor(options) {
14
14
  if (options.enabled) {
15
15
  const apiInit = import('@opentelemetry/api').then((api) => {
16
- this.#otel = {
16
+ const otel = {
17
17
  tracer: api.trace.getTracer(options.tracerName || "vitest"),
18
18
  context: api.context,
19
19
  propagation: api.propagation,
@@ -21,6 +21,7 @@ class Traces {
21
21
  SpanKind: api.SpanKind,
22
22
  SpanStatusCode: api.SpanStatusCode
23
23
  };
24
+ this.#otel = otel;
24
25
  }).catch(() => {
25
26
  throw new Error(`"@opentelemetry/api" is not installed locally. Make sure you have setup OpenTelemetry instrumentation: https://vitest.dev/guide/open-telemetry`);
26
27
  });
@@ -214,4 +215,4 @@ function createNoopContext() {
214
215
  };
215
216
  }
216
217
 
217
- export { Traces as T };
218
+ export { Traces };
package/dist/worker.d.ts CHANGED
@@ -1,14 +1,12 @@
1
- import { W as WorkerGlobalState, a as WorkerSetupContext, B as BirpcOptions } from './chunks/worker.d.ZpHpO4yb.js';
2
- import { T as Traces } from './chunks/traces.d.D2T_R8rx.js';
3
- import { Awaitable } from '@vitest/utils';
1
+ import { d as WorkerSetupContext, e as BirpcOptions } from './chunks/worker.d.CyJRpyfZ.js';
2
+ import { WorkerGlobalState } from './index.js';
3
+ import { T as Traces } from './chunks/rpc.d.3FOhdFx8.js';
4
+ import { RuntimeRPC } from './index.js';
5
+ import { A as Awaitable } from './chunks/config.d.B3YV4t0O.js';
4
6
  import { ModuleRunner } from 'vite/module-runner';
5
- import { R as RuntimeRPC } from './chunks/rpc.d.B_8sPU0w.js';
6
- import '@vitest/runner';
7
- import './chunks/config.d.A1h_Y6Jt.js';
8
- import '@vitest/pretty-format';
9
- import '@vitest/snapshot';
10
- import '@vitest/utils/diff';
11
- import './chunks/environment.d.CrsxCzP1.js';
7
+ import './chunks/environment.d.BFQtFKdZ.js';
8
+ import 'vitest/optional-runtime-types.js';
9
+ import 'tinybench';
12
10
 
13
11
  /** @experimental */
14
12
  declare function setupBaseEnvironment(context: WorkerSetupContext): Promise<() => Promise<void>>;
package/dist/worker.js CHANGED
@@ -1,55 +1,45 @@
1
- export { r as runBaseTests, s as setupEnvironment } from './chunks/base.B6Opl8PE.js';
2
- export { i as init } from './chunks/init.k9zZ9sLh.js';
1
+ export { r as runBaseTests, s as setupEnvironment } from './chunks/base.Cof-UHJf.js';
2
+ export { i as init } from './chunks/init.CO4AB7HZ.js';
3
3
  import 'node:vm';
4
- import '@vitest/spy';
5
- import './chunks/index.DXx9Dtk7.js';
6
- import '@vitest/expect';
4
+ import './chunks/spy.DDMXghXv.js';
5
+ import './chunks/index.w_oBZ9N8.js';
6
+ import 'chai';
7
7
  import 'node:async_hooks';
8
- import './chunks/setup-common.DYx3LtFI.js';
9
- import './chunks/coverage.CTzCuANN.js';
10
- import '@vitest/snapshot';
11
- import '@vitest/utils/timers';
12
- import './chunks/utils.BX5Fg8C4.js';
13
- import './chunks/rpc.MzXet3jl.js';
14
- import './chunks/index.Chj8NDwU.js';
15
- import './chunks/test.DNmyFkvJ.js';
16
- import '@vitest/runner';
17
- import '@vitest/utils/helpers';
18
- import './chunks/benchmark.CX_oY03V.js';
19
- import '@vitest/runner/utils';
20
- import '@vitest/utils/error';
21
- import 'pathe';
22
- import '@vitest/utils/offset';
23
- import '@vitest/utils/source-map';
24
- import './chunks/_commonjsHelpers.D26ty3Ew.js';
25
- import './chunks/nativeModuleRunner.BIakptoF.js';
26
- import 'node:url';
27
- import './chunks/index.BCY_7LL2.js';
28
- import 'node:fs';
8
+ import './chunks/coverage.9iqXE2gN.js';
9
+ import './chunks/coverage.jGCktcGP.js';
10
+ import './chunks/pathe.M-eThtNZ.zq3TM4NT.js';
11
+ import './chunks/rpc.Uhkwr2NM.js';
12
+ import 'vite/module-runner';
13
+ import './chunks/source-map.DakdQc29.js';
14
+ import './chunks/index.D0heQG4v.js';
15
+ import './chunks/tinyrainbow.Do8I1XRG.js';
16
+ import './chunks/index.DmDMHCg8.js';
17
+ import './chunks/utils.DYj33du9.js';
18
+ import './chunks/setup-common.CqAQCXzx.js';
19
+ import './chunks/plugins.DPQHVT0p.js';
20
+ import './chunks/index.CZzC1gGg.js';
21
+ import './chunks/run.CjdgFZiW.js';
22
+ import './chunks/display.BlTmubjj.js';
23
+ import './task-utils.js';
24
+ import './chunks/rawSnapshot.DqSiqIEx.js';
25
+ import './chunks/offset.Dy-5Fdfn.js';
26
+ import 'tinybench';
27
+ import 'expect-type';
28
+ import './chunks/module-dependencies._2Eei3FO.js';
29
29
  import 'node:module';
30
+ import 'node:url';
31
+ import './path.js';
30
32
  import 'node:path';
31
- import 'node:process';
32
- import 'node:fs/promises';
33
- import 'node:assert';
34
- import 'node:v8';
35
- import 'node:util';
36
- import 'vite/module-runner';
37
- import './chunks/traces.DT5aQ62U.js';
38
- import './chunks/evaluatedModules.Dg1zASAC.js';
39
- import './chunks/startVitestModuleRunner.DB-7oCpn.js';
33
+ import './traces.js';
34
+ import './chunks/index.Bi0NXYPf.js';
35
+ import 'node:fs';
40
36
  import './chunks/modules.BJuCwlRJ.js';
41
- import './path.js';
42
37
  import './module-evaluator.js';
43
38
  import '@vitest/mocker';
44
39
  import '@vitest/mocker/redirect';
40
+ import 'node:console';
45
41
  import 'node:perf_hooks';
46
42
  import './chunks/inspector.CvyFGlXm.js';
47
43
  import 'node:timers';
48
44
  import 'node:timers/promises';
49
- import '@vitest/utils/constants';
50
- import './chunks/index.DdgEv5B1.js';
51
- import 'expect-type';
52
- import './chunks/index.DC7d2Pf8.js';
53
- import 'node:console';
54
- import '@vitest/utils/serialize';
55
- import 'tinyrainbow';
45
+ import 'node:util';