vitest 3.0.9 → 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.
- package/dist/browser.js +4 -4
- package/dist/chunks/base.CylSMlTD.js +41 -0
- package/dist/chunks/benchmark.BKUatJGy.js +39 -0
- package/dist/chunks/cac.JtTXbKz0.js +1525 -0
- package/dist/chunks/{cli-api.Ckwz_xSb.js → cli-api.BTtPTYMs.js} +4638 -5072
- package/dist/chunks/console.D6t261w0.js +173 -0
- package/dist/chunks/constants.BZZyIeIE.js +43 -0
- package/dist/chunks/coverage.0iPg4Wrz.js +33 -0
- package/dist/chunks/{coverage.gV8doR2Y.js → coverage.C2ohxaN0.js} +2216 -2479
- package/dist/chunks/creator.BEXek7yQ.js +640 -0
- package/dist/chunks/date.CDOsz-HY.js +53 -0
- package/dist/chunks/defaults.DmfNPoe5.js +114 -0
- package/dist/chunks/{env.D4Lgay0q.js → env.Dq0hM4Xv.js} +1 -1
- package/dist/chunks/execute.DZKwfrTs.js +791 -0
- package/dist/chunks/git.DXfdBEfR.js +74 -0
- package/dist/chunks/{globals.BEpDe-k3.js → globals.DCbUWjip.js} +10 -10
- package/dist/chunks/{index.D7Ny8f_s.js → index.BDobFbcz.js} +6 -7
- package/dist/chunks/index.DFXFpH3w.js +607 -0
- package/dist/chunks/index.VfYQ6MXY.js +104 -0
- package/dist/chunks/index.ZIOEXBQB.js +2382 -0
- package/dist/chunks/inspector.DbDkSkFn.js +54 -0
- package/dist/chunks/node.IqGoMrm4.js +15 -0
- package/dist/chunks/{reporters.d.CqBhtcTq.d.ts → reporters.d.5g6jXhoW.d.ts} +25 -8
- package/dist/chunks/rpc.DGgL5dw7.js +92 -0
- package/dist/chunks/run-once.I7PpBOk1.js +47 -0
- package/dist/chunks/runBaseTests.CqmKSG99.js +134 -0
- package/dist/chunks/setup-common.DEGDGBiA.js +88 -0
- package/dist/chunks/{typechecker.BlF3eHsb.js → typechecker.C2IpOhid.js} +620 -622
- package/dist/chunks/utils.BfxieIyZ.js +66 -0
- package/dist/chunks/utils.CtocqOoE.js +72 -0
- package/dist/chunks/utils.OLmtDstN.js +194 -0
- package/dist/chunks/{vi.nSCvwQ7l.js → vi.B-PuvDzu.js} +878 -1019
- package/dist/chunks/vite.d.Dh1jE-_V.d.ts +23 -0
- package/dist/chunks/vm.BW5voG-u.js +789 -0
- package/dist/cli.js +2 -2
- package/dist/config.cjs +97 -103
- package/dist/config.d.ts +3 -3
- package/dist/config.js +6 -6
- package/dist/coverage.d.ts +1 -1
- package/dist/coverage.js +6 -6
- package/dist/environments.js +1 -1
- package/dist/execute.js +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +6 -6
- package/dist/node.d.ts +3 -3
- package/dist/node.js +36 -45
- package/dist/path.js +1 -4
- package/dist/reporters.d.ts +1 -1
- package/dist/reporters.js +4 -4
- package/dist/runners.js +231 -267
- package/dist/snapshot.js +2 -2
- package/dist/suite.js +2 -2
- package/dist/worker.js +98 -114
- package/dist/workers/forks.js +22 -22
- package/dist/workers/runVmTests.js +61 -66
- package/dist/workers/threads.js +13 -13
- package/dist/workers/vmForks.js +24 -24
- package/dist/workers/vmThreads.js +15 -15
- package/dist/workers.js +10 -10
- package/package.json +11 -11
- package/dist/chunks/base.DV59CbtV.js +0 -45
- package/dist/chunks/benchmark.DL72EVN-.js +0 -40
- package/dist/chunks/cac.CeVHgzve.js +0 -1659
- package/dist/chunks/console.CN7AiMGV.js +0 -179
- package/dist/chunks/constants.DTYd6dNH.js +0 -46
- package/dist/chunks/coverage.A3sS5-Wm.js +0 -40
- package/dist/chunks/creator.BsBnpTzI.js +0 -670
- package/dist/chunks/date.W2xKR2qe.js +0 -53
- package/dist/chunks/defaults.C2Ndd9wx.js +0 -119
- package/dist/chunks/execute.eDH0aFFd.js +0 -839
- package/dist/chunks/git.B5SDxu-n.js +0 -69
- package/dist/chunks/index.B8tIoLPT.js +0 -2526
- package/dist/chunks/index.K90BXFOx.js +0 -658
- package/dist/chunks/index.uXkkC4xl.js +0 -111
- package/dist/chunks/inspector.DKLceBVD.js +0 -54
- package/dist/chunks/node.AKq966Jp.js +0 -15
- package/dist/chunks/rpc.TVf73xOu.js +0 -102
- package/dist/chunks/run-once.2ogXb3JV.js +0 -28
- package/dist/chunks/runBaseTests.BVrL_ow3.js +0 -142
- package/dist/chunks/setup-common.CPvtqi8q.js +0 -96
- package/dist/chunks/utils.C8RiOc4B.js +0 -77
- package/dist/chunks/utils.Cn0zI1t3.js +0 -68
- package/dist/chunks/utils.bLM2atbD.js +0 -198
- package/dist/chunks/vite.d.BUZTGxQ3.d.ts +0 -11
- 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 };
|
|
@@ -639,6 +639,10 @@ declare abstract class BaseReporter implements Reporter {
|
|
|
639
639
|
error(...messages: any): void;
|
|
640
640
|
relative(path: string): string;
|
|
641
641
|
onFinished(files?: File[], errors?: unknown[]): void;
|
|
642
|
+
onTestCaseResult(testCase: TestCase): void;
|
|
643
|
+
onTestSuiteResult(testSuite: TestSuite): void;
|
|
644
|
+
onTestModuleEnd(testModule: TestModule): void;
|
|
645
|
+
private logFailedTask;
|
|
642
646
|
onTaskUpdate(packs: TaskResultPack[]): void;
|
|
643
647
|
/**
|
|
644
648
|
* Callback invoked with a single `Task` from `onTaskUpdate`
|
|
@@ -648,12 +652,12 @@ declare abstract class BaseReporter implements Reporter {
|
|
|
648
652
|
protected getTestName(test: Task, separator?: string): string;
|
|
649
653
|
protected formatShortError(error: ErrorWithDiff): string;
|
|
650
654
|
protected getTestIndentation(_test: Task): string;
|
|
651
|
-
|
|
655
|
+
protected getDurationPrefix(task: Task): string;
|
|
652
656
|
onWatcherStart(files?: File[], errors?: unknown[]): void;
|
|
653
657
|
onWatcherRerun(files: string[], trigger?: string): void;
|
|
654
|
-
onUserConsoleLog(log: UserConsoleLog): void;
|
|
658
|
+
onUserConsoleLog(log: UserConsoleLog, taskState?: TestResult["state"]): void;
|
|
655
659
|
onTestRemoved(trigger?: string): void;
|
|
656
|
-
shouldLog(log: UserConsoleLog): boolean;
|
|
660
|
+
shouldLog(log: UserConsoleLog, taskState?: TestResult["state"]): boolean;
|
|
657
661
|
onServerRestart(reason?: string): void;
|
|
658
662
|
reportSummary(files: File[], errors: unknown[]): void;
|
|
659
663
|
reportTestSummary(files: File[], errors: unknown[]): void;
|
|
@@ -917,7 +921,7 @@ declare class DotReporter extends BaseReporter {
|
|
|
917
921
|
onTestModuleCollected(module: TestModule): void;
|
|
918
922
|
onTestCaseReady(test: TestCase): void;
|
|
919
923
|
onTestCaseResult(test: TestCase): void;
|
|
920
|
-
onTestModuleEnd(): void;
|
|
924
|
+
onTestModuleEnd(testModule: TestModule): void;
|
|
921
925
|
private createSummary;
|
|
922
926
|
}
|
|
923
927
|
|
|
@@ -1726,9 +1730,11 @@ interface InlineConfig {
|
|
|
1726
1730
|
/**
|
|
1727
1731
|
* Silent mode
|
|
1728
1732
|
*
|
|
1733
|
+
* Use `'passed-only'` to see logs from failing tests only.
|
|
1734
|
+
*
|
|
1729
1735
|
* @default false
|
|
1730
1736
|
*/
|
|
1731
|
-
silent?: boolean;
|
|
1737
|
+
silent?: boolean | "passed-only";
|
|
1732
1738
|
/**
|
|
1733
1739
|
* Hide logs for skipped tests
|
|
1734
1740
|
*
|
|
@@ -2232,7 +2238,7 @@ interface UserWorkspaceConfig extends UserConfig$1 {
|
|
|
2232
2238
|
}
|
|
2233
2239
|
type UserProjectConfigFn = (env: ConfigEnv) => UserWorkspaceConfig | Promise<UserWorkspaceConfig>;
|
|
2234
2240
|
type UserProjectConfigExport = UserWorkspaceConfig | Promise<UserWorkspaceConfig> | UserProjectConfigFn;
|
|
2235
|
-
type
|
|
2241
|
+
type TestProjectInlineConfiguration = (UserWorkspaceConfig & {
|
|
2236
2242
|
/**
|
|
2237
2243
|
* Relative path to the extendable config. All other options will be merged with this config.
|
|
2238
2244
|
* If `true`, the project will inherit all options from the root config.
|
|
@@ -2240,6 +2246,7 @@ type TestProjectConfiguration = string | (UserProjectConfigExport & {
|
|
|
2240
2246
|
*/
|
|
2241
2247
|
extends?: string | true
|
|
2242
2248
|
});
|
|
2249
|
+
type TestProjectConfiguration = string | TestProjectInlineConfiguration | Promise<UserWorkspaceConfig> | UserProjectConfigFn;
|
|
2243
2250
|
/** @deprecated use `TestProjectConfiguration` instead */
|
|
2244
2251
|
type WorkspaceProjectConfiguration = TestProjectConfiguration;
|
|
2245
2252
|
|
|
@@ -2630,7 +2637,7 @@ interface SerializedTestProject {
|
|
|
2630
2637
|
serializedConfig: SerializedConfig;
|
|
2631
2638
|
context: ProvidedContext;
|
|
2632
2639
|
}
|
|
2633
|
-
interface InitializeProjectOptions extends
|
|
2640
|
+
interface InitializeProjectOptions extends TestProjectInlineConfiguration {
|
|
2634
2641
|
configFile: string | false;
|
|
2635
2642
|
}
|
|
2636
2643
|
|
|
@@ -2819,6 +2826,12 @@ declare class Vitest {
|
|
|
2819
2826
|
/** @deprecated internal */
|
|
2820
2827
|
setServer(options: UserConfig, server: ViteDevServer, cliOptions: UserConfig): Promise<void>;
|
|
2821
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
|
+
/**
|
|
2822
2835
|
* Provide a value to the test context. This value will be available to all tests with `inject`.
|
|
2823
2836
|
*/
|
|
2824
2837
|
provide: <T extends keyof ProvidedContext & string>(key: T, value: ProvidedContext[T]) => void;
|
|
@@ -2999,8 +3012,12 @@ declare class Vitest {
|
|
|
2999
3012
|
* vitest.onFilterWatchedSpecification(specification => testsToRun.includes(specification.moduleId))
|
|
3000
3013
|
*/
|
|
3001
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;
|
|
3002
3019
|
}
|
|
3003
3020
|
type OnServerRestartHandler = (reason?: string) => Promise<void> | void;
|
|
3004
3021
|
type OnTestsRerunHandler = (testFiles: TestSpecification[]) => Promise<void> | void;
|
|
3005
3022
|
|
|
3006
|
-
export { type
|
|
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 };
|