vitest 4.0.16 → 4.1.0-beta.1

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 (60) hide show
  1. package/dist/browser.d.ts +2 -1
  2. package/dist/browser.js +2 -1
  3. package/dist/chunks/{base.Bin-9uYm.js → base.CBRNZa3k.js} +8 -7
  4. package/dist/chunks/{browser.d.Bz3lxTX-.d.ts → browser.d.8hOapKZr.d.ts} +5 -1
  5. package/dist/chunks/{cac.BGonGPac.js → cac.B1v3xxoC.js} +26 -8
  6. package/dist/chunks/{cli-api.BKg19Fvw.js → cli-api.B4CqEpI6.js} +225 -110
  7. package/dist/chunks/{config.d.CzIjkicf.d.ts → config.d.idH22YSr.d.ts} +13 -11
  8. package/dist/chunks/{console.Cf-YriPC.js → console.uGgdMhyZ.js} +2 -1
  9. package/dist/chunks/{coverage.BuJUwVtg.js → coverage.BMlOMIWl.js} +18 -4
  10. package/dist/chunks/{creator.DAmOKTvJ.js → creator.C7WwjkuR.js} +32 -1
  11. package/dist/chunks/{globals.DOayXfHP.js → globals.DjuGMoMc.js} +10 -9
  12. package/dist/chunks/{index.Z5E_ObnR.js → index.BEFi2-_3.js} +3 -1
  13. package/dist/chunks/{index.6Qv1eEA6.js → index.BiOAd_ki.js} +16 -4
  14. package/dist/chunks/{index.BspFP3mn.js → index.CyBMJtT7.js} +1 -1
  15. package/dist/chunks/{index.456_DGfR.js → index.Dm4xqZ0s.js} +28 -4
  16. package/dist/chunks/{index.Drsj_6e7.js → index.DyBZXrH3.js} +1 -1
  17. package/dist/chunks/{init-forks.v9UONQS6.js → init-forks.CHeQ9Moq.js} +1 -1
  18. package/dist/chunks/{init-threads.DqYg3Trk.js → init-threads.uZiNAuPk.js} +1 -1
  19. package/dist/chunks/{init.KmQZdqFg.js → init.DVtKdFty.js} +24 -11
  20. package/dist/chunks/{plugin.d.v1sC_bv1.d.ts → plugin.d.D8KU2PY_.d.ts} +1 -1
  21. package/dist/chunks/{reporters.d.Rsi0PyxX.d.ts → reporters.d.Db3MiIWX.d.ts} +51 -22
  22. package/dist/chunks/rpc.HLmECnw_.js +148 -0
  23. package/dist/chunks/{setup-common.Cm-kSBVi.js → setup-common.BcqLPsn5.js} +1 -1
  24. package/dist/chunks/{startModuleRunner.DpqpB8k3.js → startModuleRunner.C5CcWyXW.js} +23 -23
  25. package/dist/chunks/{vi.2VT5v0um.js → test.prxIahgM.js} +500 -119
  26. package/dist/chunks/{traces.U4xDYhzZ.js → traces.CCmnQaNT.js} +46 -1
  27. package/dist/chunks/{vm.qFl6P1nF.js → vm.CrifS09m.js} +5 -8
  28. package/dist/chunks/{worker.d.5JNaocaN.d.ts → worker.d.Bji1eq5g.d.ts} +2 -1
  29. package/dist/cli.js +2 -2
  30. package/dist/config.d.ts +9 -9
  31. package/dist/coverage.d.ts +8 -8
  32. package/dist/coverage.js +3 -1
  33. package/dist/environments.js +3 -1
  34. package/dist/index.d.ts +22 -10
  35. package/dist/index.js +8 -7
  36. package/dist/module-evaluator.js +2 -6
  37. package/dist/node.d.ts +14 -11
  38. package/dist/node.js +20 -20
  39. package/dist/reporters.d.ts +7 -7
  40. package/dist/reporters.js +4 -2
  41. package/dist/runners.d.ts +23 -4
  42. package/dist/runners.js +4 -4
  43. package/dist/runtime.d.ts +6 -0
  44. package/dist/runtime.js +36 -0
  45. package/dist/snapshot.js +2 -0
  46. package/dist/suite.js +2 -0
  47. package/dist/worker.d.ts +4 -3
  48. package/dist/worker.js +10 -12
  49. package/dist/workers/forks.js +11 -13
  50. package/dist/workers/runVmTests.js +10 -12
  51. package/dist/workers/threads.js +11 -13
  52. package/dist/workers/vmForks.js +8 -9
  53. package/dist/workers/vmThreads.js +8 -9
  54. package/package.json +23 -27
  55. package/dist/chunks/date.Bq6ZW5rf.js +0 -73
  56. package/dist/chunks/rpc.BoxB0q7B.js +0 -76
  57. package/dist/chunks/test.B8ej_ZHS.js +0 -254
  58. package/dist/mocker.d.ts +0 -1
  59. package/dist/mocker.js +0 -1
  60. package/dist/module-runner.js +0 -17
@@ -1,21 +1,21 @@
1
- import { TaskMeta, Suite, File, TestAnnotation, TestArtifact, ImportDuration, Test, Task, TaskResultPack, FileSpecification, CancelReason, SequenceSetupFiles, SequenceHooks } from '@vitest/runner';
1
+ import { TaskMeta, Suite, File, SerializableRetry, TestAnnotation, TestArtifact, ImportDuration, Test, Task, TaskResultPack, FileSpecification, CancelReason, SequenceSetupFiles, SequenceHooks } from '@vitest/runner';
2
2
  import { TestError, SerializedError, Arrayable, ParsedStack, Awaitable } from '@vitest/utils';
3
3
  import { A as AfterSuiteRunMeta, U as UserConsoleLog, P as ProvidedContext, L as LabelColor } from './rpc.d.RH3apGEf.js';
4
4
  import { Writable } from 'node:stream';
5
5
  import { DevEnvironment, TransformResult as TransformResult$1, ViteDevServer, Plugin, UserConfig as UserConfig$1, DepOptimizationConfig, ServerOptions, ConfigEnv, AliasOptions } from 'vite';
6
- import { S as SerializedTestSpecification, c as SourceModuleDiagnostic, B as BrowserTesterOptions } from './browser.d.Bz3lxTX-.js';
7
- import { MockedModule } from '@vitest/mocker';
8
- import { StackTraceParserOptions } from '@vitest/utils/source-map';
9
- import { BrowserCommands } from 'vitest/browser';
10
- import { B as BrowserTraceViewMode, S as SerializedConfig, F as FakeTimerInstallOpts } from './config.d.CzIjkicf.js';
6
+ import { S as SerializedTestSpecification, c as SourceModuleDiagnostic, B as BrowserTesterOptions } from './browser.d.8hOapKZr.js';
7
+ import { B as BrowserTraceViewMode, S as SerializedConfig, F as FakeTimerInstallOpts } from './config.d.idH22YSr.js';
11
8
  import { PrettyFormatOptions } from '@vitest/pretty-format';
12
9
  import { SnapshotSummary, SnapshotStateOptions } from '@vitest/snapshot';
13
10
  import { SerializedDiffOptions } from '@vitest/utils/diff';
14
11
  import { chai } from '@vitest/expect';
15
12
  import { happyDomTypes, jsdomTypes } from 'vitest/optional-types.js';
16
- import { c as ContextTestEnvironment, d as WorkerExecuteContext, e as WorkerTestEnvironment } from './worker.d.5JNaocaN.js';
13
+ import { c as ContextTestEnvironment, d as WorkerExecuteContext, e as WorkerTestEnvironment } from './worker.d.Bji1eq5g.js';
17
14
  import { O as OTELCarrier } from './traces.d.402V_yFI.js';
18
15
  import { B as BenchmarkResult } from './benchmark.d.DAaHLpsq.js';
16
+ import { MockedModule } from '@vitest/mocker';
17
+ import { StackTraceParserOptions } from '@vitest/utils/source-map';
18
+ import { BrowserCommands } from 'vitest/browser';
19
19
  import { a as RuntimeCoverageProviderModule } from './coverage.d.BZtK59WP.js';
20
20
  import { SnapshotManager } from '@vitest/snapshot/manager';
21
21
  import { Console } from 'node:console';
@@ -278,7 +278,7 @@ interface TaskOptions {
278
278
  readonly fails: boolean | undefined;
279
279
  readonly concurrent: boolean | undefined;
280
280
  readonly shuffle: boolean | undefined;
281
- readonly retry: number | undefined;
281
+ readonly retry: SerializableRetry | undefined;
282
282
  readonly repeats: number | undefined;
283
283
  readonly mode: "run" | "only" | "skip" | "todo";
284
284
  }
@@ -402,9 +402,14 @@ declare function experimental_getRunnerTask(entity: TestSuite): Suite;
402
402
  declare function experimental_getRunnerTask(entity: TestModule): File;
403
403
  declare function experimental_getRunnerTask(entity: TestCase | TestSuite | TestModule): Suite | File | Test;
404
404
 
405
+ interface TestSpecificationOptions {
406
+ testNamePattern?: RegExp;
407
+ testIds?: string[];
408
+ testLines?: number[];
409
+ }
405
410
  declare class TestSpecification {
406
411
  /**
407
- * The task ID associated with the test module.
412
+ * The task id associated with the test module.
408
413
  */
409
414
  readonly taskId: string;
410
415
  /**
@@ -412,21 +417,28 @@ declare class TestSpecification {
412
417
  */
413
418
  readonly project: TestProject;
414
419
  /**
415
- * The ID of the module in the Vite module graph. It is usually an absolute file path.
420
+ * The id of the module in the Vite module graph. It is usually an absolute file path.
416
421
  */
417
422
  readonly moduleId: string;
418
423
  /**
419
- * The current test pool. It's possible to have multiple pools in a single test project with `poolMatchGlob` and `typecheck.enabled`.
420
- * @experimental In Vitest 4, the project will only support a single pool and this property will be removed.
424
+ * The current test pool. It's possible to have multiple pools in a single test project with `typecheck.enabled`.
425
+ * @experimental In later versions, the project will only support a single pool.
421
426
  */
422
427
  readonly pool: Pool;
423
428
  /**
424
429
  * Line numbers of the test locations to run.
425
430
  */
426
431
  readonly testLines: number[] | undefined;
427
- constructor(project: TestProject, moduleId: string, pool: Pool, testLines?: number[] | undefined);
428
432
  /**
429
- * Test module associated with the specification.
433
+ * Regular expression pattern to filter test names.
434
+ */
435
+ readonly testNamePattern: RegExp | undefined;
436
+ /**
437
+ * The ids of tasks inside of this specification to run.
438
+ */
439
+ readonly testIds: string[] | undefined;
440
+ /**
441
+ * Test module associated with the specification. This will be `undefined` if tests have not been run yet.
430
442
  */
431
443
  get testModule(): TestModule | undefined;
432
444
  toJSON(): SerializedTestSpecification;
@@ -1278,6 +1290,12 @@ declare class Vitest {
1278
1290
  */
1279
1291
  runTestSpecifications(specifications: TestSpecification[], allTestsRun?: boolean): Promise<TestRunResult>;
1280
1292
  /**
1293
+ * Runs tests for the given file paths. This does not trigger `onWatcher*` events.
1294
+ * @param filepaths A list of file paths to run tests for.
1295
+ * @param allTestsRun Indicates whether all tests were run. This only matters for coverage.
1296
+ */
1297
+ runTestFiles(filepaths: string[], allTestsRun?: boolean): Promise<TestRunResult>;
1298
+ /**
1281
1299
  * Rerun files and trigger `onWatcherRerun`, `onWatcherStart` and `onTestsRerun` events.
1282
1300
  * @param specifications A list of specifications to run.
1283
1301
  * @param allTestsRun Indicates whether all tests were run. This only matters for coverage.
@@ -1825,7 +1843,7 @@ declare class TestProject {
1825
1843
  * Creates a new test specification. Specifications describe how to run tests.
1826
1844
  * @param moduleId The file path
1827
1845
  */
1828
- createSpecification(moduleId: string, locations?: number[] | undefined, pool?: string): TestSpecification;
1846
+ createSpecification(moduleId: string, locationsOrOptions?: number[] | TestSpecificationOptions | undefined, pool?: string): TestSpecification;
1829
1847
  toJSON(): SerializedTestProject;
1830
1848
  /**
1831
1849
  * Vite's dev server instance. Every workspace project has its own server.
@@ -1924,8 +1942,8 @@ interface PoolWorker {
1924
1942
  stop: () => Promise<void>;
1925
1943
  /**
1926
1944
  * This is called on workers that already satisfy certain constraints:
1945
+ * - The task has the same worker name
1927
1946
  * - The task has the same project
1928
- * - The task has the same environment
1929
1947
  */
1930
1948
  canReuse?: (task: PoolTask) => boolean;
1931
1949
  }
@@ -1944,7 +1962,6 @@ interface PoolTask {
1944
1962
  */
1945
1963
  execArgv: string[];
1946
1964
  context: WorkerExecuteContext;
1947
- environment: ContextTestEnvironment;
1948
1965
  memoryLimit: number | null;
1949
1966
  }
1950
1967
  type WorkerRequest = {
@@ -2167,6 +2184,10 @@ interface JUnitOptions {
2167
2184
  * @default false
2168
2185
  */
2169
2186
  addFileAttribute?: boolean;
2187
+ /**
2188
+ * Hostname to use in the report. By default, it uses os.hostname()
2189
+ */
2190
+ hostname?: string;
2170
2191
  }
2171
2192
  declare class JUnitReporter implements Reporter {
2172
2193
  private ctx;
@@ -2977,11 +2998,17 @@ interface InlineConfig {
2977
2998
  */
2978
2999
  bail?: number;
2979
3000
  /**
2980
- * Retry the test specific number of times if it fails.
3001
+ * Retry configuration for tests.
3002
+ * - If a number, specifies how many times to retry failed tests
3003
+ * - If an object, allows fine-grained retry control
2981
3004
  *
2982
- * @default 0
3005
+ * ⚠️ WARNING: Function form is NOT supported in a config file
3006
+ * because configurations are serialized when passed to worker threads.
3007
+ * Use the function form only in test files directly.
3008
+ *
3009
+ * @default 0 // Don't retry
2983
3010
  */
2984
- retry?: number;
3011
+ retry?: SerializableRetry;
2985
3012
  /**
2986
3013
  * Show full diff when snapshot fails instead of a patch.
2987
3014
  */
@@ -3035,6 +3062,7 @@ interface InlineConfig {
3035
3062
  openTelemetry?: {
3036
3063
  enabled: boolean;
3037
3064
  sdkPath?: string;
3065
+ browserSdkPath?: string;
3038
3066
  };
3039
3067
  /**
3040
3068
  * Show imports (top 10) that take a long time.
@@ -3187,6 +3215,7 @@ interface ResolvedConfig extends Omit<Required<UserConfig>, "project" | "config"
3187
3215
  poolRunner?: PoolRunnerInitializer;
3188
3216
  reporters: (InlineReporter | ReporterWithOptions)[];
3189
3217
  defines: Record<string, any>;
3218
+ viteDefine: Record<string, any>;
3190
3219
  api: ApiConfig & {
3191
3220
  token: string;
3192
3221
  };
@@ -3266,5 +3295,5 @@ type TestProjectInlineConfiguration = (UserWorkspaceConfig & {
3266
3295
  });
3267
3296
  type TestProjectConfiguration = string | TestProjectInlineConfiguration | Promise<UserWorkspaceConfig> | UserProjectConfigFn;
3268
3297
 
3269
- export { CoverageMap as C, TestSuite as K, Logger as L, experimental_getRunnerTask as Q, TestProject as T, Vitest as V, BenchmarkReporter as aE, BenchmarkReportsMap as aF, DefaultReporter as aG, DotReporter as aH, GithubActionsReporter as aI, HangingProcessReporter as aJ, JsonReporter as aK, JUnitReporter as aL, ReportersMap as aM, TapFlatReporter as aN, TapReporter as aO, VerboseBenchmarkReporter as aP, VerboseReporter as aQ, BaseReporter as aR, TestSpecification as k, VitestPackageInstaller as p, TestCase as v, TestCollection as w, TestModule as y };
3270
- export type { BrowserCommand as $, ApiConfig as A, TestResult as B, TestResultFailed as D, TestResultPassed as E, TestResultSkipped as F, TestState as G, HTMLOptions as H, InlineConfig as I, JsonOptions as J, ModuleDiagnostic as M, TestSuiteState as N, OnServerRestartHandler as O, PoolWorker as P, ResolvedCoverageOptions as R, SerializedTestProject as S, UserWorkspaceConfig as U, WatcherTriggerPattern as W, TestSequencerConstructor as X, BenchmarkUserOptions as Y, BrowserBuiltinProvider as Z, _BrowserNames as _, ReportContext as a, BrowserCommandContext as a0, BrowserConfigOptions as a1, BrowserInstanceOption as a2, BrowserModuleMocker as a3, BrowserOrchestrator as a4, BrowserProvider as a5, BrowserProviderOption as a6, BrowserScript as a7, BrowserServerFactory as a8, BrowserServerOptions as a9, TestRunResult as aA, ReportedHookContext as aB, Reporter as aC, TestRunEndReason as aD, BenchmarkBuiltinReporters as aS, BuiltinReporterOptions as aT, BuiltinReporters as aU, JsonAssertionResult as aV, JsonTestResult as aW, JsonTestResults as aX, BrowserServerState as aa, BrowserServerStateSession as ab, CDPSession as ac, ParentProjectBrowser as ad, ProjectBrowser as ae, ResolvedBrowserOptions as af, ToMatchScreenshotComparators as ag, ToMatchScreenshotOptions as ah, BuiltinEnvironment as ai, CSSModuleScopeStrategy as aj, DepsOptimizationOptions as ak, EnvironmentOptions as al, Pool as am, ProjectConfig as an, ResolvedProjectConfig as ao, ResolveSnapshotPathHandler as ap, ResolveSnapshotPathHandlerContext as aq, TypecheckConfig as ar, VitestEnvironment as as, BaseCoverageOptions as at, CoverageIstanbulOptions as au, CoverageOptions as av, CoverageProvider as aw, CoverageProviderModule as ax, CoverageReporter as ay, CustomProviderOptions as az, TestProjectConfiguration as b, CoverageV8Options as c, UserProjectConfigFn as d, UserProjectConfigExport as e, UserConfig as f, TestProjectInlineConfiguration as g, ResolvedConfig as h, VitestRunMode as i, VitestOptions as j, PoolOptions as l, WorkerRequest as m, TestSequencer as n, OnTestsRerunHandler as o, PoolRunnerInitializer as q, PoolTask as r, WorkerResponse as s, JUnitOptions as t, TaskOptions as u, TestDiagnostic as x, TestModuleState as z };
3298
+ export { BenchmarkReporter as B, DefaultReporter as D, GithubActionsReporter as G, HangingProcessReporter as H, JsonReporter as J, Logger as L, TestProject as T, Vitest as V, TestCase as a3, TestCollection as a4, TestModule as a6, CoverageMap as aY, TestSuite as ad, experimental_getRunnerTask as af, TestSpecification as i, VitestPackageInstaller as n, BenchmarkReportsMap as r, DotReporter as s, JUnitReporter as t, ReportersMap as u, TapFlatReporter as v, TapReporter as w, VerboseBenchmarkReporter as x, VerboseReporter as y, BaseReporter as z };
3299
+ export type { JsonOptions as $, ApiConfig as A, CoverageV8Options as C, BenchmarkBuiltinReporters as E, BuiltinReporterOptions as F, InlineConfig as I, BuiltinReporters as K, JsonAssertionResult as M, JsonTestResult as N, OnServerRestartHandler as O, PoolWorker as P, JsonTestResults as Q, ResolvedCoverageOptions as R, SerializedTestProject as S, UserWorkspaceConfig as U, WatcherTriggerPattern as W, ReportedHookContext as X, Reporter as Y, TestRunEndReason as Z, HTMLOptions as _, TestProjectConfiguration as a, JUnitOptions as a0, ModuleDiagnostic as a1, TaskOptions as a2, TestDiagnostic as a5, TestModuleState as a7, TestResult as a8, TestResultFailed as a9, ProjectBrowser as aA, ResolvedBrowserOptions as aB, ToMatchScreenshotComparators as aC, ToMatchScreenshotOptions as aD, BuiltinEnvironment as aE, CSSModuleScopeStrategy as aF, DepsOptimizationOptions as aG, EnvironmentOptions as aH, Pool as aI, ProjectConfig as aJ, ResolvedProjectConfig as aK, ResolveSnapshotPathHandler as aL, ResolveSnapshotPathHandlerContext as aM, TypecheckConfig as aN, VitestEnvironment as aO, BaseCoverageOptions as aP, CoverageIstanbulOptions as aQ, CoverageOptions as aR, CoverageProvider as aS, CoverageProviderModule as aT, CoverageReporter as aU, CustomProviderOptions as aV, ReportContext as aW, TestRunResult as aX, TestResultPassed as aa, TestResultSkipped as ab, TestState as ac, TestSuiteState as ae, TestSequencerConstructor as ag, TestSpecificationOptions as ah, BenchmarkUserOptions as ai, _BrowserNames as aj, BrowserBuiltinProvider as ak, BrowserCommand as al, BrowserCommandContext as am, BrowserConfigOptions as an, BrowserInstanceOption as ao, BrowserModuleMocker as ap, BrowserOrchestrator as aq, BrowserProvider as ar, BrowserProviderOption as as, BrowserScript as at, BrowserServerFactory as au, BrowserServerOptions as av, BrowserServerState as aw, BrowserServerStateSession as ax, CDPSession as ay, ParentProjectBrowser as az, UserProjectConfigFn as b, UserProjectConfigExport as c, UserConfig as d, TestProjectInlineConfiguration as e, ResolvedConfig as f, VitestRunMode as g, VitestOptions as h, PoolOptions as j, WorkerRequest as k, TestSequencer as l, OnTestsRerunHandler as m, PoolRunnerInitializer as o, PoolTask as p, WorkerResponse as q };
@@ -0,0 +1,148 @@
1
+ import { getSafeTimers } from '@vitest/utils/timers';
2
+ import { c as createBirpc } from './index.Chj8NDwU.js';
3
+ import { g as getWorkerState } from './utils.DvEY5TfP.js';
4
+
5
+ /* Ported from https://github.com/boblauer/MockDate/blob/master/src/mockdate.ts */
6
+ /*
7
+ The MIT License (MIT)
8
+
9
+ Copyright (c) 2014 Bob Lauer
10
+
11
+ Permission is hereby granted, free of charge, to any person obtaining a copy
12
+ of this software and associated documentation files (the "Software"), to deal
13
+ in the Software without restriction, including without limitation the rights
14
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15
+ copies of the Software, and to permit persons to whom the Software is
16
+ furnished to do so, subject to the following conditions:
17
+
18
+ The above copyright notice and this permission notice shall be included in all
19
+ copies or substantial portions of the Software.
20
+
21
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27
+ SOFTWARE.
28
+ */
29
+ const RealDate = Date;
30
+ let now = null;
31
+ class MockDate extends RealDate {
32
+ constructor(y, m, d, h, M, s, ms) {
33
+ super();
34
+ let date;
35
+ switch (arguments.length) {
36
+ case 0:
37
+ if (now !== null) date = new RealDate(now.valueOf());
38
+ else date = new RealDate();
39
+ break;
40
+ case 1:
41
+ date = new RealDate(y);
42
+ break;
43
+ default:
44
+ d = typeof d === "undefined" ? 1 : d;
45
+ h = h || 0;
46
+ M = M || 0;
47
+ s = s || 0;
48
+ ms = ms || 0;
49
+ date = new RealDate(y, m, d, h, M, s, ms);
50
+ break;
51
+ }
52
+ Object.setPrototypeOf(date, MockDate.prototype);
53
+ return date;
54
+ }
55
+ }
56
+ MockDate.UTC = RealDate.UTC;
57
+ MockDate.now = function() {
58
+ return new MockDate().valueOf();
59
+ };
60
+ MockDate.parse = function(dateString) {
61
+ return RealDate.parse(dateString);
62
+ };
63
+ MockDate.toString = function() {
64
+ return RealDate.toString();
65
+ };
66
+ function mockDate(date) {
67
+ const dateObj = new RealDate(date.valueOf());
68
+ if (Number.isNaN(dateObj.getTime())) throw new TypeError(`mockdate: The time set is an invalid date: ${date}`);
69
+ // @ts-expect-error global
70
+ globalThis.Date = MockDate;
71
+ now = dateObj.valueOf();
72
+ }
73
+ function resetDate() {
74
+ globalThis.Date = RealDate;
75
+ }
76
+
77
+ const { get } = Reflect;
78
+ function withSafeTimers(fn) {
79
+ const { setTimeout, clearTimeout, nextTick, setImmediate, clearImmediate } = getSafeTimers();
80
+ const currentSetTimeout = globalThis.setTimeout;
81
+ const currentClearTimeout = globalThis.clearTimeout;
82
+ const currentSetImmediate = globalThis.setImmediate;
83
+ const currentClearImmediate = globalThis.clearImmediate;
84
+ const currentNextTick = globalThis.process?.nextTick;
85
+ try {
86
+ globalThis.setTimeout = setTimeout;
87
+ globalThis.clearTimeout = clearTimeout;
88
+ if (setImmediate) globalThis.setImmediate = setImmediate;
89
+ if (clearImmediate) globalThis.clearImmediate = clearImmediate;
90
+ if (globalThis.process && nextTick) globalThis.process.nextTick = nextTick;
91
+ return fn();
92
+ } finally {
93
+ globalThis.setTimeout = currentSetTimeout;
94
+ globalThis.clearTimeout = currentClearTimeout;
95
+ globalThis.setImmediate = currentSetImmediate;
96
+ globalThis.clearImmediate = currentClearImmediate;
97
+ if (globalThis.process && nextTick) nextTick(() => {
98
+ globalThis.process.nextTick = currentNextTick;
99
+ });
100
+ }
101
+ }
102
+ const promises = /* @__PURE__ */ new Set();
103
+ async function rpcDone() {
104
+ if (!promises.size) return;
105
+ const awaitable = Array.from(promises);
106
+ return Promise.all(awaitable);
107
+ }
108
+ const onCancelCallbacks = [];
109
+ function onCancel(callback) {
110
+ onCancelCallbacks.push(callback);
111
+ }
112
+ function createRuntimeRpc(options) {
113
+ return createSafeRpc(createBirpc({ async onCancel(reason) {
114
+ await Promise.all(onCancelCallbacks.map((fn) => fn(reason)));
115
+ } }, {
116
+ eventNames: [
117
+ "onUserConsoleLog",
118
+ "onCollected",
119
+ "onCancel"
120
+ ],
121
+ timeout: -1,
122
+ ...options
123
+ }));
124
+ }
125
+ function createSafeRpc(rpc) {
126
+ return new Proxy(rpc, { get(target, p, handler) {
127
+ // keep $rejectPendingCalls as sync function
128
+ if (p === "$rejectPendingCalls") return rpc.$rejectPendingCalls;
129
+ const sendCall = get(target, p, handler);
130
+ const safeSendCall = (...args) => withSafeTimers(async () => {
131
+ const result = sendCall(...args);
132
+ promises.add(result);
133
+ try {
134
+ return await result;
135
+ } finally {
136
+ promises.delete(result);
137
+ }
138
+ });
139
+ safeSendCall.asEvent = sendCall.asEvent;
140
+ return safeSendCall;
141
+ } });
142
+ }
143
+ function rpc() {
144
+ const { rpc } = getWorkerState();
145
+ return rpc;
146
+ }
147
+
148
+ export { RealDate as R, rpcDone as a, resetDate as b, createRuntimeRpc as c, mockDate as m, onCancel as o, rpc as r };
@@ -26,7 +26,7 @@ async function setupCommonEnv(config) {
26
26
  if (globalSetup) return;
27
27
  globalSetup = true;
28
28
  setSafeTimers();
29
- if (config.globals) (await import('./globals.DOayXfHP.js')).registerApiGlobally();
29
+ if (config.globals) (await import('./globals.DjuGMoMc.js')).registerApiGlobally();
30
30
  }
31
31
  function setupDefines(config) {
32
32
  for (const key in config.defines) globalThis[key] = config.defines[key];
@@ -11,28 +11,7 @@ import vm from 'node:vm';
11
11
  import { MockerRegistry, mockObject, RedirectedModule, AutomockedModule } from '@vitest/mocker';
12
12
  import nodeModule from 'node:module';
13
13
  import * as viteModuleRunner from 'vite/module-runner';
14
- import { T as Traces } from './traces.U4xDYhzZ.js';
15
-
16
- class VitestTransport {
17
- constructor(options) {
18
- this.options = options;
19
- }
20
- async invoke(event) {
21
- if (event.type !== "custom") return { error: /* @__PURE__ */ new Error(`Vitest Module Runner doesn't support Vite HMR events.`) };
22
- if (event.event !== "vite:invoke") return { error: /* @__PURE__ */ new Error(`Vitest Module Runner doesn't support ${event.event} event.`) };
23
- const { name, data } = event.data;
24
- if (name === "getBuiltins")
25
- // we return an empty array here to avoid client-side builtin check,
26
- // as we need builtins to go through `fetchModule`
27
- return { result: [] };
28
- if (name !== "fetchModule") return { error: /* @__PURE__ */ new Error(`Unknown method: ${name}. Expected "fetchModule".`) };
29
- try {
30
- return { result: await this.options.fetchModule(...data) };
31
- } catch (error) {
32
- return { error };
33
- }
34
- }
35
- }
14
+ import { T as Traces } from './traces.CCmnQaNT.js';
36
15
 
37
16
  const _DRIVE_LETTER_START_RE = /^[A-Za-z]:\//;
38
17
  function normalizeWindowsPath(input = "") {
@@ -567,6 +546,27 @@ function fixLeadingSlashes(id) {
567
546
  return id;
568
547
  }
569
548
 
549
+ class VitestTransport {
550
+ constructor(options) {
551
+ this.options = options;
552
+ }
553
+ async invoke(event) {
554
+ if (event.type !== "custom") return { error: /* @__PURE__ */ new Error(`Vitest Module Runner doesn't support Vite HMR events.`) };
555
+ if (event.event !== "vite:invoke") return { error: /* @__PURE__ */ new Error(`Vitest Module Runner doesn't support ${event.event} event.`) };
556
+ const { name, data } = event.data;
557
+ if (name === "getBuiltins")
558
+ // we return an empty array here to avoid client-side builtin check,
559
+ // as we need builtins to go through `fetchModule`
560
+ return { result: [] };
561
+ if (name !== "fetchModule") return { error: /* @__PURE__ */ new Error(`Unknown method: ${name}. Expected "fetchModule".`) };
562
+ try {
563
+ return { result: await this.options.fetchModule(...data) };
564
+ } catch (error) {
565
+ return { error };
566
+ }
567
+ }
568
+ }
569
+
570
570
  const createNodeImportMeta = (modulePath) => {
571
571
  if (!viteModuleRunner.createDefaultImportMeta) throw new Error(`createNodeImportMeta is not supported in this version of Vite.`);
572
572
  const defaultMeta = viteModuleRunner.createDefaultImportMeta(modulePath);
@@ -858,4 +858,4 @@ function startVitestModuleRunner(options) {
858
858
  return moduleRunner;
859
859
  }
860
860
 
861
- export { VitestModuleRunner as V, VITEST_VM_CONTEXT_SYMBOL as a, VitestTransport as b, createNodeImportMeta as c, startVitestModuleRunner as s };
861
+ export { VITEST_VM_CONTEXT_SYMBOL as V, VitestModuleRunner as a, VitestTransport as b, createNodeImportMeta as c, startVitestModuleRunner as s };