vitest 4.0.10 → 4.0.12
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.
- package/dist/browser.d.ts +3 -3
- package/dist/browser.js +1 -1
- package/dist/chunks/{base.BFVArrYW.js → base.CDEiaaLz.js} +46 -39
- package/dist/chunks/{browser.d.DnU_kh8a.d.ts → browser.d.Bq3zc1l_.d.ts} +1 -1
- package/dist/chunks/{cac.D9CYcNPM.js → cac.D9QaLeSz.js} +21 -7
- package/dist/chunks/{cli-api.RnIE1JbW.js → cli-api.BJh-POxZ.js} +914 -297
- package/dist/chunks/{coverage.BUlIqJrL.js → coverage.CtyeYmKM.js} +7 -1
- package/dist/chunks/{creator.DU9qFjsW.js → creator.DAmOKTvJ.js} +3 -3
- package/dist/chunks/{global.d.BQDgW9Pr.d.ts → global.d.Dheepru6.d.ts} +1 -1
- package/dist/chunks/{globals.NLOzC_A5.js → globals.C0izxiX3.js} +1 -1
- package/dist/chunks/{index.B8lJfb0J.js → index.CMvpbrsJ.js} +1 -1
- package/dist/chunks/{index.Dua7TZg_.js → index.CQwQ_SLL.js} +16 -4
- package/dist/chunks/{index.DZ-mI_Nm.js → index.DBx1AtPJ.js} +2 -1
- package/dist/chunks/{index.BYek7GgP.js → index.DWDW6mLz.js} +10 -1
- package/dist/chunks/{init-forks.BZSlxfwV.js → init-forks.FphdQhPI.js} +5 -5
- package/dist/chunks/{init-threads.CwE2n-Bv.js → init-threads.BfqfWDNi.js} +3 -3
- package/dist/chunks/{init.Cz2kTB9a.js → init.D-GGeAxo.js} +59 -21
- package/dist/chunks/{moduleRunner.d.BxT-OjLR.d.ts → moduleRunner.d.RBEiFdiW.d.ts} +5 -1
- package/dist/chunks/plugin.d.DGpEw-QV.d.ts +38 -0
- package/dist/chunks/{reporters.d.keG-yFSu.d.ts → reporters.d.C2PtoEFY.d.ts} +107 -47
- package/dist/chunks/{setup-common.BOzbXE3x.js → setup-common.DGHc_BUK.js} +1 -1
- package/dist/chunks/{startModuleRunner.DLjmA_wU.js → startModuleRunner.BEYtrq5Y.js} +97 -49
- package/dist/chunks/{test.BPErLMrw.js → test.DqQZzsWf.js} +14 -4
- package/dist/chunks/traces.U4xDYhzZ.js +172 -0
- package/dist/chunks/{config.d.BTfZNUu9.d.ts → traces.d.Brik_NWu.d.ts} +21 -1
- package/dist/chunks/{vm.wSHjz-et.js → vm.tWlKAMXr.js} +12 -8
- package/dist/chunks/{worker.d.ZGohxCEd.d.ts → worker.d.Dxl5oW0C.d.ts} +4 -4
- package/dist/cli.js +2 -2
- package/dist/config.d.ts +7 -7
- package/dist/coverage.d.ts +5 -5
- package/dist/coverage.js +2 -2
- package/dist/index.d.ts +11 -10
- package/dist/index.js +2 -2
- package/dist/module-evaluator.d.ts +3 -3
- package/dist/module-evaluator.js +14 -1
- package/dist/module-runner.js +2 -1
- package/dist/node.d.ts +10 -10
- package/dist/node.js +8 -7
- package/dist/reporters.d.ts +5 -5
- package/dist/reporters.js +2 -2
- package/dist/runners.d.ts +4 -1
- package/dist/runners.js +1 -1
- package/dist/worker.d.ts +7 -7
- package/dist/worker.js +8 -7
- package/dist/workers/forks.js +9 -8
- package/dist/workers/runVmTests.js +22 -20
- package/dist/workers/threads.js +9 -8
- package/dist/workers/vmForks.js +5 -4
- package/dist/workers/vmThreads.js +5 -4
- package/package.json +17 -12
- package/dist/chunks/plugin.d.C6KrdvNG.d.ts +0 -9
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { TaskMeta, Suite, File, TestAnnotation, ImportDuration, Test, Task, TaskResultPack, FileSpecification, CancelReason, SequenceSetupFiles, SequenceHooks } from '@vitest/runner';
|
|
1
|
+
import { TaskMeta, Suite, File, 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
|
-
import { A as AfterSuiteRunMeta, U as UserConsoleLog, P as ProvidedContext, d as ContextTestEnvironment, f as WorkerTestEnvironment, g as WorkerExecuteContext, L as LabelColor } from './worker.d.
|
|
3
|
+
import { A as AfterSuiteRunMeta, U as UserConsoleLog, P as ProvidedContext, d as ContextTestEnvironment, f as WorkerTestEnvironment, g as WorkerExecuteContext, L as LabelColor } from './worker.d.Dxl5oW0C.js';
|
|
4
4
|
import { Writable } from 'node:stream';
|
|
5
5
|
import { TransformResult as TransformResult$1, ViteDevServer, Plugin, UserConfig as UserConfig$1, DepOptimizationConfig, ServerOptions, ConfigEnv, AliasOptions } from 'vite';
|
|
6
6
|
import { MockedModule } from '@vitest/mocker';
|
|
7
7
|
import { StackTraceParserOptions } from '@vitest/utils/source-map';
|
|
8
8
|
import { BrowserCommands } from 'vitest/browser';
|
|
9
|
-
import { B as BrowserTraceViewMode, S as SerializedConfig, F as FakeTimerInstallOpts } from './
|
|
10
|
-
import { S as SerializedTestSpecification, B as BrowserTesterOptions } from './browser.d.
|
|
9
|
+
import { B as BrowserTraceViewMode, S as SerializedConfig, O as OTELCarrier, F as FakeTimerInstallOpts } from './traces.d.Brik_NWu.js';
|
|
10
|
+
import { S as SerializedTestSpecification, B as BrowserTesterOptions } from './browser.d.Bq3zc1l_.js';
|
|
11
11
|
import { PrettyFormatOptions } from '@vitest/pretty-format';
|
|
12
12
|
import { SnapshotSummary, SnapshotStateOptions } from '@vitest/snapshot';
|
|
13
13
|
import { SerializedDiffOptions } from '@vitest/utils/diff';
|
|
@@ -16,8 +16,8 @@ import { happyDomTypes, jsdomTypes } from 'vitest/optional-types.js';
|
|
|
16
16
|
import { B as BenchmarkResult } from './benchmark.d.DAaHLpsq.js';
|
|
17
17
|
import { a as RuntimeCoverageProviderModule } from './coverage.d.BZtK59WP.js';
|
|
18
18
|
import { SnapshotManager } from '@vitest/snapshot/manager';
|
|
19
|
-
import { Stats } from 'node:fs';
|
|
20
19
|
import { Console } from 'node:console';
|
|
20
|
+
import { Stats } from 'node:fs';
|
|
21
21
|
|
|
22
22
|
type ChaiConfig = Omit<Partial<typeof chai.config>, "useProxy" | "proxyExcludedKeys">;
|
|
23
23
|
|
|
@@ -134,6 +134,12 @@ declare class TestCase extends ReportedTaskImplementation {
|
|
|
134
134
|
*/
|
|
135
135
|
annotations(): ReadonlyArray<TestAnnotation>;
|
|
136
136
|
/**
|
|
137
|
+
* @experimental
|
|
138
|
+
*
|
|
139
|
+
* Test artifacts recorded via the `recordArtifact` API during the test execution.
|
|
140
|
+
*/
|
|
141
|
+
artifacts(): ReadonlyArray<TestArtifact>;
|
|
142
|
+
/**
|
|
137
143
|
* Useful information about the test like duration, memory usage, etc.
|
|
138
144
|
* Diagnostic is only available after the test has finished.
|
|
139
145
|
*/
|
|
@@ -619,6 +625,12 @@ interface CoverageProvider {
|
|
|
619
625
|
mergeReports?: (coverages: CoverageResults[]) => void | Promise<void>;
|
|
620
626
|
/** Callback called for instrumenting files with coverage counters. */
|
|
621
627
|
onFileTransform?: (sourceCode: string, id: string, pluginCtx: any) => TransformResult | Promise<TransformResult>;
|
|
628
|
+
/**
|
|
629
|
+
* Return `true` if this file is transformed by the coverage provider.
|
|
630
|
+
* This is used to generate the persistent file hash by `fsModuleCache`
|
|
631
|
+
* @experimental
|
|
632
|
+
*/
|
|
633
|
+
requiresTransform?: (id: string) => boolean;
|
|
622
634
|
/** Callback that's called when the coverage is enabled via a programmatic `enableCoverage` API. */
|
|
623
635
|
onEnabled?: () => void | Promise<void>;
|
|
624
636
|
}
|
|
@@ -809,46 +821,6 @@ interface TestRunResult {
|
|
|
809
821
|
unhandledErrors: unknown[];
|
|
810
822
|
}
|
|
811
823
|
|
|
812
|
-
interface SuiteResultCache {
|
|
813
|
-
failed: boolean;
|
|
814
|
-
duration: number;
|
|
815
|
-
}
|
|
816
|
-
declare class ResultsCache {
|
|
817
|
-
private cache;
|
|
818
|
-
private workspacesKeyMap;
|
|
819
|
-
private cachePath;
|
|
820
|
-
private version;
|
|
821
|
-
private root;
|
|
822
|
-
constructor(version: string);
|
|
823
|
-
getCachePath(): string | null;
|
|
824
|
-
setConfig(root: string, config: ResolvedConfig["cache"]): void;
|
|
825
|
-
getResults(key: string): SuiteResultCache | undefined;
|
|
826
|
-
readFromCache(): Promise<void>;
|
|
827
|
-
updateResults(files: File[]): void;
|
|
828
|
-
removeFromCache(filepath: string): void;
|
|
829
|
-
writeToCache(): Promise<void>;
|
|
830
|
-
}
|
|
831
|
-
|
|
832
|
-
type FileStatsCache = Pick<Stats, "size">;
|
|
833
|
-
declare class FilesStatsCache {
|
|
834
|
-
cache: Map<string, FileStatsCache>;
|
|
835
|
-
getStats(key: string): FileStatsCache | undefined;
|
|
836
|
-
populateStats(root: string, specs: TestSpecification[]): Promise<void>;
|
|
837
|
-
updateStats(fsPath: string, key: string): Promise<void>;
|
|
838
|
-
removeStats(fsPath: string): void;
|
|
839
|
-
}
|
|
840
|
-
|
|
841
|
-
declare class VitestCache {
|
|
842
|
-
results: ResultsCache;
|
|
843
|
-
stats: FilesStatsCache;
|
|
844
|
-
constructor(version: string);
|
|
845
|
-
getFileTestResults(key: string): SuiteResultCache | undefined;
|
|
846
|
-
getFileStats(key: string): {
|
|
847
|
-
size: number;
|
|
848
|
-
} | undefined;
|
|
849
|
-
static resolveCacheDir(root: string, dir?: string, projectName?: string): string;
|
|
850
|
-
}
|
|
851
|
-
|
|
852
824
|
declare class TypeCheckError extends Error {
|
|
853
825
|
message: string;
|
|
854
826
|
stacks: ParsedStack[];
|
|
@@ -896,6 +868,48 @@ declare class Logger {
|
|
|
896
868
|
private registerUnhandledRejection;
|
|
897
869
|
}
|
|
898
870
|
|
|
871
|
+
interface SuiteResultCache {
|
|
872
|
+
failed: boolean;
|
|
873
|
+
duration: number;
|
|
874
|
+
}
|
|
875
|
+
declare class ResultsCache {
|
|
876
|
+
private logger;
|
|
877
|
+
private cache;
|
|
878
|
+
private workspacesKeyMap;
|
|
879
|
+
private cachePath;
|
|
880
|
+
private version;
|
|
881
|
+
private root;
|
|
882
|
+
constructor(logger: Logger);
|
|
883
|
+
getCachePath(): string | null;
|
|
884
|
+
setConfig(root: string, config: ResolvedConfig["cache"]): void;
|
|
885
|
+
getResults(key: string): SuiteResultCache | undefined;
|
|
886
|
+
clearCache(): Promise<void>;
|
|
887
|
+
readFromCache(): Promise<void>;
|
|
888
|
+
updateResults(files: File[]): void;
|
|
889
|
+
removeFromCache(filepath: string): void;
|
|
890
|
+
writeToCache(): Promise<void>;
|
|
891
|
+
}
|
|
892
|
+
|
|
893
|
+
type FileStatsCache = Pick<Stats, "size">;
|
|
894
|
+
declare class FilesStatsCache {
|
|
895
|
+
cache: Map<string, FileStatsCache>;
|
|
896
|
+
getStats(key: string): FileStatsCache | undefined;
|
|
897
|
+
populateStats(root: string, specs: TestSpecification[]): Promise<void>;
|
|
898
|
+
updateStats(fsPath: string, key: string): Promise<void>;
|
|
899
|
+
removeStats(fsPath: string): void;
|
|
900
|
+
}
|
|
901
|
+
|
|
902
|
+
declare class VitestCache {
|
|
903
|
+
results: ResultsCache;
|
|
904
|
+
stats: FilesStatsCache;
|
|
905
|
+
constructor(logger: Logger);
|
|
906
|
+
getFileTestResults(key: string): SuiteResultCache | undefined;
|
|
907
|
+
getFileStats(key: string): {
|
|
908
|
+
size: number;
|
|
909
|
+
} | undefined;
|
|
910
|
+
static resolveCacheDir(root: string, dir?: string, projectName?: string): string;
|
|
911
|
+
}
|
|
912
|
+
|
|
899
913
|
declare class VitestPackageInstaller {
|
|
900
914
|
isPackageExists(name: string, options?: {
|
|
901
915
|
paths?: string[];
|
|
@@ -957,6 +971,10 @@ interface Reporter {
|
|
|
957
971
|
*/
|
|
958
972
|
onTestCaseAnnotate?: (testCase: TestCase, annotation: TestAnnotation) => Awaitable<void>;
|
|
959
973
|
/**
|
|
974
|
+
* Called when artifacts are recorded on tests via the `recordArtifact` utility.
|
|
975
|
+
*/
|
|
976
|
+
onTestCaseArtifactRecord?: (testCase: TestCase, artifact: TestArtifact) => Awaitable<void>;
|
|
977
|
+
/**
|
|
960
978
|
* Called when test suite is ready to run.
|
|
961
979
|
* Called before the `beforeAll` hooks for the test are run.
|
|
962
980
|
*/
|
|
@@ -1159,6 +1177,7 @@ declare class Vitest {
|
|
|
1159
1177
|
get cache(): VitestCache;
|
|
1160
1178
|
enableCoverage(): Promise<void>;
|
|
1161
1179
|
disableCoverage(): void;
|
|
1180
|
+
private clearAllCachePaths;
|
|
1162
1181
|
private _coverageOverrideCache;
|
|
1163
1182
|
/**
|
|
1164
1183
|
* Inject new test projects into the workspace.
|
|
@@ -1196,6 +1215,11 @@ declare class Vitest {
|
|
|
1196
1215
|
globTestSpecifications(filters?: string[]): Promise<TestSpecification[]>;
|
|
1197
1216
|
private initCoverageProvider;
|
|
1198
1217
|
/**
|
|
1218
|
+
* Deletes all Vitest caches, including `experimental.fsModuleCache`.
|
|
1219
|
+
* @experimental
|
|
1220
|
+
*/
|
|
1221
|
+
experimental_clearCache(): Promise<void>;
|
|
1222
|
+
/**
|
|
1199
1223
|
* Merge reports from multiple runs located in the specified directory (value from `--merge-reports` if not specified).
|
|
1200
1224
|
*/
|
|
1201
1225
|
mergeReports(directory?: string): Promise<TestRunResult>;
|
|
@@ -1377,7 +1401,7 @@ interface BrowserServerOptions {
|
|
|
1377
1401
|
metaEnvReplacer: () => Plugin;
|
|
1378
1402
|
}
|
|
1379
1403
|
interface BrowserServerFactory {
|
|
1380
|
-
(
|
|
1404
|
+
(options: BrowserServerOptions): Promise<ParentProjectBrowser>;
|
|
1381
1405
|
}
|
|
1382
1406
|
interface BrowserProvider {
|
|
1383
1407
|
name: string;
|
|
@@ -1919,16 +1943,24 @@ type WorkerRequest = {
|
|
|
1919
1943
|
config: SerializedConfig;
|
|
1920
1944
|
pool: string;
|
|
1921
1945
|
};
|
|
1946
|
+
traces: {
|
|
1947
|
+
enabled: boolean;
|
|
1948
|
+
sdkPath?: string;
|
|
1949
|
+
otelCarrier?: OTELCarrier;
|
|
1950
|
+
};
|
|
1922
1951
|
} | {
|
|
1923
1952
|
type: "stop";
|
|
1953
|
+
otelCarrier?: OTELCarrier;
|
|
1924
1954
|
} | {
|
|
1925
1955
|
type: "run";
|
|
1926
1956
|
context: WorkerExecuteContext;
|
|
1927
1957
|
poolId: number;
|
|
1958
|
+
otelCarrier?: OTELCarrier;
|
|
1928
1959
|
} | {
|
|
1929
1960
|
type: "collect";
|
|
1930
1961
|
context: WorkerExecuteContext;
|
|
1931
1962
|
poolId: number;
|
|
1963
|
+
otelCarrier?: OTELCarrier;
|
|
1932
1964
|
} | {
|
|
1933
1965
|
type: "cancel";
|
|
1934
1966
|
});
|
|
@@ -2963,6 +2995,29 @@ interface InlineConfig {
|
|
|
2963
2995
|
* @default '.vitest-attachments'
|
|
2964
2996
|
*/
|
|
2965
2997
|
attachmentsDir?: string;
|
|
2998
|
+
/**
|
|
2999
|
+
* Experimental features
|
|
3000
|
+
*
|
|
3001
|
+
* @experimental
|
|
3002
|
+
*/
|
|
3003
|
+
experimental?: {
|
|
3004
|
+
/**
|
|
3005
|
+
* Enable caching of modules on the file system between reruns.
|
|
3006
|
+
*/
|
|
3007
|
+
fsModuleCache?: boolean;
|
|
3008
|
+
/**
|
|
3009
|
+
* Path relative to the root of the project where the fs module cache will be stored.
|
|
3010
|
+
* @default node_modules/.experimental-vitest-cache
|
|
3011
|
+
*/
|
|
3012
|
+
fsModuleCachePath?: string;
|
|
3013
|
+
/**
|
|
3014
|
+
* {@link https://vitest.dev/guide/open-telemetry}
|
|
3015
|
+
*/
|
|
3016
|
+
openTelemetry?: {
|
|
3017
|
+
enabled: boolean;
|
|
3018
|
+
sdkPath?: string;
|
|
3019
|
+
};
|
|
3020
|
+
};
|
|
2966
3021
|
}
|
|
2967
3022
|
interface TypecheckConfig {
|
|
2968
3023
|
/**
|
|
@@ -3078,6 +3133,11 @@ interface UserConfig extends InlineConfig {
|
|
|
3078
3133
|
* @default '.vitest-reports'
|
|
3079
3134
|
*/
|
|
3080
3135
|
mergeReports?: string;
|
|
3136
|
+
/**
|
|
3137
|
+
* Delete all Vitest caches, including `experimental.fsModuleCache`.
|
|
3138
|
+
* @experimental
|
|
3139
|
+
*/
|
|
3140
|
+
clearCache?: boolean;
|
|
3081
3141
|
}
|
|
3082
3142
|
type OnUnhandledErrorCallback = (error: (TestError | Error) & {
|
|
3083
3143
|
type: string;
|
|
@@ -3182,4 +3242,4 @@ type TestProjectInlineConfiguration = (UserWorkspaceConfig & {
|
|
|
3182
3242
|
type TestProjectConfiguration = string | TestProjectInlineConfiguration | Promise<UserWorkspaceConfig> | UserProjectConfigFn;
|
|
3183
3243
|
|
|
3184
3244
|
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 };
|
|
3185
|
-
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 _,
|
|
3245
|
+
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 };
|
|
@@ -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.
|
|
29
|
+
if (config.globals) (await import('./globals.C0izxiX3.js')).registerApiGlobally();
|
|
30
30
|
}
|
|
31
31
|
function setupDefines(config) {
|
|
32
32
|
for (const key in config.defines) globalThis[key] = config.defines[key];
|
|
@@ -10,6 +10,7 @@ import { resolve as resolve$1, isAbsolute as isAbsolute$1 } from 'node:path';
|
|
|
10
10
|
import vm from 'node:vm';
|
|
11
11
|
import { MockerRegistry, mockObject, RedirectedModule, AutomockedModule } from '@vitest/mocker';
|
|
12
12
|
import * as viteModuleRunner from 'vite/module-runner';
|
|
13
|
+
import { T as Traces } from './traces.U4xDYhzZ.js';
|
|
13
14
|
|
|
14
15
|
class VitestTransport {
|
|
15
16
|
constructor(options) {
|
|
@@ -234,10 +235,12 @@ class VitestMocker {
|
|
|
234
235
|
filterPublicKeys;
|
|
235
236
|
registries = /* @__PURE__ */ new Map();
|
|
236
237
|
mockContext = { callstack: null };
|
|
238
|
+
_otel;
|
|
237
239
|
constructor(moduleRunner, options) {
|
|
238
240
|
this.moduleRunner = moduleRunner;
|
|
239
241
|
this.options = options;
|
|
240
242
|
const context = this.options.context;
|
|
243
|
+
this._otel = options.traces;
|
|
241
244
|
if (context) this.primitives = vm.runInContext("({ Object, Error, Function, RegExp, Symbol, Array, Map })", context);
|
|
242
245
|
else this.primitives = {
|
|
243
246
|
Object,
|
|
@@ -309,23 +312,41 @@ class VitestMocker {
|
|
|
309
312
|
return error;
|
|
310
313
|
}
|
|
311
314
|
async resolveId(rawId, importer) {
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
+
return this._otel.$("vitest.mocker.resolve_id", { attributes: {
|
|
316
|
+
"vitest.module.raw_id": rawId,
|
|
317
|
+
"vitest.module.importer": rawId
|
|
318
|
+
} }, async (span) => {
|
|
319
|
+
const result = await this.options.resolveId(rawId, importer);
|
|
320
|
+
if (!result) {
|
|
321
|
+
span.addEvent("could not resolve id, fallback to unresolved values");
|
|
322
|
+
const id = normalizeModuleId(rawId);
|
|
323
|
+
span.setAttributes({
|
|
324
|
+
"vitest.module.id": id,
|
|
325
|
+
"vitest.module.url": rawId,
|
|
326
|
+
"vitest.module.external": id,
|
|
327
|
+
"vitest.module.fallback": true
|
|
328
|
+
});
|
|
329
|
+
return {
|
|
330
|
+
id,
|
|
331
|
+
url: rawId,
|
|
332
|
+
external: id
|
|
333
|
+
};
|
|
334
|
+
}
|
|
335
|
+
// external is node_module or unresolved module
|
|
336
|
+
// for example, some people mock "vscode" and don't have it installed
|
|
337
|
+
const external = !isAbsolute$1(result.file) || this.isModuleDirectory(result.file) ? normalizeModuleId(rawId) : null;
|
|
338
|
+
const id = normalizeModuleId(result.id);
|
|
339
|
+
span.setAttributes({
|
|
340
|
+
"vitest.module.id": id,
|
|
341
|
+
"vitest.module.url": result.url,
|
|
342
|
+
"vitest.module.external": external ?? false
|
|
343
|
+
});
|
|
315
344
|
return {
|
|
345
|
+
...result,
|
|
316
346
|
id,
|
|
317
|
-
|
|
318
|
-
external: id
|
|
347
|
+
external
|
|
319
348
|
};
|
|
320
|
-
}
|
|
321
|
-
// external is node_module or unresolved module
|
|
322
|
-
// for example, some people mock "vscode" and don't have it installed
|
|
323
|
-
const external = !isAbsolute$1(result.file) || this.isModuleDirectory(result.file) ? normalizeModuleId(rawId) : null;
|
|
324
|
-
return {
|
|
325
|
-
...result,
|
|
326
|
-
id: normalizeModuleId(result.id),
|
|
327
|
-
external
|
|
328
|
-
};
|
|
349
|
+
});
|
|
329
350
|
}
|
|
330
351
|
async resolveMocks() {
|
|
331
352
|
if (!VitestMocker.pendingIds.length) return;
|
|
@@ -437,40 +458,52 @@ If you need to partially mock a module, you can use "importOriginal" helper insi
|
|
|
437
458
|
return this.moduleRunner.cachedRequest(mock.redirect, node, [importer], void 0, true);
|
|
438
459
|
}
|
|
439
460
|
async requestWithMockedModule(url, evaluatedNode, callstack, mock) {
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
Object.defineProperty(exports$1, Symbol.toStringTag, {
|
|
449
|
-
value: "Module",
|
|
450
|
-
configurable: true,
|
|
451
|
-
writable: true
|
|
461
|
+
return this._otel.$("vitest.mocker.evaluate", async (span) => {
|
|
462
|
+
const mockId = this.getMockPath(evaluatedNode.id);
|
|
463
|
+
span.setAttributes({
|
|
464
|
+
"vitest.module.id": mockId,
|
|
465
|
+
"vitest.mock.type": mock.type,
|
|
466
|
+
"vitest.mock.id": mock.id,
|
|
467
|
+
"vitest.mock.url": mock.url,
|
|
468
|
+
"vitest.mock.raw": mock.raw
|
|
452
469
|
});
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
470
|
+
if (mock.type === "automock" || mock.type === "autospy") {
|
|
471
|
+
const cache = this.evaluatedModules.getModuleById(mockId);
|
|
472
|
+
if (cache && cache.mockedExports) return cache.mockedExports;
|
|
473
|
+
const Object = this.primitives.Object;
|
|
474
|
+
// we have to define a separate object that will copy all properties into itself
|
|
475
|
+
// and can't just use the same `exports` define automatically by Vite before the evaluator
|
|
476
|
+
const exports$1 = Object.create(null);
|
|
477
|
+
Object.defineProperty(exports$1, Symbol.toStringTag, {
|
|
478
|
+
value: "Module",
|
|
479
|
+
configurable: true,
|
|
480
|
+
writable: true
|
|
481
|
+
});
|
|
482
|
+
const node = this.ensureModule(mockId, this.getMockPath(evaluatedNode.url));
|
|
483
|
+
node.meta = evaluatedNode.meta;
|
|
484
|
+
node.file = evaluatedNode.file;
|
|
485
|
+
node.mockedExports = exports$1;
|
|
486
|
+
const mod = await this.moduleRunner.cachedRequest(url, node, callstack, void 0, true);
|
|
487
|
+
this.mockObject(mod, exports$1, mock.type);
|
|
488
|
+
return exports$1;
|
|
489
|
+
}
|
|
490
|
+
if (mock.type === "manual" && !callstack.includes(mockId) && !callstack.includes(url)) try {
|
|
491
|
+
callstack.push(mockId);
|
|
492
|
+
// this will not work if user does Promise.all(import(), import())
|
|
493
|
+
// we can also use AsyncLocalStorage to store callstack, but this won't work in the browser
|
|
494
|
+
// maybe we should improve mock API in the future?
|
|
495
|
+
this.mockContext.callstack = callstack;
|
|
496
|
+
return await this.callFunctionMock(mockId, this.getMockPath(url), mock);
|
|
497
|
+
} finally {
|
|
498
|
+
this.mockContext.callstack = null;
|
|
499
|
+
const indexMock = callstack.indexOf(mockId);
|
|
500
|
+
callstack.splice(indexMock, 1);
|
|
501
|
+
}
|
|
502
|
+
else if (mock.type === "redirect" && !callstack.includes(mock.redirect)) {
|
|
503
|
+
span.setAttribute("vitest.mock.redirect", mock.redirect);
|
|
504
|
+
return mock.redirect;
|
|
505
|
+
}
|
|
506
|
+
});
|
|
474
507
|
}
|
|
475
508
|
async mockedRequest(url, evaluatedNode, callstack) {
|
|
476
509
|
const mock = this.getDependencyMock(evaluatedNode.id);
|
|
@@ -554,6 +587,7 @@ function createImportMetaResolver() {
|
|
|
554
587
|
class VitestModuleRunner extends viteModuleRunner.ModuleRunner {
|
|
555
588
|
mocker;
|
|
556
589
|
moduleExecutionInfo;
|
|
590
|
+
_otel;
|
|
557
591
|
constructor(vitestOptions) {
|
|
558
592
|
const options = vitestOptions;
|
|
559
593
|
const transport = new VitestTransport(options.transport);
|
|
@@ -566,10 +600,12 @@ class VitestModuleRunner extends viteModuleRunner.ModuleRunner {
|
|
|
566
600
|
createImportMeta: vitestOptions.createImportMeta
|
|
567
601
|
}, options.evaluator);
|
|
568
602
|
this.vitestOptions = vitestOptions;
|
|
603
|
+
this._otel = vitestOptions.traces || new Traces({ enabled: false });
|
|
569
604
|
this.moduleExecutionInfo = options.getWorkerState().moduleExecutionInfo;
|
|
570
605
|
this.mocker = options.mocker || new VitestMocker(this, {
|
|
571
606
|
spyModule: options.spyModule,
|
|
572
607
|
context: options.vm?.context,
|
|
608
|
+
traces: this._otel,
|
|
573
609
|
resolveId: options.transport.resolveId,
|
|
574
610
|
get root() {
|
|
575
611
|
return options.getWorkerState().config.root;
|
|
@@ -599,7 +635,15 @@ class VitestModuleRunner extends viteModuleRunner.ModuleRunner {
|
|
|
599
635
|
return exports$1;
|
|
600
636
|
}
|
|
601
637
|
async import(rawId) {
|
|
602
|
-
const resolved = await this.
|
|
638
|
+
const resolved = await this._otel.$("vitest.module.resolve_id", { attributes: { "vitest.module.raw_id": rawId } }, async (span) => {
|
|
639
|
+
const result = await this.vitestOptions.transport.resolveId(rawId);
|
|
640
|
+
if (result) span.setAttributes({
|
|
641
|
+
"vitest.module.url": result.url,
|
|
642
|
+
"vitest.module.file": result.file,
|
|
643
|
+
"vitest.module.id": result.id
|
|
644
|
+
});
|
|
645
|
+
return result;
|
|
646
|
+
});
|
|
603
647
|
return super.import(resolved ? resolved.url : rawId);
|
|
604
648
|
}
|
|
605
649
|
async fetchModule(url, importer) {
|
|
@@ -716,6 +760,7 @@ const VITEST_VM_CONTEXT_SYMBOL = "__vitest_vm_context__";
|
|
|
716
760
|
const cwd = process.cwd();
|
|
717
761
|
const isWindows = process.platform === "win32";
|
|
718
762
|
function startVitestModuleRunner(options) {
|
|
763
|
+
const traces = options.traces;
|
|
719
764
|
const state = () => globalThis.__vitest_worker__ || options.state;
|
|
720
765
|
const rpc = () => state().rpc;
|
|
721
766
|
process.exit = (code = process.exitCode || 0) => {
|
|
@@ -731,6 +776,7 @@ function startVitestModuleRunner(options) {
|
|
|
731
776
|
externalModulesExecutor: options.externalModulesExecutor
|
|
732
777
|
} : void 0;
|
|
733
778
|
const evaluator = options.evaluator || new VitestModuleEvaluator(vm, {
|
|
779
|
+
traces,
|
|
734
780
|
get moduleExecutionInfo() {
|
|
735
781
|
return state().moduleExecutionInfo;
|
|
736
782
|
},
|
|
@@ -743,6 +789,7 @@ function startVitestModuleRunner(options) {
|
|
|
743
789
|
spyModule: options.spyModule,
|
|
744
790
|
evaluatedModules: options.evaluatedModules,
|
|
745
791
|
evaluator,
|
|
792
|
+
traces,
|
|
746
793
|
mocker: options.mocker,
|
|
747
794
|
transport: {
|
|
748
795
|
async fetchModule(id, importer, options) {
|
|
@@ -774,7 +821,8 @@ function startVitestModuleRunner(options) {
|
|
|
774
821
|
externalize: toBuiltin(rawId),
|
|
775
822
|
type: "builtin"
|
|
776
823
|
};
|
|
777
|
-
const
|
|
824
|
+
const otelCarrier = traces?.getContextCarrier();
|
|
825
|
+
const result = await rpc().fetch(id, importer, environment(), options, otelCarrier);
|
|
778
826
|
if ("cached" in result) return {
|
|
779
827
|
code: readFileSync(result.tmp, "utf-8"),
|
|
780
828
|
...result
|
|
@@ -121,6 +121,7 @@ class VitestTestRunner {
|
|
|
121
121
|
cancelRun = false;
|
|
122
122
|
assertionsErrors = /* @__PURE__ */ new WeakMap();
|
|
123
123
|
pool = this.workerState.ctx.pool;
|
|
124
|
+
_otel;
|
|
124
125
|
constructor(config) {
|
|
125
126
|
this.config = config;
|
|
126
127
|
}
|
|
@@ -129,7 +130,7 @@ class VitestTestRunner {
|
|
|
129
130
|
const moduleNode = this.workerState.evaluatedModules.getModuleById(filepath);
|
|
130
131
|
if (moduleNode) this.workerState.evaluatedModules.invalidateModule(moduleNode);
|
|
131
132
|
}
|
|
132
|
-
return this.moduleRunner.import(filepath);
|
|
133
|
+
return this._otel.$(`vitest.module.import_${source === "setup" ? "setup" : "spec"}`, { attributes: { "code.file.path": filepath } }, () => this.moduleRunner.import(filepath));
|
|
133
134
|
}
|
|
134
135
|
onCollectStart(file) {
|
|
135
136
|
this.workerState.current = file;
|
|
@@ -220,11 +221,20 @@ class VitestTestRunner {
|
|
|
220
221
|
return context;
|
|
221
222
|
}
|
|
222
223
|
getImportDurations() {
|
|
223
|
-
const
|
|
224
|
-
|
|
224
|
+
const importDurations = {};
|
|
225
|
+
const entries = this.workerState.moduleExecutionInfo?.entries() || [];
|
|
226
|
+
for (const [filepath, { duration, selfTime }] of entries) importDurations[normalize(filepath)] = {
|
|
225
227
|
selfTime,
|
|
226
228
|
totalTime: duration
|
|
227
|
-
}
|
|
229
|
+
};
|
|
230
|
+
return importDurations;
|
|
231
|
+
}
|
|
232
|
+
trace = (name, attributes, cb) => {
|
|
233
|
+
const options = typeof attributes === "object" ? { attributes } : {};
|
|
234
|
+
return this._otel.$(`vitest.test.runner.${name}`, options, cb || attributes);
|
|
235
|
+
};
|
|
236
|
+
__setTraces(traces) {
|
|
237
|
+
this._otel = traces;
|
|
228
238
|
}
|
|
229
239
|
}
|
|
230
240
|
function clearModuleMocks(config) {
|