vitest 4.0.0-beta.4 → 4.0.0-beta.6
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/LICENSE.md +1 -1
- package/dist/browser.d.ts +8 -9
- package/dist/browser.js +3 -2
- package/dist/chunks/base.BXI97p6t.js +39 -0
- package/dist/chunks/{benchmark.CYdenmiT.js → benchmark.UW6Ezvxy.js} +6 -8
- package/dist/chunks/{browser.d.BRP8scJf.d.ts → browser.d.Cawq_X_N.d.ts} +1 -1
- package/dist/chunks/{cac.CY0IAxC4.js → cac.WE-urWw5.js} +38 -115
- package/dist/chunks/{cli-api.B8xRY9Zt.js → cli-api.CZz3evYC.js} +931 -1439
- package/dist/chunks/{config.d.DZo8c7fw.d.ts → config.d.CKNVOKm0.d.ts} +3 -8
- package/dist/chunks/{console.DoJHFxmj.js → console.B0quX7yH.js} +32 -68
- package/dist/chunks/{constants.CXzqaLmq.js → constants.D_Q9UYh-.js} +1 -6
- package/dist/chunks/{coverage.C84l9G-M.js → coverage.BPRS6xgn.js} +395 -665
- package/dist/chunks/{coverage.DVF1vEu8.js → coverage.D_JHT54q.js} +2 -2
- package/dist/chunks/{coverage.d.CNYjU4GF.d.ts → coverage.d.BZtK59WP.d.ts} +7 -5
- package/dist/chunks/{creator.yfA2ExGt.js → creator.KEg6n5IC.js} +29 -75
- package/dist/chunks/{date.Bq6ZW5rf.js → date.-jtEtIeV.js} +6 -17
- package/dist/chunks/{environment.d.Bhm9oc0v.d.ts → environment.d.2fYMoz3o.d.ts} +26 -4
- package/dist/chunks/{git.BVQ8w_Sw.js → git.BFNcloKD.js} +1 -2
- package/dist/chunks/{global.d.DAhT2emn.d.ts → global.d.K6uBQHzY.d.ts} +1 -1
- package/dist/chunks/{globals.Dgo-vS5G.js → globals.lgsmH00r.js} +7 -6
- package/dist/chunks/{index.D3SKT3tv.js → index.7w0eqmYM.js} +14 -24
- package/dist/chunks/{index.D1_MsKEt.js → index.AR8aAkCC.js} +4 -2
- package/dist/chunks/{index.CmSc2RE5.js → index.BG0gqZH-.js} +43 -106
- package/dist/chunks/{index.CtUvr1c8.js → index.CsFXYRkW.js} +27 -46
- package/dist/chunks/{index.Bz6b0Ib7.js → index.VNI-1z5c.js} +276 -604
- package/dist/chunks/{inspector.C914Efll.js → inspector.CvQD-Nie.js} +10 -25
- package/dist/chunks/moduleRunner.d.8kKUsuDg.d.ts +202 -0
- package/dist/chunks/moduleTransport.I-bgQy0S.js +19 -0
- package/dist/chunks/{node.fjCdwEIl.js → node.BOqcT2jW.js} +1 -1
- package/dist/chunks/{plugin.d.CLhMcYdD.d.ts → plugin.d.DuiQJfUL.d.ts} +1 -1
- package/dist/chunks/{reporters.d.DWg40D2B.d.ts → reporters.d.CqR9-CDJ.d.ts} +52 -101
- package/dist/chunks/resolver.Bx6lE0iq.js +119 -0
- package/dist/chunks/{rpc.jnQO9F8a.js → rpc.RpPylpp0.js} +7 -21
- package/dist/chunks/runBaseTests.D6sfuWBM.js +99 -0
- package/dist/chunks/{setup-common.Ebx5x0eP.js → setup-common.hLGRxhC8.js} +15 -27
- package/dist/chunks/startModuleRunner.C8TW8zTN.js +655 -0
- package/dist/chunks/{typechecker.CMNPqJOo.js → typechecker.Cd1wvxUM.js} +97 -209
- package/dist/chunks/{utils.CcGm2cd1.js → utils.C2YI6McM.js} +4 -13
- package/dist/chunks/{utils.XdZDrNZV.js → utils.C7__0Iv5.js} +7 -17
- package/dist/chunks/{vi.CA0EPI9Y.js → vi.BfdOiD4j.js} +116 -269
- package/dist/chunks/{vm.BUnLJt_P.js → vm.BHBje7cC.js} +101 -225
- package/dist/chunks/{worker.d.zjyR34Pb.d.ts → worker.d.D9QWnzAe.d.ts} +16 -13
- package/dist/chunks/{worker.d.C-1AbnVe.d.ts → worker.d.Db-UVmXc.d.ts} +1 -1
- package/dist/cli.js +4 -4
- package/dist/config.cjs +3 -9
- package/dist/config.d.ts +10 -12
- package/dist/config.js +1 -1
- package/dist/coverage.d.ts +10 -11
- package/dist/coverage.js +5 -6
- package/dist/environments.d.ts +2 -2
- package/dist/environments.js +1 -1
- package/dist/index.d.ts +10 -9
- package/dist/index.js +6 -5
- package/dist/module-evaluator.d.ts +12 -0
- package/dist/module-evaluator.js +276 -0
- package/dist/module-runner.js +15 -0
- package/dist/node.d.ts +12 -13
- package/dist/node.js +19 -24
- package/dist/reporters.d.ts +7 -8
- package/dist/reporters.js +3 -3
- package/dist/runners.d.ts +3 -3
- package/dist/runners.js +35 -57
- package/dist/snapshot.js +2 -2
- package/dist/suite.js +2 -2
- package/dist/worker.js +82 -45
- package/dist/workers/forks.js +11 -10
- package/dist/workers/runVmTests.js +27 -46
- package/dist/workers/threads.js +11 -10
- package/dist/workers/vmForks.js +11 -10
- package/dist/workers/vmThreads.js +11 -10
- package/dist/workers.d.ts +5 -4
- package/dist/workers.js +17 -16
- package/package.json +22 -17
- package/dist/chunks/base.BaCDDRPG.js +0 -38
- package/dist/chunks/execute.Dt-pCVcL.js +0 -708
- package/dist/chunks/runBaseTests.DBVVLMSb.js +0 -129
- package/dist/execute.d.ts +0 -148
- package/dist/execute.js +0 -13
package/dist/node.d.ts
CHANGED
|
@@ -3,36 +3,35 @@ import { InlineConfig, UserConfig as UserConfig$1, Plugin, ResolvedConfig as Res
|
|
|
3
3
|
export { vite as Vite };
|
|
4
4
|
export { esbuildVersion, isCSSRequest, isFileServingAllowed, parseAst, parseAstAsync, rollupVersion, version as viteVersion } from 'vite';
|
|
5
5
|
import { IncomingMessage } from 'node:http';
|
|
6
|
-
import { h as ResolvedConfig, f as UserConfig, i as VitestRunMode, j as VitestOptions, V as Vitest, A as ApiConfig, T as TestProject, k as TestSequencer, l as TestSpecification, L as Logger } from './chunks/reporters.d.
|
|
7
|
-
export {
|
|
8
|
-
import { R as RuntimeRPC } from './chunks/worker.d.
|
|
9
|
-
export { T as TestExecutionType } from './chunks/worker.d.
|
|
6
|
+
import { h as ResolvedConfig, f as UserConfig, i as VitestRunMode, j as VitestOptions, V as Vitest, A as ApiConfig, T as TestProject, k as TestSequencer, l as TestSpecification, L as Logger } from './chunks/reporters.d.CqR9-CDJ.js';
|
|
7
|
+
export { ap as BaseCoverageOptions, K as BenchmarkUserOptions, N as BrowserBuiltinProvider, Q as BrowserCommand, X as BrowserCommandContext, Y as BrowserConfigOptions, Z as BrowserInstanceOption, _ as BrowserModuleMocker, $ as BrowserOrchestrator, a0 as BrowserProvider, a1 as BrowserProviderInitializationOptions, a2 as BrowserProviderModule, a3 as BrowserProviderOptions, a4 as BrowserScript, a5 as BrowserServerState, a6 as BrowserServerStateSession, ad as BuiltinEnvironment, a7 as CDPSession, ae as CSSModuleScopeStrategy, aq as CoverageIstanbulOptions, ar as CoverageOptions, as as CoverageProvider, at as CoverageProviderModule, au as CoverageReporter, c as CoverageV8Options, av as CustomProviderOptions, af as DepsOptimizationOptions, ag as EnvironmentOptions, H as HTMLOptions, I as InlineConfig, q as JUnitOptions, J as JsonOptions, M as ModuleDiagnostic, O as OnServerRestartHandler, m as OnTestsRerunHandler, a8 as ParentProjectBrowser, ah as Pool, ai as PoolOptions, P as ProcessPool, a9 as ProjectBrowser, aj as ProjectConfig, b as ReportContext, ax as ReportedHookContext, ay as Reporter, al as ResolveSnapshotPathHandler, am as ResolveSnapshotPathHandlerContext, aa as ResolvedBrowserOptions, R as ResolvedCoverageOptions, ak as ResolvedProjectConfig, S as SerializedTestProject, r as TaskOptions, s as TestCase, t as TestCollection, u as TestDiagnostic, v as TestModule, w as TestModuleState, x as TestResult, y as TestResultFailed, z as TestResultPassed, B as TestResultSkipped, az as TestRunEndReason, aw as TestRunResult, G as TestSequencerConstructor, D as TestState, E as TestSuite, F as TestSuiteState, ab as ToMatchScreenshotComparators, ac as ToMatchScreenshotOptions, an as TypecheckConfig, U as UserWorkspaceConfig, ao as VitestEnvironment, n as VitestPackageInstaller, W as WatcherTriggerPattern, o as WorkspaceSpec, p as getFilePoolName } from './chunks/reporters.d.CqR9-CDJ.js';
|
|
8
|
+
import { R as RuntimeRPC } from './chunks/worker.d.D9QWnzAe.js';
|
|
9
|
+
export { T as TestExecutionType } from './chunks/worker.d.D9QWnzAe.js';
|
|
10
10
|
import { Writable } from 'node:stream';
|
|
11
|
-
export { V as VitestPluginContext } from './chunks/plugin.d.
|
|
12
|
-
export { W as WorkerContext } from './chunks/worker.d.
|
|
11
|
+
export { V as VitestPluginContext } from './chunks/plugin.d.DuiQJfUL.js';
|
|
12
|
+
export { W as WorkerContext } from './chunks/worker.d.Db-UVmXc.js';
|
|
13
13
|
import { Debugger } from 'debug';
|
|
14
|
-
import './chunks/global.d.
|
|
14
|
+
import './chunks/global.d.K6uBQHzY.js';
|
|
15
15
|
export { Task as RunnerTask, TaskResult as RunnerTaskResult, TaskResultPack as RunnerTaskResultPack, Test as RunnerTestCase, File as RunnerTestFile, Suite as RunnerTestSuite, SequenceHooks, SequenceSetupFiles } from '@vitest/runner';
|
|
16
|
-
export { b as RuntimeConfig } from './chunks/config.d.
|
|
16
|
+
export { b as RuntimeConfig } from './chunks/config.d.CKNVOKm0.js';
|
|
17
17
|
export { SerializedError } from '@vitest/utils';
|
|
18
18
|
export { generateFileHash } from '@vitest/runner/utils';
|
|
19
|
-
import './chunks/environment.d.
|
|
19
|
+
import './chunks/environment.d.2fYMoz3o.js';
|
|
20
20
|
import 'node:console';
|
|
21
|
-
import './chunks/browser.d.
|
|
21
|
+
import './chunks/browser.d.Cawq_X_N.js';
|
|
22
22
|
import '@vitest/mocker';
|
|
23
23
|
import '@vitest/utils/source-map';
|
|
24
24
|
import '@vitest/pretty-format';
|
|
25
25
|
import '@vitest/snapshot';
|
|
26
26
|
import '@vitest/utils/diff';
|
|
27
|
-
import 'vite-node';
|
|
28
27
|
import 'chai';
|
|
29
28
|
import 'vitest/optional-types.js';
|
|
30
29
|
import './chunks/benchmark.d.DAaHLpsq.js';
|
|
31
30
|
import 'tinybench';
|
|
32
|
-
import './chunks/coverage.d.
|
|
33
|
-
import 'vite-node/client';
|
|
31
|
+
import './chunks/coverage.d.BZtK59WP.js';
|
|
34
32
|
import '@vitest/snapshot/manager';
|
|
35
33
|
import 'node:fs';
|
|
34
|
+
import 'vite/module-runner';
|
|
36
35
|
import 'node:worker_threads';
|
|
37
36
|
import '@vitest/expect';
|
|
38
37
|
|
package/dist/node.js
CHANGED
|
@@ -1,28 +1,26 @@
|
|
|
1
1
|
import * as vite from 'vite';
|
|
2
2
|
import { resolveConfig as resolveConfig$1, mergeConfig } from 'vite';
|
|
3
3
|
export { esbuildVersion, isCSSRequest, isFileServingAllowed, parseAst, parseAstAsync, rollupVersion, version as viteVersion } from 'vite';
|
|
4
|
-
import { V as Vitest, a as VitestPlugin } from './chunks/cli-api.
|
|
5
|
-
export { G as GitNotFoundError, F as TestsNotFoundError, b as VitestPackageInstaller, e as createViteLogger, c as createVitest, i as isValidApiRequest, d as registerConsoleShortcuts, r as resolveFsAllow, s as startVitest } from './chunks/cli-api.
|
|
6
|
-
export { p as parseCLI } from './chunks/cac.
|
|
7
|
-
import { r as resolveConfig$2 } from './chunks/coverage.
|
|
8
|
-
export { b as BaseSequencer, c as createMethodsRPC, g as getFilePoolName, a as resolveApiServerConfig } from './chunks/coverage.
|
|
4
|
+
import { V as Vitest, a as VitestPlugin } from './chunks/cli-api.CZz3evYC.js';
|
|
5
|
+
export { G as GitNotFoundError, F as TestsNotFoundError, b as VitestPackageInstaller, e as createViteLogger, c as createVitest, i as isValidApiRequest, d as registerConsoleShortcuts, r as resolveFsAllow, s as startVitest } from './chunks/cli-api.CZz3evYC.js';
|
|
6
|
+
export { p as parseCLI } from './chunks/cac.WE-urWw5.js';
|
|
7
|
+
import { r as resolveConfig$2 } from './chunks/coverage.BPRS6xgn.js';
|
|
8
|
+
export { b as BaseSequencer, c as createMethodsRPC, g as getFilePoolName, a as resolveApiServerConfig } from './chunks/coverage.BPRS6xgn.js';
|
|
9
9
|
import { slash, deepClone } from '@vitest/utils';
|
|
10
10
|
import { f as findUp } from './chunks/index.X0nbfr6-.js';
|
|
11
11
|
import { resolve } from 'pathe';
|
|
12
|
-
import { c as configFiles } from './chunks/constants.
|
|
12
|
+
import { c as configFiles } from './chunks/constants.D_Q9UYh-.js';
|
|
13
13
|
export { distDir, rootDir } from './path.js';
|
|
14
14
|
import createDebug from 'debug';
|
|
15
15
|
export { generateFileHash } from '@vitest/runner/utils';
|
|
16
16
|
import 'node:fs';
|
|
17
|
-
import './chunks/coverage.
|
|
17
|
+
import './chunks/coverage.D_JHT54q.js';
|
|
18
18
|
import 'node:path';
|
|
19
19
|
import '@vitest/snapshot/manager';
|
|
20
|
-
import 'vite-node/client';
|
|
21
|
-
import 'vite-node/server';
|
|
22
20
|
import './chunks/index.Bgo3tNWt.js';
|
|
23
|
-
import './chunks/index.
|
|
21
|
+
import './chunks/index.VNI-1z5c.js';
|
|
24
22
|
import 'node:fs/promises';
|
|
25
|
-
import './chunks/typechecker.
|
|
23
|
+
import './chunks/typechecker.Cd1wvxUM.js';
|
|
26
24
|
import 'node:os';
|
|
27
25
|
import 'node:perf_hooks';
|
|
28
26
|
import '@vitest/utils/source-map';
|
|
@@ -46,14 +44,17 @@ import 'zlib';
|
|
|
46
44
|
import 'buffer';
|
|
47
45
|
import './chunks/_commonjsHelpers.BFTU3MAI.js';
|
|
48
46
|
import 'node:crypto';
|
|
47
|
+
import '#module-evaluator';
|
|
48
|
+
import 'vite/module-runner';
|
|
49
49
|
import 'node:url';
|
|
50
50
|
import 'picomatch';
|
|
51
51
|
import 'tinyglobby';
|
|
52
|
-
import '
|
|
52
|
+
import 'magic-string';
|
|
53
53
|
import '@vitest/mocker/node';
|
|
54
54
|
import './chunks/defaults.CXFFjsi8.js';
|
|
55
|
-
import '
|
|
56
|
-
import '
|
|
55
|
+
import './chunks/resolver.Bx6lE0iq.js';
|
|
56
|
+
import 'es-module-lexer';
|
|
57
|
+
import './chunks/index.7w0eqmYM.js';
|
|
57
58
|
import 'node:assert';
|
|
58
59
|
import '@vitest/utils/error';
|
|
59
60
|
import 'node:readline';
|
|
@@ -67,20 +68,14 @@ import 'readline';
|
|
|
67
68
|
|
|
68
69
|
// this is only exported as a public function and not used inside vitest
|
|
69
70
|
async function resolveConfig(options = {}, viteOverrides = {}) {
|
|
70
|
-
const root = slash(resolve(options.root || process.cwd()));
|
|
71
|
-
const configPath = options.config === false ? false : options.config ? resolve(root, options.config) : await findUp(configFiles, { cwd: root });
|
|
71
|
+
const root = slash(resolve(options.root || process.cwd())), configPath = options.config === false ? false : options.config ? resolve(root, options.config) : await findUp(configFiles, { cwd: root });
|
|
72
72
|
options.config = configPath;
|
|
73
|
-
const vitest = new Vitest("test", deepClone(options))
|
|
74
|
-
const config = await resolveConfig$1(mergeConfig({
|
|
73
|
+
const vitest = new Vitest("test", deepClone(options)), config = await resolveConfig$1(mergeConfig({
|
|
75
74
|
configFile: configPath,
|
|
76
75
|
mode: options.mode || "test",
|
|
77
76
|
plugins: [await VitestPlugin(options, vitest)]
|
|
78
|
-
}, mergeConfig(viteOverrides, { root: options.root })), "serve");
|
|
79
|
-
|
|
80
|
-
const updatedOptions = Reflect.get(config, "_vitest");
|
|
81
|
-
const vitestConfig = resolveConfig$2(vitest, updatedOptions, config);
|
|
82
|
-
await vitest.close();
|
|
83
|
-
return {
|
|
77
|
+
}, mergeConfig(viteOverrides, { root: options.root })), "serve"), updatedOptions = Reflect.get(config, "_vitest"), vitestConfig = resolveConfig$2(vitest, updatedOptions, config);
|
|
78
|
+
return await vitest.close(), {
|
|
84
79
|
viteConfig: config,
|
|
85
80
|
vitestConfig
|
|
86
81
|
};
|
package/dist/reporters.d.ts
CHANGED
|
@@ -1,25 +1,24 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { aN as BaseReporter, aO as BenchmarkBuiltinReporters, aA as BenchmarkReporter, aB as BenchmarkReportsMap, aP as BuiltinReporterOptions, aQ as BuiltinReporters, aC as DefaultReporter, aD as DotReporter, aE as GithubActionsReporter, aF as HangingProcessReporter, aH as JUnitReporter, aR as JsonAssertionResult, aG as JsonReporter, aS as JsonTestResult, aT as JsonTestResults, ax as ReportedHookContext, ay as Reporter, aI as ReportersMap, aJ as TapFlatReporter, aK as TapReporter, az as TestRunEndReason, aL as VerboseBenchmarkReporter, aM as VerboseReporter } from './chunks/reporters.d.CqR9-CDJ.js';
|
|
2
2
|
import '@vitest/runner';
|
|
3
|
-
import './chunks/environment.d.Bhm9oc0v.js';
|
|
4
3
|
import '@vitest/utils';
|
|
4
|
+
import './chunks/environment.d.2fYMoz3o.js';
|
|
5
5
|
import 'node:stream';
|
|
6
6
|
import 'vite';
|
|
7
7
|
import 'node:console';
|
|
8
|
-
import './chunks/browser.d.
|
|
9
|
-
import './chunks/worker.d.
|
|
10
|
-
import '
|
|
8
|
+
import './chunks/browser.d.Cawq_X_N.js';
|
|
9
|
+
import './chunks/worker.d.D9QWnzAe.js';
|
|
10
|
+
import 'vite/module-runner';
|
|
11
|
+
import './chunks/config.d.CKNVOKm0.js';
|
|
11
12
|
import '@vitest/pretty-format';
|
|
12
13
|
import '@vitest/snapshot';
|
|
13
14
|
import '@vitest/utils/diff';
|
|
14
15
|
import '@vitest/mocker';
|
|
15
16
|
import '@vitest/utils/source-map';
|
|
16
|
-
import 'vite-node';
|
|
17
17
|
import 'chai';
|
|
18
18
|
import 'vitest/optional-types.js';
|
|
19
19
|
import './chunks/benchmark.d.DAaHLpsq.js';
|
|
20
20
|
import '@vitest/runner/utils';
|
|
21
21
|
import 'tinybench';
|
|
22
|
-
import './chunks/coverage.d.
|
|
23
|
-
import 'vite-node/client';
|
|
22
|
+
import './chunks/coverage.d.BZtK59WP.js';
|
|
24
23
|
import '@vitest/snapshot/manager';
|
|
25
24
|
import 'node:fs';
|
package/dist/reporters.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
export { D as DefaultReporter, a as DotReporter, G as GithubActionsReporter, H as HangingProcessReporter, b as JUnitReporter, J as JsonReporter, R as ReportersMap, T as TapFlatReporter, c as TapReporter, V as VerboseReporter } from './chunks/index.
|
|
2
|
-
export { B as BenchmarkReporter, a as BenchmarkReportsMap, V as VerboseBenchmarkReporter } from './chunks/index.
|
|
1
|
+
export { D as DefaultReporter, a as DotReporter, G as GithubActionsReporter, H as HangingProcessReporter, b as JUnitReporter, J as JsonReporter, R as ReportersMap, T as TapFlatReporter, c as TapReporter, V as VerboseReporter } from './chunks/index.VNI-1z5c.js';
|
|
2
|
+
export { B as BenchmarkReporter, a as BenchmarkReportsMap, V as VerboseBenchmarkReporter } from './chunks/index.7w0eqmYM.js';
|
|
3
3
|
import 'node:fs';
|
|
4
4
|
import 'node:fs/promises';
|
|
5
5
|
import 'pathe';
|
|
6
|
-
import './chunks/typechecker.
|
|
6
|
+
import './chunks/typechecker.Cd1wvxUM.js';
|
|
7
7
|
import 'node:os';
|
|
8
8
|
import 'node:perf_hooks';
|
|
9
9
|
import '@vitest/utils/source-map';
|
package/dist/runners.d.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import * as tinybench from 'tinybench';
|
|
2
2
|
import { VitestRunner, VitestRunnerImportSource, Suite, File, Task, CancelReason, Test, TestContext, ImportDuration } from '@vitest/runner';
|
|
3
3
|
export { VitestRunner } from '@vitest/runner';
|
|
4
|
-
import { a as SerializedConfig } from './chunks/config.d.
|
|
4
|
+
import { a as SerializedConfig } from './chunks/config.d.CKNVOKm0.js';
|
|
5
5
|
import '@vitest/pretty-format';
|
|
6
6
|
import '@vitest/snapshot';
|
|
7
7
|
import '@vitest/utils/diff';
|
|
8
8
|
|
|
9
9
|
declare class NodeBenchmarkRunner implements VitestRunner {
|
|
10
10
|
config: SerializedConfig;
|
|
11
|
-
private
|
|
11
|
+
private moduleRunner;
|
|
12
12
|
constructor(config: SerializedConfig);
|
|
13
13
|
importTinybench(): Promise<typeof tinybench>;
|
|
14
14
|
importFile(filepath: string, source: VitestRunnerImportSource): unknown;
|
|
@@ -20,7 +20,7 @@ declare class VitestTestRunner implements VitestRunner {
|
|
|
20
20
|
config: SerializedConfig;
|
|
21
21
|
private snapshotClient;
|
|
22
22
|
private workerState;
|
|
23
|
-
private
|
|
23
|
+
private moduleRunner;
|
|
24
24
|
private cancelRun;
|
|
25
25
|
private assertionsErrors;
|
|
26
26
|
pool: string;
|
package/dist/runners.js
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import { updateTask } from '@vitest/runner';
|
|
2
2
|
import { createDefer, getSafeTimers } from '@vitest/utils';
|
|
3
|
-
import { a as getBenchOptions, g as getBenchFn } from './chunks/benchmark.
|
|
4
|
-
import { g as getWorkerState } from './chunks/utils.
|
|
3
|
+
import { a as getBenchOptions, g as getBenchFn } from './chunks/benchmark.UW6Ezvxy.js';
|
|
4
|
+
import { g as getWorkerState } from './chunks/utils.C7__0Iv5.js';
|
|
5
5
|
import { setState, GLOBAL_EXPECT, getState } from '@vitest/expect';
|
|
6
6
|
import { getTests, getNames, getTestName } from '@vitest/runner/utils';
|
|
7
7
|
import { processError } from '@vitest/utils/error';
|
|
8
8
|
import { normalize } from 'pathe';
|
|
9
|
-
import { g as getSnapshotClient, i as inject, c as createExpect, v as vi } from './chunks/vi.
|
|
10
|
-
import { r as rpc } from './chunks/rpc.
|
|
9
|
+
import { g as getSnapshotClient, i as inject, c as createExpect, v as vi } from './chunks/vi.BfdOiD4j.js';
|
|
10
|
+
import { r as rpc } from './chunks/rpc.RpPylpp0.js';
|
|
11
11
|
import 'chai';
|
|
12
12
|
import './chunks/_commonjsHelpers.BFTU3MAI.js';
|
|
13
13
|
import '@vitest/snapshot';
|
|
14
14
|
import '@vitest/spy';
|
|
15
15
|
import '@vitest/utils/source-map';
|
|
16
|
-
import './chunks/date.
|
|
16
|
+
import './chunks/date.-jtEtIeV.js';
|
|
17
17
|
import './chunks/index.Bgo3tNWt.js';
|
|
18
18
|
|
|
19
19
|
function createBenchmarkResult(name) {
|
|
@@ -26,10 +26,7 @@ function createBenchmarkResult(name) {
|
|
|
26
26
|
}
|
|
27
27
|
const benchmarkTasks = /* @__PURE__ */ new WeakMap();
|
|
28
28
|
async function runBenchmarkSuite(suite, runner) {
|
|
29
|
-
const { Task, Bench } = await runner.importTinybench();
|
|
30
|
-
const start = performance.now();
|
|
31
|
-
const benchmarkGroup = [];
|
|
32
|
-
const benchmarkSuiteGroup = [];
|
|
29
|
+
const { Task, Bench } = await runner.importTinybench(), start = performance.now(), benchmarkGroup = [], benchmarkSuiteGroup = [];
|
|
33
30
|
for (const task of suite.tasks) {
|
|
34
31
|
if (task.mode !== "run" && task.mode !== "queued") continue;
|
|
35
32
|
if (task.meta?.benchmark) benchmarkGroup.push(task);
|
|
@@ -43,62 +40,45 @@ async function runBenchmarkSuite(suite, runner) {
|
|
|
43
40
|
state: "run",
|
|
44
41
|
startTime: start,
|
|
45
42
|
benchmark: createBenchmarkResult(suite.name)
|
|
46
|
-
};
|
|
47
|
-
updateTask$1("suite-prepare", suite);
|
|
43
|
+
}, updateTask$1("suite-prepare", suite);
|
|
48
44
|
const addBenchTaskListener = (task, benchmark) => {
|
|
49
45
|
task.addEventListener("complete", (e) => {
|
|
50
|
-
const task = e.task;
|
|
51
|
-
|
|
52
|
-
const result = benchmark.result.benchmark;
|
|
53
|
-
benchmark.result.state = "pass";
|
|
54
|
-
Object.assign(result, taskRes);
|
|
46
|
+
const task = e.task, taskRes = task.result, result = benchmark.result.benchmark;
|
|
47
|
+
benchmark.result.state = "pass", Object.assign(result, taskRes);
|
|
55
48
|
// compute extra stats and free raw samples as early as possible
|
|
56
49
|
const samples = result.samples;
|
|
57
|
-
result.sampleCount = samples.length;
|
|
58
|
-
result.median = samples.length % 2 ? samples[Math.floor(samples.length / 2)] : (samples[samples.length / 2] + samples[samples.length / 2 - 1]) / 2;
|
|
59
|
-
if (!runner.config.benchmark?.includeSamples) result.samples.length = 0;
|
|
50
|
+
if (result.sampleCount = samples.length, result.median = samples.length % 2 ? samples[Math.floor(samples.length / 2)] : (samples[samples.length / 2] + samples[samples.length / 2 - 1]) / 2, !runner.config.benchmark?.includeSamples) result.samples.length = 0;
|
|
60
51
|
updateTask$1("test-finished", benchmark);
|
|
61
|
-
}, { once: true })
|
|
62
|
-
task.addEventListener("error", (e) => {
|
|
52
|
+
}, { once: true }), task.addEventListener("error", (e) => {
|
|
63
53
|
const task = e.task;
|
|
64
54
|
defer.reject(benchmark ? task.result.error : e);
|
|
65
55
|
}, { once: true });
|
|
66
56
|
};
|
|
67
57
|
benchmarkGroup.forEach((benchmark) => {
|
|
68
|
-
const options = getBenchOptions(benchmark);
|
|
69
|
-
const benchmarkInstance = new Bench(options);
|
|
70
|
-
const benchmarkFn = getBenchFn(benchmark);
|
|
58
|
+
const options = getBenchOptions(benchmark), benchmarkInstance = new Bench(options), benchmarkFn = getBenchFn(benchmark);
|
|
71
59
|
benchmark.result = {
|
|
72
60
|
state: "run",
|
|
73
61
|
startTime: start,
|
|
74
62
|
benchmark: createBenchmarkResult(benchmark.name)
|
|
75
63
|
};
|
|
76
64
|
const task = new Task(benchmarkInstance, benchmark.name, benchmarkFn);
|
|
77
|
-
benchmarkTasks.set(benchmark, task);
|
|
78
|
-
addBenchTaskListener(task, benchmark);
|
|
65
|
+
benchmarkTasks.set(benchmark, task), addBenchTaskListener(task, benchmark);
|
|
79
66
|
});
|
|
80
|
-
const { setTimeout } = getSafeTimers();
|
|
81
|
-
const tasks = [];
|
|
67
|
+
const { setTimeout } = getSafeTimers(), tasks = [];
|
|
82
68
|
for (const benchmark of benchmarkGroup) {
|
|
83
69
|
const task = benchmarkTasks.get(benchmark);
|
|
84
|
-
updateTask$1("test-prepare", benchmark)
|
|
85
|
-
await task.warmup();
|
|
86
|
-
tasks.push([await new Promise((resolve) => setTimeout(async () => {
|
|
70
|
+
updateTask$1("test-prepare", benchmark), await task.warmup(), tasks.push([await new Promise((resolve) => setTimeout(async () => {
|
|
87
71
|
resolve(await task.run());
|
|
88
72
|
})), benchmark]);
|
|
89
73
|
}
|
|
90
|
-
suite.result.duration = performance.now() - start;
|
|
91
|
-
suite.result.state = "pass";
|
|
92
|
-
updateTask$1("suite-finished", suite);
|
|
93
|
-
defer.resolve(null);
|
|
94
|
-
await defer;
|
|
74
|
+
suite.result.duration = performance.now() - start, suite.result.state = "pass", updateTask$1("suite-finished", suite), defer.resolve(null), await defer;
|
|
95
75
|
}
|
|
96
76
|
function updateTask$1(event, task) {
|
|
97
77
|
updateTask(event, task, runner);
|
|
98
78
|
}
|
|
99
79
|
}
|
|
100
80
|
class NodeBenchmarkRunner {
|
|
101
|
-
|
|
81
|
+
moduleRunner;
|
|
102
82
|
constructor(config) {
|
|
103
83
|
this.config = config;
|
|
104
84
|
}
|
|
@@ -106,8 +86,11 @@ class NodeBenchmarkRunner {
|
|
|
106
86
|
return await import('tinybench');
|
|
107
87
|
}
|
|
108
88
|
importFile(filepath, source) {
|
|
109
|
-
if (source === "setup")
|
|
110
|
-
|
|
89
|
+
if (source === "setup") {
|
|
90
|
+
const moduleNode = getWorkerState().evaluatedModules.getModuleById(filepath);
|
|
91
|
+
if (moduleNode) getWorkerState().evaluatedModules.invalidateModule(moduleNode);
|
|
92
|
+
}
|
|
93
|
+
return this.moduleRunner.import(filepath);
|
|
111
94
|
}
|
|
112
95
|
async runSuite(suite) {
|
|
113
96
|
await runBenchmarkSuite(suite, this);
|
|
@@ -123,7 +106,7 @@ const workerContext = Object.create(null);
|
|
|
123
106
|
class VitestTestRunner {
|
|
124
107
|
snapshotClient = getSnapshotClient();
|
|
125
108
|
workerState = getWorkerState();
|
|
126
|
-
|
|
109
|
+
moduleRunner;
|
|
127
110
|
cancelRun = false;
|
|
128
111
|
assertionsErrors = /* @__PURE__ */ new WeakMap();
|
|
129
112
|
pool = this.workerState.ctx.pool;
|
|
@@ -131,8 +114,11 @@ class VitestTestRunner {
|
|
|
131
114
|
this.config = config;
|
|
132
115
|
}
|
|
133
116
|
importFile(filepath, source) {
|
|
134
|
-
if (source === "setup")
|
|
135
|
-
|
|
117
|
+
if (source === "setup") {
|
|
118
|
+
const moduleNode = this.workerState.evaluatedModules.getModuleById(filepath);
|
|
119
|
+
if (moduleNode) this.workerState.evaluatedModules.invalidateModule(moduleNode);
|
|
120
|
+
}
|
|
121
|
+
return this.moduleRunner.import(filepath);
|
|
136
122
|
}
|
|
137
123
|
onCollectStart(file) {
|
|
138
124
|
this.workerState.current = file;
|
|
@@ -141,8 +127,7 @@ class VitestTestRunner {
|
|
|
141
127
|
this.workerState.onCleanup(listener);
|
|
142
128
|
}
|
|
143
129
|
onAfterRunFiles() {
|
|
144
|
-
this.snapshotClient.clear();
|
|
145
|
-
this.workerState.current = void 0;
|
|
130
|
+
this.snapshotClient.clear(), this.workerState.current = void 0;
|
|
146
131
|
}
|
|
147
132
|
getWorkerContext() {
|
|
148
133
|
return workerContext;
|
|
@@ -159,9 +144,7 @@ class VitestTestRunner {
|
|
|
159
144
|
if (this.workerState.config.snapshotOptions.updateSnapshot === "none" && result.unchecked) {
|
|
160
145
|
let message = `Obsolete snapshots found when no snapshot update is expected.\n`;
|
|
161
146
|
for (const key of result.uncheckedKeys) message += `· ${key}\n`;
|
|
162
|
-
suite.result.errors ??= [];
|
|
163
|
-
suite.result.errors.push(processError(new Error(message)));
|
|
164
|
-
suite.result.state = "fail";
|
|
147
|
+
suite.result.errors ??= [], suite.result.errors.push(processError(new Error(message))), suite.result.state = "fail";
|
|
165
148
|
}
|
|
166
149
|
await rpc().snapshotSaved(result);
|
|
167
150
|
}
|
|
@@ -181,8 +164,7 @@ class VitestTestRunner {
|
|
|
181
164
|
}
|
|
182
165
|
async onBeforeRunTask(test) {
|
|
183
166
|
if (this.cancelRun) test.mode = "skip";
|
|
184
|
-
|
|
185
|
-
this.workerState.current = test;
|
|
167
|
+
test.mode !== "run" && test.mode !== "queued" || (this.workerState.current = test);
|
|
186
168
|
}
|
|
187
169
|
async onBeforeRunSuite(suite) {
|
|
188
170
|
if (this.cancelRun) suite.mode = "skip";
|
|
@@ -191,9 +173,7 @@ class VitestTestRunner {
|
|
|
191
173
|
this.workerState.current = suite;
|
|
192
174
|
}
|
|
193
175
|
onBeforeTryTask(test) {
|
|
194
|
-
clearModuleMocks(this.config)
|
|
195
|
-
this.snapshotClient.clearTest(test.file.filepath, test.id);
|
|
196
|
-
setState({
|
|
176
|
+
clearModuleMocks(this.config), this.snapshotClient.clearTest(test.file.filepath, test.id), setState({
|
|
197
177
|
assertionCalls: 0,
|
|
198
178
|
isExpectingAssertions: false,
|
|
199
179
|
isExpectingAssertionsError: null,
|
|
@@ -213,14 +193,12 @@ class VitestTestRunner {
|
|
|
213
193
|
// create error during the test initialization so we have a nice stack trace
|
|
214
194
|
if (this.config.expect.requireAssertions) this.assertionsErrors.set(context.task, /* @__PURE__ */ new Error("expected any number of assertion, but got none"));
|
|
215
195
|
let _expect;
|
|
216
|
-
Object.defineProperty(context, "expect", { get() {
|
|
196
|
+
return Object.defineProperty(context, "expect", { get() {
|
|
217
197
|
if (!_expect) _expect = createExpect(context.task);
|
|
218
198
|
return _expect;
|
|
219
|
-
} })
|
|
220
|
-
Object.defineProperty(context, "_local", { get() {
|
|
199
|
+
} }), Object.defineProperty(context, "_local", { get() {
|
|
221
200
|
return _expect != null;
|
|
222
|
-
} });
|
|
223
|
-
return context;
|
|
201
|
+
} }), context;
|
|
224
202
|
}
|
|
225
203
|
getImportDurations() {
|
|
226
204
|
const entries = [...this.workerState.moduleExecutionInfo?.entries() ?? []];
|
package/dist/snapshot.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { VitestNodeSnapshotEnvironment as VitestSnapshotEnvironment } from './chunks/node.
|
|
1
|
+
export { VitestNodeSnapshotEnvironment as VitestSnapshotEnvironment } from './chunks/node.BOqcT2jW.js';
|
|
2
2
|
import '@vitest/snapshot/environment';
|
|
3
|
-
import './chunks/utils.
|
|
3
|
+
import './chunks/utils.C7__0Iv5.js';
|
|
4
4
|
import '@vitest/utils';
|
package/dist/suite.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { g as getBenchFn, a as getBenchOptions } from './chunks/benchmark.
|
|
1
|
+
export { g as getBenchFn, a as getBenchOptions } from './chunks/benchmark.UW6Ezvxy.js';
|
|
2
2
|
export { createTaskCollector, getCurrentSuite, getCurrentTest, getFn, getHooks, setFn, setHooks } from '@vitest/runner';
|
|
3
3
|
export { createChainable } from '@vitest/runner/utils';
|
|
4
4
|
import '@vitest/utils';
|
|
5
|
-
import './chunks/utils.
|
|
5
|
+
import './chunks/utils.C7__0Iv5.js';
|
package/dist/worker.js
CHANGED
|
@@ -1,50 +1,70 @@
|
|
|
1
1
|
import { pathToFileURL } from 'node:url';
|
|
2
2
|
import { createStackString, parseStacktrace } from '@vitest/utils/source-map';
|
|
3
3
|
import { workerId } from 'tinypool';
|
|
4
|
-
import {
|
|
4
|
+
import { ModuleRunner, EvaluatedModules } from 'vite/module-runner';
|
|
5
5
|
import { readFileSync } from 'node:fs';
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
6
|
+
import { isBuiltin } from 'node:module';
|
|
7
|
+
import { resolve } from 'pathe';
|
|
8
|
+
import { V as VitestTransport } from './chunks/moduleTransport.I-bgQy0S.js';
|
|
9
|
+
import { e as environments } from './chunks/index.BG0gqZH-.js';
|
|
10
|
+
import { s as setupInspect } from './chunks/inspector.CvQD-Nie.js';
|
|
11
|
+
import { c as createRuntimeRpc, a as rpcDone } from './chunks/rpc.RpPylpp0.js';
|
|
12
|
+
import { i as isChildProcess, s as setProcessTitle } from './chunks/utils.C7__0Iv5.js';
|
|
13
|
+
import { d as disposeInternalListeners } from './chunks/utils.C2YI6McM.js';
|
|
12
14
|
import 'node:console';
|
|
13
|
-
import 'node:module';
|
|
14
15
|
import '@vitest/utils';
|
|
15
16
|
import './chunks/index.Bgo3tNWt.js';
|
|
16
17
|
|
|
17
18
|
function isBuiltinEnvironment(env) {
|
|
18
19
|
return env in environments;
|
|
19
20
|
}
|
|
20
|
-
const _loaders = /* @__PURE__ */ new Map();
|
|
21
|
-
async function createEnvironmentLoader(
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
21
|
+
const isWindows = process.platform === "win32", _loaders = /* @__PURE__ */ new Map();
|
|
22
|
+
async function createEnvironmentLoader(root, rpc) {
|
|
23
|
+
const cachedLoader = _loaders.get(root);
|
|
24
|
+
if (!cachedLoader || cachedLoader.isClosed()) {
|
|
25
|
+
_loaders.delete(root);
|
|
26
|
+
const moduleRunner = new ModuleRunner({
|
|
27
|
+
hmr: false,
|
|
28
|
+
sourcemapInterceptor: "prepareStackTrace",
|
|
29
|
+
transport: new VitestTransport({
|
|
30
|
+
async fetchModule(id, importer, options) {
|
|
31
|
+
const result = await rpc.fetch(id, importer, "__vitest__", options);
|
|
32
|
+
if ("cached" in result) {
|
|
33
|
+
const code = readFileSync(result.tmp, "utf-8");
|
|
34
|
+
return {
|
|
35
|
+
code,
|
|
36
|
+
...result
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
if (isWindows && "externalize" in result)
|
|
40
|
+
// TODO: vitest returns paths for external modules, but Vite returns file://
|
|
41
|
+
// https://github.com/vitejs/vite/pull/20449
|
|
42
|
+
result.externalize = isBuiltin(id) || /^(?:node:|data:|http:|https:|file:)/.test(id) ? result.externalize : pathToFileURL(result.externalize).toString();
|
|
43
|
+
return result;
|
|
44
|
+
},
|
|
45
|
+
async resolveId(id, importer) {
|
|
46
|
+
return rpc.resolve(id, importer, "__vitest__");
|
|
47
|
+
}
|
|
48
|
+
})
|
|
49
|
+
});
|
|
50
|
+
_loaders.set(root, moduleRunner), await moduleRunner.import("/@vite/env");
|
|
26
51
|
}
|
|
27
|
-
return _loaders.get(
|
|
52
|
+
return _loaders.get(root);
|
|
28
53
|
}
|
|
29
54
|
async function loadEnvironment(ctx, rpc) {
|
|
30
55
|
const name = ctx.environment.name;
|
|
31
|
-
if (isBuiltinEnvironment(name)) return environments[name];
|
|
32
|
-
const loader = await createEnvironmentLoader({
|
|
33
|
-
root: ctx.config.root,
|
|
34
|
-
fetchModule: async (id) => {
|
|
35
|
-
const result = await rpc.fetch(id, "ssr");
|
|
36
|
-
if (result.id) return { code: readFileSync(result.id, "utf-8") };
|
|
37
|
-
return result;
|
|
38
|
-
},
|
|
39
|
-
resolveId: (id, importer) => rpc.resolveId(id, importer, "ssr")
|
|
40
|
-
});
|
|
41
|
-
const root = loader.root;
|
|
42
|
-
const packageId = name[0] === "." || name[0] === "/" ? resolve(root, name) : (await rpc.resolveId(`vitest-environment-${name}`, void 0, "ssr"))?.id ?? resolve(root, name);
|
|
43
|
-
const pkg = await loader.executeId(normalize(packageId));
|
|
56
|
+
if (isBuiltinEnvironment(name)) return { environment: environments[name] };
|
|
57
|
+
const root = ctx.config.root, loader = await createEnvironmentLoader(root, rpc), packageId = name[0] === "." || name[0] === "/" ? resolve(root, name) : (await rpc.resolve(`vitest-environment-${name}`, void 0, "__vitest__"))?.id ?? resolve(root, name), pkg = await loader.import(packageId);
|
|
44
58
|
if (!pkg || !pkg.default || typeof pkg.default !== "object") throw new TypeError(`Environment "${name}" is not a valid environment. Path "${packageId}" should export default object with a "setup" or/and "setupVM" method.`);
|
|
45
59
|
const environment = pkg.default;
|
|
46
|
-
if (environment.transformMode !== "web" && environment.transformMode !== "ssr") throw new TypeError(`Environment "${name}" is not a valid environment. Path "${packageId}" should export default object with a "transformMode" method equal to "ssr" or "web".`);
|
|
47
|
-
|
|
60
|
+
if (environment.transformMode != null && environment.transformMode !== "web" && environment.transformMode !== "ssr") throw new TypeError(`Environment "${name}" is not a valid environment. Path "${packageId}" should export default object with a "transformMode" method equal to "ssr" or "web", received "${environment.transformMode}".`);
|
|
61
|
+
if (environment.transformMode)
|
|
62
|
+
// keep for backwards compat
|
|
63
|
+
console.warn(`The Vitest environment ${environment.name} defines the "transformMode". This options was deprecated in Vitest 4 and will be removed in the next major version. Please, use "viteEnvironment" instead.`), environment.viteEnvironment ??= environment.transformMode === "ssr" ? "ssr" : "client";
|
|
64
|
+
return {
|
|
65
|
+
environment,
|
|
66
|
+
loader
|
|
67
|
+
};
|
|
48
68
|
}
|
|
49
69
|
|
|
50
70
|
const listeners = /* @__PURE__ */ new Set();
|
|
@@ -65,18 +85,17 @@ if (isChildProcess()) {
|
|
|
65
85
|
process.exit();
|
|
66
86
|
});
|
|
67
87
|
}
|
|
88
|
+
const resolvingModules = /* @__PURE__ */ new Set();
|
|
68
89
|
// this is what every pool executes when running tests
|
|
69
90
|
async function execute(method, ctx) {
|
|
70
91
|
disposeInternalListeners();
|
|
71
|
-
const prepareStart = performance.now();
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
process.env.VITEST_POOL_ID = String(workerId);
|
|
92
|
+
const prepareStart = performance.now(), cleanups = [setupInspect(ctx)];
|
|
93
|
+
process.env.VITEST_WORKER_ID = String(ctx.workerId), process.env.VITEST_POOL_ID = String(workerId);
|
|
94
|
+
let environmentLoader;
|
|
75
95
|
try {
|
|
76
96
|
// worker is a filepath or URL to a file that exposes a default export with "getRpcOptions" and "runTests" methods
|
|
77
97
|
if (ctx.worker[0] === ".") throw new Error(`Path to the test runner cannot be relative, received "${ctx.worker}"`);
|
|
78
|
-
const file = ctx.worker.startsWith("file:") ? ctx.worker : pathToFileURL(ctx.worker).toString();
|
|
79
|
-
const testRunnerModule = await import(file);
|
|
98
|
+
const file = ctx.worker.startsWith("file:") ? ctx.worker : pathToFileURL(ctx.worker).toString(), testRunnerModule = await import(file);
|
|
80
99
|
if (!testRunnerModule.default || typeof testRunnerModule.default !== "object") throw new TypeError(`Test worker object should be exposed as a default export. Received "${typeof testRunnerModule.default}"`);
|
|
81
100
|
const worker = testRunnerModule.default;
|
|
82
101
|
if (!worker.getRpcOptions || typeof worker.getRpcOptions !== "function") throw new TypeError(`Test worker should expose "getRpcOptions" method. Received "${typeof worker.getRpcOptions}".`);
|
|
@@ -88,12 +107,12 @@ async function execute(method, ctx) {
|
|
|
88
107
|
reject(/* @__PURE__ */ new Error(`[vitest-worker]: Closing rpc while "${method}" was pending`));
|
|
89
108
|
}));
|
|
90
109
|
});
|
|
91
|
-
const beforeEnvironmentTime = performance.now();
|
|
92
|
-
|
|
93
|
-
if (ctx.environment.transformMode) environment.transformMode = ctx.environment.transformMode;
|
|
110
|
+
const beforeEnvironmentTime = performance.now(), { environment, loader } = await loadEnvironment(ctx, rpc);
|
|
111
|
+
environmentLoader = loader;
|
|
94
112
|
const state = {
|
|
95
113
|
ctx,
|
|
96
|
-
|
|
114
|
+
evaluatedModules: new EvaluatedModules(),
|
|
115
|
+
resolvingModules,
|
|
97
116
|
moduleExecutionInfo: /* @__PURE__ */ new Map(),
|
|
98
117
|
config: ctx.config,
|
|
99
118
|
onCancel,
|
|
@@ -107,14 +126,13 @@ async function execute(method, ctx) {
|
|
|
107
126
|
providedContext: ctx.providedContext,
|
|
108
127
|
onFilterStackTrace(stack) {
|
|
109
128
|
return createStackString(parseStacktrace(stack));
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
|
|
129
|
+
},
|
|
130
|
+
metaEnv: createImportMetaEnvProxy()
|
|
131
|
+
}, methodName = method === "collect" ? "collectTests" : "runTests";
|
|
113
132
|
if (!worker[methodName] || typeof worker[methodName] !== "function") throw new TypeError(`Test worker should expose "runTests" method. Received "${typeof worker.runTests}".`);
|
|
114
133
|
await worker[methodName](state);
|
|
115
134
|
} finally {
|
|
116
|
-
await Promise.all(cleanups.map((fn) => fn()));
|
|
117
|
-
await rpcDone().catch(() => {});
|
|
135
|
+
await Promise.all(cleanups.map((fn) => fn())), await rpcDone().catch(() => {}), environmentLoader?.close();
|
|
118
136
|
}
|
|
119
137
|
}
|
|
120
138
|
function run(ctx) {
|
|
@@ -126,5 +144,24 @@ function collect(ctx) {
|
|
|
126
144
|
async function teardown() {
|
|
127
145
|
return cleanup();
|
|
128
146
|
}
|
|
147
|
+
function createImportMetaEnvProxy() {
|
|
148
|
+
// packages/vitest/src/node/plugins/index.ts:146
|
|
149
|
+
const booleanKeys = [
|
|
150
|
+
"DEV",
|
|
151
|
+
"PROD",
|
|
152
|
+
"SSR"
|
|
153
|
+
];
|
|
154
|
+
return new Proxy(process.env, {
|
|
155
|
+
get(_, key) {
|
|
156
|
+
return typeof key === "string" ? booleanKeys.includes(key) ? !!process.env[key] : process.env[key] : void 0;
|
|
157
|
+
},
|
|
158
|
+
set(_, key, value) {
|
|
159
|
+
if (typeof key !== "string") return true;
|
|
160
|
+
if (booleanKeys.includes(key)) process.env[key] = value ? "1" : "";
|
|
161
|
+
else process.env[key] = value;
|
|
162
|
+
return true;
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
}
|
|
129
166
|
|
|
130
167
|
export { collect, run, teardown };
|