vitest 3.1.0-beta.1 → 3.1.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. package/dist/browser.js +4 -4
  2. package/dist/chunks/base.CylSMlTD.js +41 -0
  3. package/dist/chunks/benchmark.BKUatJGy.js +39 -0
  4. package/dist/chunks/cac.JtTXbKz0.js +1525 -0
  5. package/dist/chunks/{cli-api.BwkkJsRe.js → cli-api.BTtPTYMs.js} +4638 -5072
  6. package/dist/chunks/console.D6t261w0.js +173 -0
  7. package/dist/chunks/constants.BZZyIeIE.js +43 -0
  8. package/dist/chunks/coverage.0iPg4Wrz.js +33 -0
  9. package/dist/chunks/{coverage.gV8doR2Y.js → coverage.C2ohxaN0.js} +2216 -2479
  10. package/dist/chunks/creator.BEXek7yQ.js +640 -0
  11. package/dist/chunks/date.CDOsz-HY.js +53 -0
  12. package/dist/chunks/defaults.DmfNPoe5.js +114 -0
  13. package/dist/chunks/{env.D4Lgay0q.js → env.Dq0hM4Xv.js} +1 -1
  14. package/dist/chunks/execute.DZKwfrTs.js +791 -0
  15. package/dist/chunks/git.DXfdBEfR.js +74 -0
  16. package/dist/chunks/{globals.BEpDe-k3.js → globals.DCbUWjip.js} +10 -10
  17. package/dist/chunks/{index.D7Ny8f_s.js → index.BDobFbcz.js} +6 -7
  18. package/dist/chunks/index.DFXFpH3w.js +607 -0
  19. package/dist/chunks/index.VfYQ6MXY.js +104 -0
  20. package/dist/chunks/index.ZIOEXBQB.js +2382 -0
  21. package/dist/chunks/inspector.DbDkSkFn.js +54 -0
  22. package/dist/chunks/node.IqGoMrm4.js +15 -0
  23. package/dist/chunks/{reporters.d.r7poTZjA.d.ts → reporters.d.5g6jXhoW.d.ts} +14 -3
  24. package/dist/chunks/rpc.DGgL5dw7.js +92 -0
  25. package/dist/chunks/run-once.I7PpBOk1.js +47 -0
  26. package/dist/chunks/runBaseTests.CqmKSG99.js +134 -0
  27. package/dist/chunks/setup-common.DEGDGBiA.js +88 -0
  28. package/dist/chunks/{typechecker.BlF3eHsb.js → typechecker.C2IpOhid.js} +620 -622
  29. package/dist/chunks/utils.BfxieIyZ.js +66 -0
  30. package/dist/chunks/utils.CtocqOoE.js +72 -0
  31. package/dist/chunks/utils.OLmtDstN.js +194 -0
  32. package/dist/chunks/{vi.nSCvwQ7l.js → vi.B-PuvDzu.js} +878 -1019
  33. package/dist/chunks/vite.d.Dh1jE-_V.d.ts +23 -0
  34. package/dist/chunks/vm.BW5voG-u.js +789 -0
  35. package/dist/cli.js +2 -2
  36. package/dist/config.cjs +97 -103
  37. package/dist/config.d.ts +3 -3
  38. package/dist/config.js +6 -6
  39. package/dist/coverage.d.ts +1 -1
  40. package/dist/coverage.js +6 -6
  41. package/dist/environments.js +1 -1
  42. package/dist/execute.js +1 -1
  43. package/dist/index.d.ts +2 -2
  44. package/dist/index.js +6 -6
  45. package/dist/node.d.ts +3 -3
  46. package/dist/node.js +36 -45
  47. package/dist/path.js +1 -4
  48. package/dist/reporters.d.ts +1 -1
  49. package/dist/reporters.js +4 -4
  50. package/dist/runners.js +231 -267
  51. package/dist/snapshot.js +2 -2
  52. package/dist/suite.js +2 -2
  53. package/dist/worker.js +98 -114
  54. package/dist/workers/forks.js +22 -22
  55. package/dist/workers/runVmTests.js +61 -66
  56. package/dist/workers/threads.js +13 -13
  57. package/dist/workers/vmForks.js +24 -24
  58. package/dist/workers/vmThreads.js +15 -15
  59. package/dist/workers.js +10 -10
  60. package/package.json +11 -11
  61. package/dist/chunks/base.DV59CbtV.js +0 -45
  62. package/dist/chunks/benchmark.DL72EVN-.js +0 -40
  63. package/dist/chunks/cac.BjmXy7OV.js +0 -1664
  64. package/dist/chunks/console.CN7AiMGV.js +0 -179
  65. package/dist/chunks/constants.DTYd6dNH.js +0 -46
  66. package/dist/chunks/coverage.A3sS5-Wm.js +0 -40
  67. package/dist/chunks/creator.BsBnpTzI.js +0 -670
  68. package/dist/chunks/date.W2xKR2qe.js +0 -53
  69. package/dist/chunks/defaults.C2Ndd9wx.js +0 -119
  70. package/dist/chunks/execute.eDH0aFFd.js +0 -839
  71. package/dist/chunks/git.B5SDxu-n.js +0 -69
  72. package/dist/chunks/index.DOyx6FYJ.js +0 -2551
  73. package/dist/chunks/index.K90BXFOx.js +0 -658
  74. package/dist/chunks/index.uXkkC4xl.js +0 -111
  75. package/dist/chunks/inspector.DKLceBVD.js +0 -54
  76. package/dist/chunks/node.AKq966Jp.js +0 -15
  77. package/dist/chunks/rpc.TVf73xOu.js +0 -102
  78. package/dist/chunks/run-once.2ogXb3JV.js +0 -28
  79. package/dist/chunks/runBaseTests.BVrL_ow3.js +0 -142
  80. package/dist/chunks/setup-common.CPvtqi8q.js +0 -96
  81. package/dist/chunks/utils.C8RiOc4B.js +0 -77
  82. package/dist/chunks/utils.Cn0zI1t3.js +0 -68
  83. package/dist/chunks/utils.bLM2atbD.js +0 -198
  84. package/dist/chunks/vite.d.Fvq-NZoa.d.ts +0 -11
  85. package/dist/chunks/vm.jEFQDlX_.js +0 -852
@@ -0,0 +1,54 @@
1
+ import { createRequire } from 'node:module';
2
+ import { pathToFileURL } from 'node:url';
3
+
4
+ const __require = createRequire(import.meta.url);
5
+ let inspector;
6
+ let session;
7
+ /**
8
+ * Enables debugging inside `worker_threads` and `child_process`.
9
+ * Should be called as early as possible when worker/process has been set up.
10
+ */
11
+ function setupInspect(ctx) {
12
+ const config = ctx.config;
13
+ const isEnabled = config.inspector.enabled;
14
+ if (isEnabled) {
15
+ inspector = __require("node:inspector");
16
+ const isOpen = inspector.url() !== undefined;
17
+ if (!isOpen) {
18
+ inspector.open(config.inspector.port, config.inspector.host, config.inspector.waitForDebugger);
19
+ if (config.inspectBrk) {
20
+ const firstTestFile = typeof ctx.files[0] === "string" ? ctx.files[0] : ctx.files[0].filepath;
21
+ if (firstTestFile) {
22
+ session = new inspector.Session();
23
+ session.connect();
24
+ session.post("Debugger.enable");
25
+ session.post("Debugger.setBreakpointByUrl", {
26
+ lineNumber: 0,
27
+ url: pathToFileURL(firstTestFile)
28
+ });
29
+ }
30
+ }
31
+ }
32
+ }
33
+ const keepOpen = shouldKeepOpen(config);
34
+ return function cleanup() {
35
+ if (isEnabled && !keepOpen && inspector) {
36
+ inspector.close();
37
+ session?.disconnect();
38
+ }
39
+ };
40
+ }
41
+ function closeInspector(config) {
42
+ const keepOpen = shouldKeepOpen(config);
43
+ if (inspector && !keepOpen) {
44
+ inspector.close();
45
+ session?.disconnect();
46
+ }
47
+ }
48
+ function shouldKeepOpen(config) {
49
+ const isIsolatedSingleThread = config.pool === "threads" && config.poolOptions?.threads?.isolate === false && config.poolOptions?.threads?.singleThread;
50
+ const isIsolatedSingleFork = config.pool === "forks" && config.poolOptions?.forks?.isolate === false && config.poolOptions?.forks?.singleFork;
51
+ return config.watch && (isIsolatedSingleFork || isIsolatedSingleThread);
52
+ }
53
+
54
+ export { closeInspector as c, setupInspect as s };
@@ -0,0 +1,15 @@
1
+ import { NodeSnapshotEnvironment } from '@vitest/snapshot/environment';
2
+ import { g as getWorkerState } from './utils.CtocqOoE.js';
3
+ import '@vitest/utils';
4
+
5
+ class VitestNodeSnapshotEnvironment extends NodeSnapshotEnvironment {
6
+ getHeader() {
7
+ return `// Vitest Snapshot v${this.getVersion()}, https://vitest.dev/guide/snapshot.html`;
8
+ }
9
+ resolvePath(filepath) {
10
+ const rpc = getWorkerState().rpc;
11
+ return rpc.resolveSnapshotPath(filepath);
12
+ }
13
+ }
14
+
15
+ export { VitestNodeSnapshotEnvironment };
@@ -2238,7 +2238,7 @@ interface UserWorkspaceConfig extends UserConfig$1 {
2238
2238
  }
2239
2239
  type UserProjectConfigFn = (env: ConfigEnv) => UserWorkspaceConfig | Promise<UserWorkspaceConfig>;
2240
2240
  type UserProjectConfigExport = UserWorkspaceConfig | Promise<UserWorkspaceConfig> | UserProjectConfigFn;
2241
- type TestProjectConfiguration = string | (UserProjectConfigExport & {
2241
+ type TestProjectInlineConfiguration = (UserWorkspaceConfig & {
2242
2242
  /**
2243
2243
  * Relative path to the extendable config. All other options will be merged with this config.
2244
2244
  * If `true`, the project will inherit all options from the root config.
@@ -2246,6 +2246,7 @@ type TestProjectConfiguration = string | (UserProjectConfigExport & {
2246
2246
  */
2247
2247
  extends?: string | true
2248
2248
  });
2249
+ type TestProjectConfiguration = string | TestProjectInlineConfiguration | Promise<UserWorkspaceConfig> | UserProjectConfigFn;
2249
2250
  /** @deprecated use `TestProjectConfiguration` instead */
2250
2251
  type WorkspaceProjectConfiguration = TestProjectConfiguration;
2251
2252
 
@@ -2636,7 +2637,7 @@ interface SerializedTestProject {
2636
2637
  serializedConfig: SerializedConfig;
2637
2638
  context: ProvidedContext;
2638
2639
  }
2639
- interface InitializeProjectOptions extends UserWorkspaceConfig {
2640
+ interface InitializeProjectOptions extends TestProjectInlineConfiguration {
2640
2641
  configFile: string | false;
2641
2642
  }
2642
2643
 
@@ -2825,6 +2826,12 @@ declare class Vitest {
2825
2826
  /** @deprecated internal */
2826
2827
  setServer(options: UserConfig, server: ViteDevServer, cliOptions: UserConfig): Promise<void>;
2827
2828
  /**
2829
+ * Inject new test projects into the workspace.
2830
+ * @param config Glob, config path or a custom config options.
2831
+ * @returns An array of new test projects. Can be empty if the name was filtered out.
2832
+ */
2833
+ private injectTestProject;
2834
+ /**
2828
2835
  * Provide a value to the test context. This value will be available to all tests with `inject`.
2829
2836
  */
2830
2837
  provide: <T extends keyof ProvidedContext & string>(key: T, value: ProvidedContext[T]) => void;
@@ -3005,8 +3012,12 @@ declare class Vitest {
3005
3012
  * vitest.onFilterWatchedSpecification(specification => testsToRun.includes(specification.moduleId))
3006
3013
  */
3007
3014
  onFilterWatchedSpecification(fn: (specification: TestSpecification) => boolean): void;
3015
+ /**
3016
+ * Check if the project with a given name should be included.
3017
+ */
3018
+ matchesProjectFilter(name: string): boolean;
3008
3019
  }
3009
3020
  type OnServerRestartHandler = (reason?: string) => Promise<void> | void;
3010
3021
  type OnTestsRerunHandler = (testFiles: TestSpecification[]) => Promise<void> | void;
3011
3022
 
3012
- export { type JUnitOptions as $, type ApiConfig as A, type BaseCoverageOptions as B, CoverageMap as C, type DepsOptimizationOptions as D, TestProject as E, type TestSequencer as F, TestSpecification as G, TestModule as H, type InlineConfig as I, type OnTestsRerunHandler as J, VitestPackageInstaller as K, Logger as L, type ModuleDiagnostic as M, type ProcessPool as N, type OnServerRestartHandler as O, type Pool as P, type WorkspaceSpec as Q, type ResolvedCoverageOptions as R, type SerializedTestSpecification as S, type TestProjectConfiguration as T, type UserWorkspaceConfig as U, Vitest as V, type WorkspaceProjectConfiguration as W, getFilePoolName as X, type SerializedTestProject as Y, type HTMLOptions as Z, type JsonOptions$1 as _, type ReportContext as a, type TaskOptions as a0, TestCase as a1, TestCollection as a2, type TestDiagnostic as a3, type TestModuleState as a4, type TestResult as a5, type TestResultFailed as a6, type TestResultPassed as a7, type TestResultSkipped as a8, type TestState as a9, BenchmarkReportsMap as aA, DefaultReporter as aB, DotReporter as aC, GithubActionsReporter as aD, HangingProcessReporter as aE, JsonReporter as aF, JUnitReporter as aG, ReportersMap as aH, TapFlatReporter as aI, TapReporter as aJ, VerboseBenchmarkReporter as aK, VerboseReporter as aL, BaseReporter as aM, type BenchmarkBuiltinReporters as aN, type BuiltinReporterOptions as aO, type BuiltinReporters as aP, type JsonAssertionResult as aQ, type JsonTestResult as aR, type JsonTestResults as aS, TestSuite as aa, type TestSuiteState as ab, type TestSequencerConstructor as ac, type BrowserBuiltinProvider as ad, type BrowserCommand as ae, type BrowserCommandContext as af, type BrowserInstanceOption as ag, type BrowserOrchestrator as ah, type BrowserProvider as ai, type BrowserProviderInitializationOptions as aj, type BrowserProviderModule as ak, type BrowserProviderOptions as al, type BrowserServerState as am, type BrowserServerStateSession as an, type CDPSession as ao, type ParentProjectBrowser as ap, type ProjectBrowser as aq, type ResolvedBrowserOptions as ar, type ResolvedProjectConfig as as, type ResolveSnapshotPathHandler as at, type ResolveSnapshotPathHandlerContext as au, type TestRunResult as av, type ReportedHookContext as aw, type TestRunEndReason as ax, BasicReporter as ay, BenchmarkReporter as az, type CoverageV8Options as b, type UserProjectConfigFn as c, type UserProjectConfigExport as d, type CoverageProvider as e, type CoverageProviderModule as f, type CoverageReporter as g, type CoverageProviderName as h, type CoverageOptions as i, type CoverageIstanbulOptions as j, type CustomProviderOptions as k, type Reporter as l, type BrowserScript as m, type BrowserConfigOptions as n, type BuiltinEnvironment as o, type VitestEnvironment as p, type PoolOptions as q, type CSSModuleScopeStrategy as r, type VitestRunMode as s, type TransformModePatterns as t, type TypecheckConfig as u, type UserConfig as v, type ResolvedConfig as w, type ProjectConfig as x, type BenchmarkUserOptions as y, type VitestOptions as z };
3023
+ export { type JsonOptions$1 as $, type ApiConfig as A, type BaseCoverageOptions as B, CoverageMap as C, type DepsOptimizationOptions as D, type BenchmarkUserOptions as E, type VitestOptions as F, type TestSequencer as G, TestSpecification as H, type InlineConfig as I, TestModule as J, type OnTestsRerunHandler as K, Logger as L, type ModuleDiagnostic as M, VitestPackageInstaller as N, type OnServerRestartHandler as O, type Pool as P, type ProcessPool as Q, type ResolvedCoverageOptions as R, type SerializedTestSpecification as S, TestProject as T, type UserWorkspaceConfig as U, Vitest as V, type WorkspaceProjectConfiguration as W, type WorkspaceSpec as X, getFilePoolName as Y, type SerializedTestProject as Z, type HTMLOptions as _, type ReportContext as a, type JUnitOptions as a0, type TaskOptions as a1, TestCase as a2, TestCollection as a3, type TestDiagnostic as a4, type TestModuleState as a5, type TestResult as a6, type TestResultFailed as a7, type TestResultPassed as a8, type TestResultSkipped as a9, BenchmarkReporter as aA, BenchmarkReportsMap as aB, DefaultReporter as aC, DotReporter as aD, GithubActionsReporter as aE, HangingProcessReporter as aF, JsonReporter as aG, JUnitReporter as aH, ReportersMap as aI, TapFlatReporter as aJ, TapReporter as aK, VerboseBenchmarkReporter as aL, VerboseReporter as aM, BaseReporter as aN, type BenchmarkBuiltinReporters as aO, type BuiltinReporterOptions as aP, type BuiltinReporters as aQ, type JsonAssertionResult as aR, type JsonTestResult as aS, type JsonTestResults as aT, type TestState as aa, TestSuite as ab, type TestSuiteState as ac, type TestSequencerConstructor as ad, type BrowserBuiltinProvider as ae, type BrowserCommand as af, type BrowserCommandContext as ag, type BrowserInstanceOption as ah, type BrowserOrchestrator as ai, type BrowserProvider as aj, type BrowserProviderInitializationOptions as ak, type BrowserProviderModule as al, type BrowserProviderOptions as am, type BrowserServerState as an, type BrowserServerStateSession as ao, type CDPSession as ap, type ParentProjectBrowser as aq, type ProjectBrowser as ar, type ResolvedBrowserOptions as as, type ResolvedProjectConfig as at, type ResolveSnapshotPathHandler as au, type ResolveSnapshotPathHandlerContext as av, type TestRunResult as aw, type ReportedHookContext as ax, type TestRunEndReason as ay, BasicReporter as az, type TestProjectConfiguration as b, type CoverageV8Options as c, type UserProjectConfigFn as d, type UserProjectConfigExport as e, type TestProjectInlineConfiguration as f, type CoverageProvider as g, type CoverageProviderModule as h, type CoverageReporter as i, type CoverageProviderName as j, type CoverageOptions as k, type CoverageIstanbulOptions as l, type CustomProviderOptions as m, type Reporter as n, type BrowserScript as o, type BrowserConfigOptions as p, type BuiltinEnvironment as q, type VitestEnvironment as r, type PoolOptions as s, type CSSModuleScopeStrategy as t, type VitestRunMode as u, type TransformModePatterns as v, type TypecheckConfig as w, type UserConfig as x, type ResolvedConfig as y, type ProjectConfig as z };
@@ -0,0 +1,92 @@
1
+ import { getSafeTimers } from '@vitest/utils';
2
+ import { c as createBirpc } from './index.68735LiX.js';
3
+ import { g as getWorkerState } from './utils.CtocqOoE.js';
4
+
5
+ const { get } = Reflect;
6
+ function withSafeTimers(fn) {
7
+ const { setTimeout, clearTimeout, nextTick, setImmediate, clearImmediate } = getSafeTimers();
8
+ const currentSetTimeout = globalThis.setTimeout;
9
+ const currentClearTimeout = globalThis.clearTimeout;
10
+ const currentSetImmediate = globalThis.setImmediate;
11
+ const currentClearImmediate = globalThis.clearImmediate;
12
+ const currentNextTick = globalThis.process?.nextTick;
13
+ try {
14
+ globalThis.setTimeout = setTimeout;
15
+ globalThis.clearTimeout = clearTimeout;
16
+ globalThis.setImmediate = setImmediate;
17
+ globalThis.clearImmediate = clearImmediate;
18
+ if (globalThis.process) {
19
+ globalThis.process.nextTick = nextTick;
20
+ }
21
+ const result = fn();
22
+ return result;
23
+ } finally {
24
+ globalThis.setTimeout = currentSetTimeout;
25
+ globalThis.clearTimeout = currentClearTimeout;
26
+ globalThis.setImmediate = currentSetImmediate;
27
+ globalThis.clearImmediate = currentClearImmediate;
28
+ if (globalThis.process) {
29
+ nextTick(() => {
30
+ globalThis.process.nextTick = currentNextTick;
31
+ });
32
+ }
33
+ }
34
+ }
35
+ const promises = new Set();
36
+ async function rpcDone() {
37
+ if (!promises.size) {
38
+ return;
39
+ }
40
+ const awaitable = Array.from(promises);
41
+ return Promise.all(awaitable);
42
+ }
43
+ function createRuntimeRpc(options) {
44
+ let setCancel = (_reason) => {};
45
+ const onCancel = new Promise((resolve) => {
46
+ setCancel = resolve;
47
+ });
48
+ const rpc = createSafeRpc(createBirpc({ onCancel: setCancel }, {
49
+ eventNames: [
50
+ "onUserConsoleLog",
51
+ "onCollected",
52
+ "onCancel"
53
+ ],
54
+ onTimeoutError(functionName, args) {
55
+ let message = `[vitest-worker]: Timeout calling "${functionName}"`;
56
+ if (functionName === "fetch" || functionName === "transform" || functionName === "resolveId") {
57
+ message += ` with "${JSON.stringify(args)}"`;
58
+ }
59
+ if (functionName === "onUnhandledError") {
60
+ message += ` with "${args[0]?.message || args[0]}"`;
61
+ }
62
+ throw new Error(message);
63
+ },
64
+ ...options
65
+ }));
66
+ return {
67
+ rpc,
68
+ onCancel
69
+ };
70
+ }
71
+ function createSafeRpc(rpc) {
72
+ return new Proxy(rpc, { get(target, p, handler) {
73
+ const sendCall = get(target, p, handler);
74
+ const safeSendCall = (...args) => withSafeTimers(async () => {
75
+ const result = sendCall(...args);
76
+ promises.add(result);
77
+ try {
78
+ return await result;
79
+ } finally {
80
+ promises.delete(result);
81
+ }
82
+ });
83
+ safeSendCall.asEvent = sendCall.asEvent;
84
+ return safeSendCall;
85
+ } });
86
+ }
87
+ function rpc() {
88
+ const { rpc } = getWorkerState();
89
+ return rpc;
90
+ }
91
+
92
+ export { rpcDone as a, createRuntimeRpc as c, rpc as r };
@@ -0,0 +1,47 @@
1
+ import { g as getWorkerState } from './utils.CtocqOoE.js';
2
+
3
+ const filesCount = new Map();
4
+ const cache = new Map();
5
+ /**
6
+ * This utils allows computational intensive tasks to only be ran once
7
+ * across test reruns to improve the watch mode performance.
8
+ *
9
+ * Currently only works with `poolOptions.<pool>.isolate: false`
10
+ *
11
+ * @experimental
12
+ */
13
+ function runOnce(fn, key) {
14
+ const filepath = getWorkerState().filepath || "__unknown_files__";
15
+ if (!key) {
16
+ filesCount.set(filepath, (filesCount.get(filepath) || 0) + 1);
17
+ key = String(filesCount.get(filepath));
18
+ }
19
+ const id = `${filepath}:${key}`;
20
+ if (!cache.has(id)) {
21
+ cache.set(id, fn());
22
+ }
23
+ return cache.get(id);
24
+ }
25
+ /**
26
+ * Get a boolean indicates whether the task is running in the first time.
27
+ * Could only be `false` in watch mode.
28
+ *
29
+ * Currently only works with `isolate: false`
30
+ *
31
+ * @experimental
32
+ */
33
+ function isFirstRun() {
34
+ let firstRun = false;
35
+ runOnce(() => {
36
+ firstRun = true;
37
+ }, "__vitest_first_run__");
38
+ return firstRun;
39
+ }
40
+ /**
41
+ * @internal
42
+ */
43
+ function resetRunOnceCounter() {
44
+ filesCount.clear();
45
+ }
46
+
47
+ export { runOnce as a, isFirstRun as i, resetRunOnceCounter as r };
@@ -0,0 +1,134 @@
1
+ import { performance } from 'node:perf_hooks';
2
+ import { startTests, collectTests } from '@vitest/runner';
3
+ import { a as resolveSnapshotEnvironment, s as setupChaiConfig, r as resolveTestRunner } from './index.VfYQ6MXY.js';
4
+ import { c as setupCommonEnv, s as startCoverageInsideWorker, a as stopCoverageInsideWorker } from './setup-common.DEGDGBiA.js';
5
+ import { a as globalExpect, v as vi } from './vi.B-PuvDzu.js';
6
+ import { c as closeInspector } from './inspector.DbDkSkFn.js';
7
+ import { createRequire } from 'node:module';
8
+ import timers from 'node:timers';
9
+ import timersPromises from 'node:timers/promises';
10
+ import util from 'node:util';
11
+ import { getSafeTimers } from '@vitest/utils';
12
+ import { KNOWN_ASSET_TYPES } from 'vite-node/constants';
13
+ import { installSourcemapsSupport } from 'vite-node/source-map';
14
+ import { V as VitestIndex } from './index.BDobFbcz.js';
15
+ import { g as getWorkerState, r as resetModules } from './utils.CtocqOoE.js';
16
+ import 'chai';
17
+ import 'node:path';
18
+ import '../path.js';
19
+ import 'node:url';
20
+ import './rpc.DGgL5dw7.js';
21
+ import './index.68735LiX.js';
22
+ import './coverage.0iPg4Wrz.js';
23
+ import '@vitest/snapshot';
24
+ import './run-once.I7PpBOk1.js';
25
+ import '@vitest/expect';
26
+ import '@vitest/runner/utils';
27
+ import './_commonjsHelpers.BFTU3MAI.js';
28
+ import '@vitest/utils/error';
29
+ import '@vitest/spy';
30
+ import '@vitest/utils/source-map';
31
+ import './date.CDOsz-HY.js';
32
+ import './benchmark.BKUatJGy.js';
33
+ import 'expect-type';
34
+
35
+ let globalSetup = false;
36
+ async function setupGlobalEnv(config, { environment }, executor) {
37
+ await setupCommonEnv(config);
38
+ Object.defineProperty(globalThis, "__vitest_index__", {
39
+ value: VitestIndex,
40
+ enumerable: false
41
+ });
42
+ const state = getWorkerState();
43
+ if (!state.config.snapshotOptions.snapshotEnvironment) {
44
+ state.config.snapshotOptions.snapshotEnvironment = await resolveSnapshotEnvironment(config, executor);
45
+ }
46
+ if (globalSetup) {
47
+ return;
48
+ }
49
+ globalSetup = true;
50
+ if (environment.transformMode === "web") {
51
+ const _require = createRequire(import.meta.url);
52
+ _require.extensions[".css"] = resolveCss;
53
+ _require.extensions[".scss"] = resolveCss;
54
+ _require.extensions[".sass"] = resolveCss;
55
+ _require.extensions[".less"] = resolveCss;
56
+ KNOWN_ASSET_TYPES.forEach((type) => {
57
+ _require.extensions[`.${type}`] = resolveAsset;
58
+ });
59
+ process.env.SSR = "";
60
+ } else {
61
+ process.env.SSR = "1";
62
+ }
63
+ globalThis.__vitest_required__ = {
64
+ util,
65
+ timers,
66
+ timersPromises
67
+ };
68
+ installSourcemapsSupport({ getSourceMap: (source) => state.moduleCache.getSourceMap(source) });
69
+ if (!config.disableConsoleIntercept) {
70
+ await setupConsoleLogSpy();
71
+ }
72
+ }
73
+ function resolveCss(mod) {
74
+ mod.exports = "";
75
+ }
76
+ function resolveAsset(mod, url) {
77
+ mod.exports = url;
78
+ }
79
+ async function setupConsoleLogSpy() {
80
+ const { createCustomConsole } = await import('./console.D6t261w0.js');
81
+ globalThis.console = createCustomConsole();
82
+ }
83
+ async function withEnv({ environment }, options, fn) {
84
+ globalThis.__vitest_environment__ = environment.name;
85
+ globalExpect.setState({ environment: environment.name });
86
+ const env = await environment.setup(globalThis, options);
87
+ try {
88
+ await fn();
89
+ } finally {
90
+ const { setTimeout } = getSafeTimers();
91
+ await new Promise((resolve) => setTimeout(resolve));
92
+ await env.teardown(globalThis);
93
+ }
94
+ }
95
+
96
+ async function run(method, files, config, environment, executor) {
97
+ const workerState = getWorkerState();
98
+ const isIsolatedThreads = config.pool === "threads" && (config.poolOptions?.threads?.isolate ?? true);
99
+ const isIsolatedForks = config.pool === "forks" && (config.poolOptions?.forks?.isolate ?? true);
100
+ const isolate = isIsolatedThreads || isIsolatedForks;
101
+ await setupGlobalEnv(config, environment, executor);
102
+ await startCoverageInsideWorker(config.coverage, executor, { isolate });
103
+ if (config.chaiConfig) {
104
+ setupChaiConfig(config.chaiConfig);
105
+ }
106
+ const runner = await resolveTestRunner(config, executor);
107
+ workerState.onCancel.then((reason) => {
108
+ closeInspector(config);
109
+ runner.onCancel?.(reason);
110
+ });
111
+ workerState.durations.prepare = performance.now() - workerState.durations.prepare;
112
+ workerState.durations.environment = performance.now();
113
+ await withEnv(environment, environment.options || config.environmentOptions || {}, async () => {
114
+ workerState.durations.environment = performance.now() - workerState.durations.environment;
115
+ for (const file of files) {
116
+ if (isolate) {
117
+ executor.mocker.reset();
118
+ resetModules(workerState.moduleCache, true);
119
+ }
120
+ workerState.filepath = file.filepath;
121
+ if (method === "run") {
122
+ await startTests([file], runner);
123
+ } else {
124
+ await collectTests([file], runner);
125
+ }
126
+ vi.resetConfig();
127
+ vi.restoreAllMocks();
128
+ }
129
+ await stopCoverageInsideWorker(config.coverage, executor, { isolate });
130
+ });
131
+ workerState.environmentTeardownRun = true;
132
+ }
133
+
134
+ export { run };
@@ -0,0 +1,88 @@
1
+ import { r as resolveCoverageProviderModule } from './coverage.0iPg4Wrz.js';
2
+ import { addSerializer } from '@vitest/snapshot';
3
+ import { setSafeTimers } from '@vitest/utils';
4
+ import { r as resetRunOnceCounter } from './run-once.I7PpBOk1.js';
5
+
6
+ async function startCoverageInsideWorker(options, loader, runtimeOptions) {
7
+ const coverageModule = await resolveCoverageProviderModule(options, loader);
8
+ if (coverageModule) {
9
+ return coverageModule.startCoverage?.(runtimeOptions);
10
+ }
11
+ return null;
12
+ }
13
+ async function takeCoverageInsideWorker(options, loader) {
14
+ const coverageModule = await resolveCoverageProviderModule(options, loader);
15
+ if (coverageModule) {
16
+ return coverageModule.takeCoverage?.({ moduleExecutionInfo: loader.moduleExecutionInfo });
17
+ }
18
+ return null;
19
+ }
20
+ async function stopCoverageInsideWorker(options, loader, runtimeOptions) {
21
+ const coverageModule = await resolveCoverageProviderModule(options, loader);
22
+ if (coverageModule) {
23
+ return coverageModule.stopCoverage?.(runtimeOptions);
24
+ }
25
+ return null;
26
+ }
27
+
28
+ let globalSetup = false;
29
+ async function setupCommonEnv(config) {
30
+ resetRunOnceCounter();
31
+ setupDefines(config.defines);
32
+ setupEnv(config.env);
33
+ if (globalSetup) {
34
+ return;
35
+ }
36
+ globalSetup = true;
37
+ setSafeTimers();
38
+ if (config.globals) {
39
+ (await import('./globals.DCbUWjip.js')).registerApiGlobally();
40
+ }
41
+ }
42
+ function setupDefines(defines) {
43
+ for (const key in defines) {
44
+ globalThis[key] = defines[key];
45
+ }
46
+ }
47
+ function setupEnv(env) {
48
+ if (typeof process === "undefined") {
49
+ return;
50
+ }
51
+ const { PROD, DEV,...restEnvs } = env;
52
+ process.env.PROD = PROD ? "1" : "";
53
+ process.env.DEV = DEV ? "1" : "";
54
+ for (const key in restEnvs) {
55
+ process.env[key] = env[key];
56
+ }
57
+ }
58
+ async function loadDiffConfig(config, executor) {
59
+ if (typeof config.diff === "object") {
60
+ return config.diff;
61
+ }
62
+ if (typeof config.diff !== "string") {
63
+ return;
64
+ }
65
+ const diffModule = await executor.executeId(config.diff);
66
+ if (diffModule && typeof diffModule.default === "object" && diffModule.default != null) {
67
+ return diffModule.default;
68
+ } else {
69
+ throw new Error(`invalid diff config file ${config.diff}. Must have a default export with config object`);
70
+ }
71
+ }
72
+ async function loadSnapshotSerializers(config, executor) {
73
+ const files = config.snapshotSerializers;
74
+ const snapshotSerializers = await Promise.all(files.map(async (file) => {
75
+ const mo = await executor.executeId(file);
76
+ if (!mo || typeof mo.default !== "object" || mo.default === null) {
77
+ throw new Error(`invalid snapshot serializer file ${file}. Must export a default object`);
78
+ }
79
+ const config = mo.default;
80
+ if (typeof config.test !== "function" || typeof config.serialize !== "function" && typeof config.print !== "function") {
81
+ throw new TypeError(`invalid snapshot serializer in ${file}. Must have a 'test' method along with either a 'serialize' or 'print' method.`);
82
+ }
83
+ return config;
84
+ }));
85
+ snapshotSerializers.forEach((serializer) => addSerializer(serializer));
86
+ }
87
+
88
+ export { stopCoverageInsideWorker as a, loadSnapshotSerializers as b, setupCommonEnv as c, loadDiffConfig as l, startCoverageInsideWorker as s, takeCoverageInsideWorker as t };