From 2225ced76596a2e1a5058b16b5f8906982e88e24 Mon Sep 17 00:00:00 2001 From: Vladimir Sheremet Date: Fri, 26 Dec 2025 20:55:42 +0100 Subject: [PATCH 1/7] fix: deprecate several vitest/* entry points --- packages/coverage-istanbul/src/provider.ts | 3 +- packages/coverage-v8/src/provider.ts | 3 +- packages/vitest/package.json | 6 ++-- packages/vitest/rollup.config.js | 4 +-- packages/vitest/src/public/coverage.ts | 2 ++ packages/vitest/src/public/environments.ts | 2 ++ packages/vitest/src/public/mocker.ts | 1 - packages/vitest/src/public/node.ts | 29 +++++++++++++++++++ packages/vitest/src/public/reporters.ts | 2 ++ packages/vitest/src/public/runners.ts | 2 ++ packages/vitest/src/public/runtime.ts | 24 +++++++++++++++ packages/vitest/src/public/snapshot.ts | 2 ++ packages/vitest/src/public/suite.ts | 2 ++ .../test/threshold-auto-update.unit.test.ts | 2 +- 14 files changed, 73 insertions(+), 11 deletions(-) delete mode 100644 packages/vitest/src/public/mocker.ts create mode 100644 packages/vitest/src/public/runtime.ts diff --git a/packages/coverage-istanbul/src/provider.ts b/packages/coverage-istanbul/src/provider.ts index 4fdef96298d6..2934ee82e486 100644 --- a/packages/coverage-istanbul/src/provider.ts +++ b/packages/coverage-istanbul/src/provider.ts @@ -15,8 +15,7 @@ import reports from 'istanbul-reports' import { parseModule } from 'magicast' import { createDebug } from 'obug' import c from 'tinyrainbow' -import { BaseCoverageProvider } from 'vitest/coverage' -import { isCSSRequest } from 'vitest/node' +import { BaseCoverageProvider, isCSSRequest } from 'vitest/node' import { version } from '../package.json' with { type: 'json' } import { COVERAGE_STORE_KEY } from './constants' diff --git a/packages/coverage-v8/src/provider.ts b/packages/coverage-v8/src/provider.ts index b9a2c4cdc574..1d270f053f5a 100644 --- a/packages/coverage-v8/src/provider.ts +++ b/packages/coverage-v8/src/provider.ts @@ -16,8 +16,7 @@ import { createDebug } from 'obug' import { normalize } from 'pathe' import { provider } from 'std-env' import c from 'tinyrainbow' -import { BaseCoverageProvider } from 'vitest/coverage' -import { parseAstAsync } from 'vitest/node' +import { BaseCoverageProvider, parseAstAsync } from 'vitest/node' import { version } from '../package.json' with { type: 'json' } export interface ScriptCoverageWithOffset extends Profiler.ScriptCoverage { diff --git a/packages/vitest/package.json b/packages/vitest/package.json index 3dce38879a7c..e352648fede4 100644 --- a/packages/vitest/package.json +++ b/packages/vitest/package.json @@ -101,9 +101,9 @@ "types": "./dist/snapshot.d.ts", "default": "./dist/snapshot.js" }, - "./mocker": { - "types": "./dist/mocker.d.ts", - "default": "./dist/mocker.js" + "./runtime": { + "types": "./dist/runtime.d.ts", + "default": "./dist/runtime.js" }, "./worker": { "types": "./worker.d.ts", diff --git a/packages/vitest/rollup.config.js b/packages/vitest/rollup.config.js index ce0da7b0cabe..59f178a33680 100644 --- a/packages/vitest/rollup.config.js +++ b/packages/vitest/rollup.config.js @@ -25,8 +25,8 @@ const entries = { 'browser': 'src/public/browser.ts', 'runners': 'src/public/runners.ts', 'environments': 'src/public/environments.ts', - 'mocker': 'src/public/mocker.ts', 'spy': 'src/integrations/spy.ts', + 'runtime': 'src/public/runtime.ts', 'coverage': 'src/public/coverage.ts', 'reporters': 'src/public/reporters.ts', 'worker': 'src/public/worker.ts', @@ -51,11 +51,11 @@ const dtsEntries = { 'environments': 'src/public/environments.ts', 'browser': 'src/public/browser.ts', 'runners': 'src/public/runners.ts', + 'runtime': 'src/public/runtime.ts', 'suite': 'src/public/suite.ts', 'config': 'src/public/config.ts', 'coverage': 'src/public/coverage.ts', 'reporters': 'src/public/reporters.ts', - 'mocker': 'src/public/mocker.ts', 'snapshot': 'src/public/snapshot.ts', 'worker': 'src/public/worker.ts', 'module-evaluator': 'src/runtime/moduleRunner/moduleEvaluator.ts', diff --git a/packages/vitest/src/public/coverage.ts b/packages/vitest/src/public/coverage.ts index 916a865bd9b0..54a469e3c643 100644 --- a/packages/vitest/src/public/coverage.ts +++ b/packages/vitest/src/public/coverage.ts @@ -1 +1,3 @@ export { BaseCoverageProvider } from '../node/coverage' + +process.emitWarning('Importing from "vitest/coverage" is deprecated since Vitest 4.1. Please use "vitest/node" instead.', 'DeprecationWarning') diff --git a/packages/vitest/src/public/environments.ts b/packages/vitest/src/public/environments.ts index 06e168b9a460..589c58ce8336 100644 --- a/packages/vitest/src/public/environments.ts +++ b/packages/vitest/src/public/environments.ts @@ -5,3 +5,5 @@ export type { EnvironmentReturn, VmEnvironmentReturn, } from '../types/environment' + +process.emitWarning('Importing from "vitest/environments" is deprecated since Vitest 4.1. Please use "vitest/runtime" instead.', 'DeprecationWarning') diff --git a/packages/vitest/src/public/mocker.ts b/packages/vitest/src/public/mocker.ts deleted file mode 100644 index f898a39ad42c..000000000000 --- a/packages/vitest/src/public/mocker.ts +++ /dev/null @@ -1 +0,0 @@ -export * from '@vitest/mocker' diff --git a/packages/vitest/src/public/node.ts b/packages/vitest/src/public/node.ts index dae69dc672b6..4b75abfd0466 100644 --- a/packages/vitest/src/public/node.ts +++ b/packages/vitest/src/public/node.ts @@ -17,6 +17,7 @@ export type { Vitest, VitestOptions, } from '../node/core' +export { BaseCoverageProvider } from '../node/coverage' export { createVitest } from '../node/create' export { GitNotFoundError, FilesNotFoundError as TestsNotFoundError } from '../node/errors' export { VitestPackageInstaller } from '../node/packageInstaller' @@ -40,6 +41,34 @@ export { TypecheckPoolWorker } from '../node/pools/workers/typecheckWorker' export { VmForksPoolWorker } from '../node/pools/workers/vmForksWorker' export { VmThreadsPoolWorker } from '../node/pools/workers/vmThreadsWorker' export type { SerializedTestProject, TestProject } from '../node/project' + +export { + BenchmarkReporter, + BenchmarkReportsMap, + DefaultReporter, + DotReporter, + GithubActionsReporter, + HangingProcessReporter, + JsonReporter, + JUnitReporter, + ReportersMap, + TapFlatReporter, + TapReporter, + VerboseBenchmarkReporter, + VerboseReporter, +} from '../node/reporters' +export type { + BaseReporter, + BenchmarkBuiltinReporters, + BuiltinReporterOptions, + BuiltinReporters, + JsonAssertionResult, + JsonTestResult, + JsonTestResults, + ReportedHookContext, + Reporter, + TestRunEndReason, +} from '../node/reporters' export type { HTMLOptions } from '../node/reporters/html' export type { JsonOptions } from '../node/reporters/json' diff --git a/packages/vitest/src/public/reporters.ts b/packages/vitest/src/public/reporters.ts index b10c9791a9b3..c1154db18f30 100644 --- a/packages/vitest/src/public/reporters.ts +++ b/packages/vitest/src/public/reporters.ts @@ -25,3 +25,5 @@ export type { Reporter, TestRunEndReason, } from '../node/reporters' + +process.emitWarning('Importing from "vitest/reporters" is deprecated since Vitest 4.1. Please use "vitest/node" instead.', 'DeprecationWarning') diff --git a/packages/vitest/src/public/runners.ts b/packages/vitest/src/public/runners.ts index 8691e331e5de..9b1b808edf65 100644 --- a/packages/vitest/src/public/runners.ts +++ b/packages/vitest/src/public/runners.ts @@ -1,3 +1,5 @@ export { NodeBenchmarkRunner } from '../runtime/runners/benchmark' export { VitestTestRunner } from '../runtime/runners/test' export type { VitestRunner } from '@vitest/runner' + +process.emitWarning('Importing from "vitest/runners" is deprecated since Vitest 4.1. Please use "vitest/runtime" instead.', 'DeprecationWarning') diff --git a/packages/vitest/src/public/runtime.ts b/packages/vitest/src/public/runtime.ts new file mode 100644 index 000000000000..07ba4f980d3f --- /dev/null +++ b/packages/vitest/src/public/runtime.ts @@ -0,0 +1,24 @@ +export { environments as builtinEnvironments } from '../integrations/env/index' +export { populateGlobal } from '../integrations/env/utils' +export { VitestNodeSnapshotEnvironment as VitestSnapshotEnvironment } from '../integrations/snapshot/environments/node' +export { getBenchFn, getBenchOptions } from '../runtime/benchmark' +export { NodeBenchmarkRunner } from '../runtime/runners/benchmark' +export { VitestTestRunner } from '../runtime/runners/test' +export type { + Environment, + EnvironmentReturn, + VmEnvironmentReturn, +} from '../types/environment' +export type { VitestRunner } from '@vitest/runner' +export { + createTaskCollector, + getCurrentSuite, + getCurrentTest, + getFn, + getHooks, + setFn, + setHooks, +} from '@vitest/runner' +export type { VitestRunner, VitestRunnerConfig } from '@vitest/runner' +export { createChainable } from '@vitest/runner/utils' +export type { SnapshotEnvironment } from '@vitest/snapshot/environment' diff --git a/packages/vitest/src/public/snapshot.ts b/packages/vitest/src/public/snapshot.ts index 0e24c2ec0129..8a2b78262349 100644 --- a/packages/vitest/src/public/snapshot.ts +++ b/packages/vitest/src/public/snapshot.ts @@ -1,2 +1,4 @@ export { VitestNodeSnapshotEnvironment as VitestSnapshotEnvironment } from '../integrations/snapshot/environments/node' export type { SnapshotEnvironment } from '@vitest/snapshot/environment' + +process.emitWarning('Importing from "vitest/snapshot" is deprecated since Vitest 4.1. Please use "vitest/runtime" instead.', 'DeprecationWarning') diff --git a/packages/vitest/src/public/suite.ts b/packages/vitest/src/public/suite.ts index 9e65e3953446..39a3e5b4602a 100644 --- a/packages/vitest/src/public/suite.ts +++ b/packages/vitest/src/public/suite.ts @@ -10,3 +10,5 @@ export { } from '@vitest/runner' export type { VitestRunner, VitestRunnerConfig } from '@vitest/runner' export { createChainable } from '@vitest/runner/utils' + +process.emitWarning('Importing from "vitest/suite" is deprecated since Vitest 4.1. Please use "vitest/runtime" instead.', 'DeprecationWarning') diff --git a/test/coverage-test/test/threshold-auto-update.unit.test.ts b/test/coverage-test/test/threshold-auto-update.unit.test.ts index b27c4d511e3c..95356bb2da30 100644 --- a/test/coverage-test/test/threshold-auto-update.unit.test.ts +++ b/test/coverage-test/test/threshold-auto-update.unit.test.ts @@ -4,7 +4,7 @@ import { parseModule } from 'magicast' import { expect, test, vi } from 'vitest' import { defineConfig } from 'vitest/config' -import { BaseCoverageProvider } from 'vitest/coverage' +import { BaseCoverageProvider } from 'vitest/node' const initialThresholds = { lines: 1, branches: 2, functions: 3, statements: 4 } const coveredThresholds = { lines: 50, branches: 60, functions: 70, statements: 80 } From 6f8c015afd6d865ce688ee259b3e0d5f8100f475 Mon Sep 17 00:00:00 2001 From: Vladimir Sheremet Date: Fri, 26 Dec 2025 21:02:11 +0100 Subject: [PATCH 2/7] chore: remove duplicate --- packages/vitest/src/public/node.ts | 5 ----- 1 file changed, 5 deletions(-) diff --git a/packages/vitest/src/public/node.ts b/packages/vitest/src/public/node.ts index 4b75abfd0466..01c04eed95c4 100644 --- a/packages/vitest/src/public/node.ts +++ b/packages/vitest/src/public/node.ts @@ -189,11 +189,6 @@ export type { RunnerTestFile, RunnerTestSuite, } from './index' -export type { - ReportedHookContext, - Reporter, - TestRunEndReason, -} from './reporters' export { generateFileHash } from '@vitest/runner/utils' export type { SerializedError } from '@vitest/utils' From 93104161ffae1432911e6209768170db0b0392e7 Mon Sep 17 00:00:00 2001 From: Vladimir Sheremet Date: Fri, 26 Dec 2025 21:11:57 +0100 Subject: [PATCH 3/7] chore: remove internal/module-runner --- packages/vitest/package.json | 4 --- packages/vitest/rollup.config.js | 1 - packages/vitest/src/public/module-runner.ts | 14 --------- packages/vitest/src/public/runtime.ts | 35 ++++++++++++++++++++- packages/web-worker/src/runner.ts | 14 +++++---- test/core/test/exports.test.ts | 30 ------------------ tsconfig.base.json | 1 - 7 files changed, 42 insertions(+), 57 deletions(-) delete mode 100644 packages/vitest/src/public/module-runner.ts diff --git a/packages/vitest/package.json b/packages/vitest/package.json index e352648fede4..a940f06d9127 100644 --- a/packages/vitest/package.json +++ b/packages/vitest/package.json @@ -68,10 +68,6 @@ "types": "./dist/browser.d.ts", "default": "./dist/browser.js" }, - "./internal/module-runner": { - "types": "./dist/module-runner.d.ts", - "default": "./dist/module-runner.js" - }, "./runners": { "types": "./dist/runners.d.ts", "default": "./dist/runners.js" diff --git a/packages/vitest/rollup.config.js b/packages/vitest/rollup.config.js index 59f178a33680..60797b08e6ad 100644 --- a/packages/vitest/rollup.config.js +++ b/packages/vitest/rollup.config.js @@ -30,7 +30,6 @@ const entries = { 'coverage': 'src/public/coverage.ts', 'reporters': 'src/public/reporters.ts', 'worker': 'src/public/worker.ts', - 'module-runner': 'src/public/module-runner.ts', 'module-evaluator': 'src/runtime/moduleRunner/moduleEvaluator.ts', // for performance reasons we bundle them separately so we don't import everything at once diff --git a/packages/vitest/src/public/module-runner.ts b/packages/vitest/src/public/module-runner.ts deleted file mode 100644 index 841257fdb48f..000000000000 --- a/packages/vitest/src/public/module-runner.ts +++ /dev/null @@ -1,14 +0,0 @@ -export { - VitestModuleEvaluator, - type VitestModuleEvaluatorOptions, -} from '../runtime/moduleRunner/moduleEvaluator' -export { - VitestModuleRunner, - type VitestModuleRunnerOptions, -} from '../runtime/moduleRunner/moduleRunner' -export { - type ContextModuleRunnerOptions, - startVitestModuleRunner, - VITEST_VM_CONTEXT_SYMBOL, -} from '../runtime/moduleRunner/startModuleRunner' -export { getWorkerState } from '../runtime/utils' diff --git a/packages/vitest/src/public/runtime.ts b/packages/vitest/src/public/runtime.ts index 07ba4f980d3f..6bf8dcdfa2bb 100644 --- a/packages/vitest/src/public/runtime.ts +++ b/packages/vitest/src/public/runtime.ts @@ -1,3 +1,13 @@ +import { VitestModuleEvaluator } from '../runtime/moduleRunner/moduleEvaluator' +// #region internal +import { VitestModuleRunner } from '../runtime/moduleRunner/moduleRunner' +import { + startVitestModuleRunner, + VITEST_VM_CONTEXT_SYMBOL, +} from '../runtime/moduleRunner/startModuleRunner' +import { getWorkerState } from '../runtime/utils' +// #endregion + export { environments as builtinEnvironments } from '../integrations/env/index' export { populateGlobal } from '../integrations/env/utils' export { VitestNodeSnapshotEnvironment as VitestSnapshotEnvironment } from '../integrations/snapshot/environments/node' @@ -9,7 +19,6 @@ export type { EnvironmentReturn, VmEnvironmentReturn, } from '../types/environment' -export type { VitestRunner } from '@vitest/runner' export { createTaskCollector, getCurrentSuite, @@ -22,3 +31,27 @@ export { export type { VitestRunner, VitestRunnerConfig } from '@vitest/runner' export { createChainable } from '@vitest/runner/utils' export type { SnapshotEnvironment } from '@vitest/snapshot/environment' + +// #region internal +/** + * @internal + */ +export interface __TYPES { + VitestModuleRunner: VitestModuleRunner +} +/** + * @internal + */ +export const __INTERNAL: { + VitestModuleEvaluator: typeof VitestModuleEvaluator + startVitestModuleRunner: typeof startVitestModuleRunner + VITEST_VM_CONTEXT_SYMBOL: typeof VITEST_VM_CONTEXT_SYMBOL + getWorkerState: typeof getWorkerState +} = { + VitestModuleEvaluator, + VitestModuleRunner, + startVitestModuleRunner, + VITEST_VM_CONTEXT_SYMBOL, + getWorkerState, +} as any +// #endregion diff --git a/packages/web-worker/src/runner.ts b/packages/web-worker/src/runner.ts index 42e0bf8c45bf..e847ec530b2b 100644 --- a/packages/web-worker/src/runner.ts +++ b/packages/web-worker/src/runner.ts @@ -1,12 +1,14 @@ -import type { VitestModuleRunner } from 'vitest/internal/module-runner' -import { - getWorkerState, +import type { __TYPES } from 'vitest/runtime' +import { __INTERNAL } from 'vitest/runtime' + +const { + VitestModuleEvaluator, startVitestModuleRunner, VITEST_VM_CONTEXT_SYMBOL, - VitestModuleEvaluator, -} from 'vitest/internal/module-runner' + getWorkerState, +} = __INTERNAL -export function startWebWorkerModuleRunner(context: Record): VitestModuleRunner { +export function startWebWorkerModuleRunner(context: Record): __TYPES['VitestModuleRunner'] { const state = getWorkerState() const mocker = (globalThis as any).__vitest_mocker__ diff --git a/test/core/test/exports.test.ts b/test/core/test/exports.test.ts index f26e9ff76104..1ecefd5062db 100644 --- a/test/core/test/exports.test.ts +++ b/test/core/test/exports.test.ts @@ -81,21 +81,6 @@ it('exports snapshot', async ({ skip, task }) => { "stringify": "function", "takeCoverageInsideWorker": "function", }, - "./internal/module-runner": { - "VITEST_VM_CONTEXT_SYMBOL": "string", - "VitestModuleEvaluator": "function", - "VitestModuleRunner": "function", - "getWorkerState": "function", - "startVitestModuleRunner": "function", - }, - "./mocker": { - "AutomockedModule": "function", - "AutospiedModule": "function", - "ManualMockedModule": "function", - "MockerRegistry": "function", - "RedirectedModule": "function", - "mockObject": "function", - }, "./node": { "BaseRuntime": "function", "BaseSequencer": "function", @@ -250,21 +235,6 @@ it('exports snapshot', async ({ skip, task }) => { "stringify": "function", "takeCoverageInsideWorker": "function", }, - "./internal/module-runner": { - "VITEST_VM_CONTEXT_SYMBOL": "string", - "VitestModuleEvaluator": "function", - "VitestModuleRunner": "function", - "getWorkerState": "function", - "startVitestModuleRunner": "function", - }, - "./mocker": { - "AutomockedModule": "function", - "AutospiedModule": "function", - "ManualMockedModule": "function", - "MockerRegistry": "function", - "RedirectedModule": "function", - "mockObject": "function", - }, "./node": { "BaseSequencer": "function", "ForksPoolWorker": "function", diff --git a/tsconfig.base.json b/tsconfig.base.json index 4e56cc8d9f69..08ceb3685b0c 100644 --- a/tsconfig.base.json +++ b/tsconfig.base.json @@ -25,7 +25,6 @@ "~/*": ["./packages/ui/client/*"], "vitest": ["./packages/vitest/src/public/index.ts"], "vitest/internal/browser": ["./packages/vitest/src/public/browser.ts"], - "vitest/internal/module-runner": ["./packages/vitest/src/public/module-runner.ts"], "vitest/globals": ["./packages/vitest/globals.d.ts"], "vitest/browser": ["./packages/vitest/browser/context.d.ts"], "vitest/*": ["./packages/vitest/src/public/*"] From 82366a0f3b433403a6d9af542d0dc6c996083d42 Mon Sep 17 00:00:00 2001 From: Vladimir Sheremet Date: Sat, 27 Dec 2025 17:14:00 +0100 Subject: [PATCH 4/7] chore: move shared props to vitest exports --- docs/api/advanced/runner.md | 18 ++++------- docs/api/advanced/test-suite.md | 5 ++- packages/browser/src/client/tester/runner.ts | 4 +-- packages/browser/src/node/plugin.ts | 1 - packages/vitest/src/public/coverage.ts | 2 +- packages/vitest/src/public/environments.ts | 2 +- packages/vitest/src/public/index.ts | 7 +++- packages/vitest/src/public/reporters.ts | 2 +- packages/vitest/src/public/runners.ts | 4 +-- packages/vitest/src/public/runtime.ts | 15 +-------- packages/vitest/src/public/snapshot.ts | 2 +- packages/vitest/src/public/suite.ts | 2 +- packages/vitest/src/runtime/runners/index.ts | 4 +-- packages/vitest/src/runtime/runners/test.ts | 32 +++++++++++++++++-- .../cli/fixtures/custom-runner/test-runner.ts | 6 ++-- test/cli/test/expect-soft.test.ts | 5 ++- test/core/test/custom.test.ts | 6 ++-- test/core/test/task-collector.test.ts | 9 +++--- test/coverage-test/utils.ts | 5 ++- test/test-utils/index.ts | 5 ++- 20 files changed, 72 insertions(+), 64 deletions(-) diff --git a/docs/api/advanced/runner.md b/docs/api/advanced/runner.md index 4b7d3fd493c7..acbf384b7bb1 100644 --- a/docs/api/advanced/runner.md +++ b/docs/api/advanced/runner.md @@ -106,14 +106,12 @@ export interface VitestRunner { When initiating this class, Vitest passes down Vitest config, - you should expose it as a `config` property: ```ts [runner.ts] -import type { RunnerTestFile } from 'vitest' -import type { VitestRunner, VitestRunnerConfig } from 'vitest/suite' -import { VitestTestRunner } from 'vitest/runners' +import type { RunnerTestFile, SerializedConfig, TestRunner, VitestTestRunner } from 'vitest' -class CustomRunner extends VitestTestRunner implements VitestRunner { - public config: VitestRunnerConfig +class CustomRunner extends TestRunner implements VitestTestRunner { + public config: SerializedConfig - constructor(config: VitestRunnerConfig) { + constructor(config: SerializedConfig) { this.config = config } @@ -281,17 +279,15 @@ Vitest exposes `createTaskCollector` utility to create your own `test` method. I A task is an object that is part of a suite. It is automatically added to the current suite with a `suite.task` method: ```js [custom.js] -import { createTaskCollector, getCurrentSuite } from 'vitest/suite' - -export { afterAll, beforeAll, describe } from 'vitest' +export { afterAll, beforeAll, describe, TestRunner } from 'vitest' // this function will be called during collection phase: // don't call function handler here, add it to suite tasks // with "getCurrentSuite().task()" method // note: createTaskCollector provides support for "todo"/"each"/... -export const myCustomTask = createTaskCollector( +export const myCustomTask = TestRunner.createTaskCollector( function (name, fn, timeout) { - getCurrentSuite().task(name, { + TestRunner.getCurrentSuite().task(name, { ...this, // so "todo"/"skip"/... is tracked correctly meta: { customPropertyToDifferentiateTask: true diff --git a/docs/api/advanced/test-suite.md b/docs/api/advanced/test-suite.md index db2f98e71b72..88260d311cbd 100644 --- a/docs/api/advanced/test-suite.md +++ b/docs/api/advanced/test-suite.md @@ -200,12 +200,11 @@ function meta(): TaskMeta Custom [metadata](/api/advanced/metadata) that was attached to the suite during its execution or collection. The meta can be attached by assigning a property to the `suite.meta` object during a test run: ```ts {7,12} -import { test } from 'vitest' -import { getCurrentSuite } from 'vitest/suite' +import { describe, test, TestRunner } from 'vitest' describe('the validation works correctly', () => { // assign "decorated" during collection - const { suite } = getCurrentSuite() + const { suite } = TestRunner.getCurrentSuite() suite!.meta.decorated = true test('some test', ({ task }) => { diff --git a/packages/browser/src/client/tester/runner.ts b/packages/browser/src/client/tester/runner.ts index cd780b05a5ca..767555fbfb1b 100644 --- a/packages/browser/src/client/tester/runner.ts +++ b/packages/browser/src/client/tester/runner.ts @@ -18,6 +18,7 @@ import type { VitestBrowserClientMocker } from './mocker' import type { CommandsManager } from './tester-utils' import { globalChannel, onCancel } from '@vitest/browser/client' import { getTestName } from '@vitest/runner/utils' +import { BenchmarkRunner, TestRunner } from 'vitest' import { page, userEvent } from 'vitest/browser' import { DecodedMap, @@ -26,7 +27,6 @@ import { loadSnapshotSerializers, takeCoverageInsideWorker, } from 'vitest/internal/browser' -import { NodeBenchmarkRunner, VitestTestRunner } from 'vitest/runners' import { createStackString, parseStacktrace } from '../../../../utils/src/source-map' import { getBrowserState, getWorkerState, moduleRunner } from '../utils' import { rpc } from './rpc' @@ -323,7 +323,7 @@ export async function initiateRunner( return cachedRunner } const runnerClass - = config.mode === 'test' ? VitestTestRunner : NodeBenchmarkRunner + = config.mode === 'test' ? TestRunner : BenchmarkRunner const BrowserRunner = createBrowserRunner(runnerClass, mocker, state, { takeCoverage: () => diff --git a/packages/browser/src/node/plugin.ts b/packages/browser/src/node/plugin.ts index 29baa659239a..0b23b6dd4acd 100644 --- a/packages/browser/src/node/plugin.ts +++ b/packages/browser/src/node/plugin.ts @@ -242,7 +242,6 @@ export default (parentServer: ParentBrowserProject, base = '/'): Plugin[] => { 'vitest', 'vitest/browser', 'vitest/internal/browser', - 'vitest/runners', 'vite/module-runner', '@vitest/browser/utils', '@vitest/browser/context', diff --git a/packages/vitest/src/public/coverage.ts b/packages/vitest/src/public/coverage.ts index 54a469e3c643..50daddeeefac 100644 --- a/packages/vitest/src/public/coverage.ts +++ b/packages/vitest/src/public/coverage.ts @@ -1,3 +1,3 @@ export { BaseCoverageProvider } from '../node/coverage' -process.emitWarning('Importing from "vitest/coverage" is deprecated since Vitest 4.1. Please use "vitest/node" instead.', 'DeprecationWarning') +console.warn('Importing from "vitest/coverage" is deprecated since Vitest 4.1. Please use "vitest/node" instead.') diff --git a/packages/vitest/src/public/environments.ts b/packages/vitest/src/public/environments.ts index 589c58ce8336..75cc6c75a496 100644 --- a/packages/vitest/src/public/environments.ts +++ b/packages/vitest/src/public/environments.ts @@ -6,4 +6,4 @@ export type { VmEnvironmentReturn, } from '../types/environment' -process.emitWarning('Importing from "vitest/environments" is deprecated since Vitest 4.1. Please use "vitest/runtime" instead.', 'DeprecationWarning') +console.warn('Importing from "vitest/environments" is deprecated since Vitest 4.1. Please use "vitest/runtime" instead.') diff --git a/packages/vitest/src/public/index.ts b/packages/vitest/src/public/index.ts index df2e69c9e886..6ee9bdbdab38 100644 --- a/packages/vitest/src/public/index.ts +++ b/packages/vitest/src/public/index.ts @@ -42,6 +42,9 @@ export type { } from '../runtime/config' export { VitestEvaluatedModules as EvaluatedModules } from '../runtime/moduleRunner/evaluatedModules' + +export { NodeBenchmarkRunner as BenchmarkRunner } from '../runtime/runners/benchmark' +export { TestRunner } from '../runtime/runners/test' export type { BenchFactory, BenchFunction, @@ -59,7 +62,6 @@ export { expectTypeOf } from '../typecheck/expectTypeOf' export type { ExpectTypeOf } from '../typecheck/expectTypeOf' export type { BrowserTesterOptions } from '../types/browser' -// export type * as Experimental from '../types/experimental' export type { AfterSuiteRunMeta, LabelColor, @@ -135,6 +137,9 @@ export type { TestContext, TestFunction, TestOptions, + + VitestRunnerConfig as TestRunnerConfig, + VitestRunner as VitestTestRunner, } from '@vitest/runner' export type { CancelReason } from '@vitest/runner' diff --git a/packages/vitest/src/public/reporters.ts b/packages/vitest/src/public/reporters.ts index c1154db18f30..60d0eac90f75 100644 --- a/packages/vitest/src/public/reporters.ts +++ b/packages/vitest/src/public/reporters.ts @@ -26,4 +26,4 @@ export type { TestRunEndReason, } from '../node/reporters' -process.emitWarning('Importing from "vitest/reporters" is deprecated since Vitest 4.1. Please use "vitest/node" instead.', 'DeprecationWarning') +console.warn('Importing from "vitest/reporters" is deprecated since Vitest 4.1. Please use "vitest/node" instead.') diff --git a/packages/vitest/src/public/runners.ts b/packages/vitest/src/public/runners.ts index 9b1b808edf65..267aa89881e0 100644 --- a/packages/vitest/src/public/runners.ts +++ b/packages/vitest/src/public/runners.ts @@ -1,5 +1,5 @@ export { NodeBenchmarkRunner } from '../runtime/runners/benchmark' -export { VitestTestRunner } from '../runtime/runners/test' +export { TestRunner as VitestTestRunner } from '../runtime/runners/test' export type { VitestRunner } from '@vitest/runner' -process.emitWarning('Importing from "vitest/runners" is deprecated since Vitest 4.1. Please use "vitest/runtime" instead.', 'DeprecationWarning') +console.warn('Importing from "vitest/runners" is deprecated since Vitest 4.1. Please use "vitest/runtime" instead.') diff --git a/packages/vitest/src/public/runtime.ts b/packages/vitest/src/public/runtime.ts index 6bf8dcdfa2bb..19b12d540a54 100644 --- a/packages/vitest/src/public/runtime.ts +++ b/packages/vitest/src/public/runtime.ts @@ -1,5 +1,5 @@ -import { VitestModuleEvaluator } from '../runtime/moduleRunner/moduleEvaluator' // #region internal +import { VitestModuleEvaluator } from '../runtime/moduleRunner/moduleEvaluator' import { VitestModuleRunner } from '../runtime/moduleRunner/moduleRunner' import { startVitestModuleRunner, @@ -11,25 +11,12 @@ import { getWorkerState } from '../runtime/utils' export { environments as builtinEnvironments } from '../integrations/env/index' export { populateGlobal } from '../integrations/env/utils' export { VitestNodeSnapshotEnvironment as VitestSnapshotEnvironment } from '../integrations/snapshot/environments/node' -export { getBenchFn, getBenchOptions } from '../runtime/benchmark' -export { NodeBenchmarkRunner } from '../runtime/runners/benchmark' -export { VitestTestRunner } from '../runtime/runners/test' export type { Environment, EnvironmentReturn, VmEnvironmentReturn, } from '../types/environment' -export { - createTaskCollector, - getCurrentSuite, - getCurrentTest, - getFn, - getHooks, - setFn, - setHooks, -} from '@vitest/runner' export type { VitestRunner, VitestRunnerConfig } from '@vitest/runner' -export { createChainable } from '@vitest/runner/utils' export type { SnapshotEnvironment } from '@vitest/snapshot/environment' // #region internal diff --git a/packages/vitest/src/public/snapshot.ts b/packages/vitest/src/public/snapshot.ts index 8a2b78262349..2f438d93148d 100644 --- a/packages/vitest/src/public/snapshot.ts +++ b/packages/vitest/src/public/snapshot.ts @@ -1,4 +1,4 @@ export { VitestNodeSnapshotEnvironment as VitestSnapshotEnvironment } from '../integrations/snapshot/environments/node' export type { SnapshotEnvironment } from '@vitest/snapshot/environment' -process.emitWarning('Importing from "vitest/snapshot" is deprecated since Vitest 4.1. Please use "vitest/runtime" instead.', 'DeprecationWarning') +console.warn('Importing from "vitest/snapshot" is deprecated since Vitest 4.1. Please use "vitest/runtime" instead.') diff --git a/packages/vitest/src/public/suite.ts b/packages/vitest/src/public/suite.ts index 39a3e5b4602a..4f9afa44a2da 100644 --- a/packages/vitest/src/public/suite.ts +++ b/packages/vitest/src/public/suite.ts @@ -11,4 +11,4 @@ export { export type { VitestRunner, VitestRunnerConfig } from '@vitest/runner' export { createChainable } from '@vitest/runner/utils' -process.emitWarning('Importing from "vitest/suite" is deprecated since Vitest 4.1. Please use "vitest/runtime" instead.', 'DeprecationWarning') +console.warn('Importing from "vitest/suite" is deprecated since Vitest 4.1. Please use static methods of "TestRunner" from the "vitest" entry point instead: e.g., `TestRunner.getCurrentTest()`.') diff --git a/packages/vitest/src/runtime/runners/index.ts b/packages/vitest/src/runtime/runners/index.ts index 056e4fc8feaa..e3f5aca59e52 100644 --- a/packages/vitest/src/runtime/runners/index.ts +++ b/packages/vitest/src/runtime/runners/index.ts @@ -7,7 +7,7 @@ import { rpc } from '../rpc' import { loadDiffConfig, loadSnapshotSerializers } from '../setup-common' import { getWorkerState } from '../utils' import { NodeBenchmarkRunner } from './benchmark' -import { VitestTestRunner } from './test' +import { TestRunner } from './test' async function getTestRunnerConstructor( config: SerializedConfig, @@ -15,7 +15,7 @@ async function getTestRunnerConstructor( ): Promise { if (!config.runner) { return ( - config.mode === 'test' ? VitestTestRunner : NodeBenchmarkRunner + config.mode === 'test' ? TestRunner : NodeBenchmarkRunner ) as any as VitestRunnerConstructor } const mod = await moduleRunner.import(config.runner) diff --git a/packages/vitest/src/runtime/runners/test.ts b/packages/vitest/src/runtime/runners/test.ts index 477173388d03..b0f52fe4c7d1 100644 --- a/packages/vitest/src/runtime/runners/test.ts +++ b/packages/vitest/src/runtime/runners/test.ts @@ -8,27 +8,35 @@ import type { Task, Test, TestContext, - VitestRunner, VitestRunnerImportSource, + VitestRunner as VitestTestRunner, } from '@vitest/runner' import type { ModuleRunner } from 'vite/module-runner' import type { Traces } from '../../utils/traces' import type { SerializedConfig } from '../config' import { getState, GLOBAL_EXPECT, setState } from '@vitest/expect' -import { getNames, getTestName, getTests } from '@vitest/runner/utils' +import { + createTaskCollector, + getCurrentSuite, + getCurrentTest, + getFn, + getHooks, +} from '@vitest/runner' +import { createChainable, getNames, getTestName, getTests } from '@vitest/runner/utils' import { processError } from '@vitest/utils/error' import { normalize } from 'pathe' import { createExpect } from '../../integrations/chai/index' import { inject } from '../../integrations/inject' import { getSnapshotClient } from '../../integrations/snapshot/chai' import { vi } from '../../integrations/vi' +import { getBenchFn, getBenchOptions } from '../benchmark' import { rpc } from '../rpc' import { getWorkerState } from '../utils' // worker context is shared between all tests const workerContext = Object.create(null) -export class VitestTestRunner implements VitestRunner { +export class TestRunner implements VitestTestRunner { private snapshotClient = getSnapshotClient() private workerState = getWorkerState() private moduleRunner!: ModuleRunner @@ -250,6 +258,24 @@ export class VitestTestRunner implements VitestRunner { __setTraces(traces: Traces): void { this._otel = traces } + + static createTaskCollector: typeof createTaskCollector = createTaskCollector + static getCurrentSuite: typeof getCurrentSuite = getCurrentSuite + static getCurrentTest: typeof getCurrentTest = getCurrentTest + static createChainable: typeof createChainable = createChainable + static getSuiteHooks: typeof getHooks = getHooks + static getTestFn: typeof getFn = getFn + static setSuiteHooks: typeof getHooks = getHooks + static setTestFn: typeof getFn = getFn + + /** + * @deprecated + */ + static getBenchFn: typeof getBenchFn = getBenchFn + /** + * @deprecated + */ + static getBenchOptions: typeof getBenchOptions = getBenchOptions } function clearModuleMocks(config: SerializedConfig) { diff --git a/test/cli/fixtures/custom-runner/test-runner.ts b/test/cli/fixtures/custom-runner/test-runner.ts index 611671a26f2c..b1d8ebdc3c75 100644 --- a/test/cli/fixtures/custom-runner/test-runner.ts +++ b/test/cli/fixtures/custom-runner/test-runner.ts @@ -1,8 +1,8 @@ -import type { Suite, TestContext } from '@vitest/runner' -import { VitestTestRunner } from 'vitest/runners' +import type { TestContext } from '@vitest/runner' +import { TestRunner } from 'vitest' import { getSuiteNames } from './utils'; -class CustomTestRunner extends VitestTestRunner { +class CustomTestRunner extends TestRunner { extendTaskContext(context: TestContext) { super.extendTaskContext(context); (context as any).__suiteNames = getSuiteNames(context.task.suite) diff --git a/test/cli/test/expect-soft.test.ts b/test/cli/test/expect-soft.test.ts index 8dd750a50ac9..49355621686c 100644 --- a/test/cli/test/expect-soft.test.ts +++ b/test/cli/test/expect-soft.test.ts @@ -1,7 +1,6 @@ import type { TestUserConfig } from 'vitest/node' import { resolve } from 'node:path' -import { describe, expect, test } from 'vitest' -import { getCurrentTest } from 'vitest/suite' +import { describe, expect, test, TestRunner } from 'vitest' import { runVitest } from '../../test-utils' describe('expect.soft', () => { @@ -9,7 +8,7 @@ describe('expect.soft', () => { root: resolve('./fixtures/expect-soft'), include: ['expects/soft.test.ts'], setupFiles: [], - testNamePattern: getCurrentTest()?.name, + testNamePattern: TestRunner.getCurrentTest()?.name, testTimeout: 4000, ...config, }, ['soft']) diff --git a/test/core/test/custom.test.ts b/test/core/test/custom.test.ts index ecc07367258b..28f08d2c5e5b 100644 --- a/test/core/test/custom.test.ts +++ b/test/core/test/custom.test.ts @@ -6,13 +6,13 @@ import { describe, expect, test, + TestRunner, } from 'vitest' -import { createChainable, getCurrentSuite } from 'vitest/suite' import { Gardener } from '../src/custom/gardener.js' // this function will be called, when Vitest collects tasks -const myCustomTask = createChainable(['todo'], function (name: string, fn: () => void) { - getCurrentSuite().task(name, { +const myCustomTask = TestRunner.createChainable(['todo'], function (name: string, fn: () => void) { + TestRunner.getCurrentSuite().task(name, { ...this, meta: { customPropertyToDifferentiateTask: true, diff --git a/test/core/test/task-collector.test.ts b/test/core/test/task-collector.test.ts index 01295139ff0b..c44698ef4e89 100644 --- a/test/core/test/task-collector.test.ts +++ b/test/core/test/task-collector.test.ts @@ -1,10 +1,9 @@ import type { RunnerTestCase, RunnerTestSuite } from 'vitest' -import { assert, describe, expect, test, vi } from 'vitest' -import { createTaskCollector, getCurrentSuite } from 'vitest/suite' +import { assert, describe, expect, test, TestRunner, vi } from 'vitest' test('collector keeps the order of arguments', () => { const fn = vi.fn() - const collector = createTaskCollector(fn) + const collector = TestRunner.createTaskCollector(fn) const cb = vi.fn() const options = { timeout: 100 } @@ -28,7 +27,7 @@ test('collector keeps the order of arguments', () => { describe('collector.extend should preserve handler wrapping', () => { let flag = false - const flagTest = createTaskCollector(function ( + const flagTest = TestRunner.createTaskCollector(function ( this: object, name: string, fn: () => void, @@ -38,7 +37,7 @@ describe('collector.extend should preserve handler wrapping', () => { await fn() assert(flag) } - getCurrentSuite().task(name, { ...this, handler }) + TestRunner.getCurrentSuite().task(name, { ...this, handler }) }) const extendedTest = flagTest.extend({}) diff --git a/test/coverage-test/utils.ts b/test/coverage-test/utils.ts index 91e9d7cff4f2..644dbe6577d8 100644 --- a/test/coverage-test/utils.ts +++ b/test/coverage-test/utils.ts @@ -10,8 +10,7 @@ import { stripVTControlCharacters } from 'node:util' import { playwright } from '@vitest/browser-playwright' import libCoverage from 'istanbul-lib-coverage' import { normalize } from 'pathe' -import { onTestFailed, vi, describe as vitestDescribe, test as vitestTest } from 'vitest' -import { getCurrentTest } from 'vitest/suite' +import { onTestFailed, TestRunner, vi, describe as vitestDescribe, test as vitestTest } from 'vitest' import * as testUtils from '../test-utils' export function test(name: string, fn: TestFunction, skip = false) { @@ -63,7 +62,7 @@ export async function runVitest(config: TestUserConfig, options = { throwOnError }, }) - if (getCurrentTest()) { + if (TestRunner.getCurrentTest()) { onTestFailed(() => { console.error('stderr:', result.stderr) console.error('stdout:', result.stdout) diff --git a/test/test-utils/index.ts b/test/test-utils/index.ts index b24a22d02718..8667c6bb2181 100644 --- a/test/test-utils/index.ts +++ b/test/test-utils/index.ts @@ -19,9 +19,8 @@ import { inspect } from 'node:util' import { dirname, relative, resolve } from 'pathe' import { x } from 'tinyexec' import * as tinyrainbow from 'tinyrainbow' -import { afterEach, onTestFinished } from 'vitest' +import { afterEach, onTestFinished, TestRunner } from 'vitest' import { startVitest } from 'vitest/node' -import { getCurrentTest } from 'vitest/suite' import { Cli } from './cli' // override default colors to disable them in tests @@ -135,7 +134,7 @@ export async function runVitest( exitCode = process.exitCode process.exitCode = 0 - if (getCurrentTest()) { + if (TestRunner.getCurrentTest()) { onTestFinished(async () => { await ctx?.close() process.exit = exit From f789803535749a888be3549e3e07a116d523135c Mon Sep 17 00:00:00 2001 From: Vladimir Sheremet Date: Sat, 27 Dec 2025 21:08:11 +0100 Subject: [PATCH 5/7] test: update exports test --- test/core/test/exports.test.ts | 476 ++++++++++++--------------------- 1 file changed, 172 insertions(+), 304 deletions(-) diff --git a/test/core/test/exports.test.ts b/test/core/test/exports.test.ts index 1ecefd5062db..1097f0fd4a75 100644 --- a/test/core/test/exports.test.ts +++ b/test/core/test/exports.test.ts @@ -1,7 +1,6 @@ import { resolve } from 'node:path' import { expect, it } from 'vitest' import { getPackageExportsManifest } from 'vitest-package-exports' -import { rolldownVersion } from 'vitest/node' it('exports snapshot', async ({ skip, task }) => { skip(task.file.pool !== 'threads', 'run only once inside threads') @@ -14,307 +13,176 @@ it('exports snapshot', async ({ skip, task }) => { }, }) - if (rolldownVersion) { - expect(manifest.exports) - .toMatchInlineSnapshot(` - { - ".": { - "EvaluatedModules": "function", - "afterAll": "function", - "afterEach": "function", - "assert": "function", - "assertType": "function", - "beforeAll": "function", - "beforeEach": "function", - "bench": "function", - "chai": "object", - "createExpect": "function", - "describe": "function", - "expect": "function", - "expectTypeOf": "function", - "inject": "function", - "it": "function", - "onTestFailed": "function", - "onTestFinished": "function", - "recordArtifact": "function", - "should": "function", - "suite": "function", - "test": "function", - "vi": "object", - "vitest": "object", - }, - "./config": { - "configDefaults": "object", - "coverageConfigDefaults": "object", - "defaultBrowserPort": "number", - "defaultExclude": "object", - "defaultInclude": "object", - "defineConfig": "function", - "defineProject": "function", - "mergeConfig": "function", - }, - "./coverage": { - "BaseCoverageProvider": "function", - }, - "./environments": { - "builtinEnvironments": "object", - "populateGlobal": "function", - }, - "./internal/browser": { - "DecodedMap": "function", - "SpyModule": "object", - "__INTERNAL": "object", - "collectTests": "function", - "format": "function", - "getOriginalPosition": "function", - "getSafeTimers": "function", - "getType": "function", - "inspect": "function", - "loadDiffConfig": "function", - "loadSnapshotSerializers": "function", - "processError": "function", - "setSafeTimers": "function", - "setupCommonEnv": "function", - "startCoverageInsideWorker": "function", - "startTests": "function", - "stopCoverageInsideWorker": "function", - "stringify": "function", - "takeCoverageInsideWorker": "function", - }, - "./node": { - "BaseRuntime": "function", - "BaseSequencer": "function", - "ForksRuntime": "function", - "GitNotFoundError": "function", - "TestsNotFoundError": "function", - "ThreadsRuntime": "function", - "TypecheckRuntime": "function", - "VitestPackageInstaller": "function", - "VitestPlugin": "function", - "VmForksRuntime": "function", - "VmThreadsRuntime": "function", - "createDebugger": "function", - "createMethodsRPC": "function", - "createViteLogger": "function", - "createViteServer": "function", - "createVitest": "function", - "distDir": "string", - "esbuildVersion": "string", - "escapeTestName": "function", - "experimental_getRunnerTask": "function", - "generateFileHash": "function", - "getFilePoolName": "function", - "isCSSRequest": "function", - "isFileLoadingAllowed": "function", - "isFileServingAllowed": "function", - "isValidApiRequest": "function", - "parseAst": "function", - "parseAstAsync": "function", - "parseCLI": "function", - "registerConsoleShortcuts": "function", - "resolveApiServerConfig": "function", - "resolveConfig": "function", - "resolveFsAllow": "function", - "rolldownVersion": "string", - "rollupVersion": "string", - "rootDir": "string", - "startVitest": "function", - "version": "string", - "viteVersion": "string", - }, - "./reporters": { - "BenchmarkReporter": "function", - "BenchmarkReportsMap": "object", - "DefaultReporter": "function", - "DotReporter": "function", - "GithubActionsReporter": "function", - "HangingProcessReporter": "function", - "JUnitReporter": "function", - "JsonReporter": "function", - "ReportersMap": "object", - "TapFlatReporter": "function", - "TapReporter": "function", - "VerboseBenchmarkReporter": "function", - "VerboseReporter": "function", - }, - "./runners": { - "NodeBenchmarkRunner": "function", - "VitestTestRunner": "function", - }, - "./snapshot": { - "VitestSnapshotEnvironment": "function", - }, - "./suite": { - "createChainable": "function", - "createTaskCollector": "function", - "getBenchFn": "function", - "getBenchOptions": "function", - "getCurrentSuite": "function", - "getCurrentTest": "function", - "getFn": "function", - "getHooks": "function", - "setFn": "function", - "setHooks": "function", - }, - "./workers": { - "collectVitestWorkerTests": "function", - "provideWorkerState": "function", - "runBaseTests": "function", - "runVitestWorker": "function", - "runVmTests": "function", - }, - } - `) - } - else { - expect(manifest.exports) - .toMatchInlineSnapshot(` - { - ".": { - "EvaluatedModules": "function", - "afterAll": "function", - "afterEach": "function", - "assert": "function", - "assertType": "function", - "beforeAll": "function", - "beforeEach": "function", - "bench": "function", - "chai": "object", - "createExpect": "function", - "describe": "function", - "expect": "function", - "expectTypeOf": "function", - "inject": "function", - "it": "function", - "onTestFailed": "function", - "onTestFinished": "function", - "recordArtifact": "function", - "should": "function", - "suite": "function", - "test": "function", - "vi": "object", - "vitest": "object", - }, - "./config": { - "configDefaults": "object", - "coverageConfigDefaults": "object", - "defaultBrowserPort": "number", - "defaultExclude": "object", - "defaultInclude": "object", - "defineConfig": "function", - "defineProject": "function", - "mergeConfig": "function", - }, - "./coverage": { - "BaseCoverageProvider": "function", - }, - "./environments": { - "builtinEnvironments": "object", - "populateGlobal": "function", - }, - "./internal/browser": { - "DecodedMap": "function", - "SpyModule": "object", - "Traces": "function", - "__INTERNAL": "object", - "browserFormat": "function", - "collectTests": "function", - "format": "function", - "getOriginalPosition": "function", - "getSafeTimers": "function", - "getType": "function", - "inspect": "function", - "loadDiffConfig": "function", - "loadSnapshotSerializers": "function", - "processError": "function", - "setSafeTimers": "function", - "setupCommonEnv": "function", - "startCoverageInsideWorker": "function", - "startTests": "function", - "stopCoverageInsideWorker": "function", - "stringify": "function", - "takeCoverageInsideWorker": "function", - }, - "./node": { - "BaseSequencer": "function", - "ForksPoolWorker": "function", - "GitNotFoundError": "function", - "TestsNotFoundError": "function", - "ThreadsPoolWorker": "function", - "TypecheckPoolWorker": "function", - "VitestPackageInstaller": "function", - "VitestPlugin": "function", - "VmForksPoolWorker": "function", - "VmThreadsPoolWorker": "function", - "createDebugger": "function", - "createMethodsRPC": "function", - "createViteLogger": "function", - "createViteServer": "function", - "createVitest": "function", - "distDir": "string", - "esbuildVersion": "string", - "escapeTestName": "function", - "experimental_getRunnerTask": "function", - "generateFileHash": "function", - "getFilePoolName": "function", - "isCSSRequest": "function", - "isFileLoadingAllowed": "function", - "isFileServingAllowed": "function", - "isValidApiRequest": "function", - "parseAst": "function", - "parseAstAsync": "function", - "parseCLI": "function", - "registerConsoleShortcuts": "function", - "resolveApiServerConfig": "function", - "resolveConfig": "function", - "resolveFsAllow": "function", - "rolldownVersion": "undefined", - "rollupVersion": "string", - "rootDir": "string", - "startVitest": "function", - "version": "string", - "viteVersion": "string", - }, - "./reporters": { - "BenchmarkReporter": "function", - "BenchmarkReportsMap": "object", - "DefaultReporter": "function", - "DotReporter": "function", - "GithubActionsReporter": "function", - "HangingProcessReporter": "function", - "JUnitReporter": "function", - "JsonReporter": "function", - "ReportersMap": "object", - "TapFlatReporter": "function", - "TapReporter": "function", - "VerboseBenchmarkReporter": "function", - "VerboseReporter": "function", - }, - "./runners": { - "NodeBenchmarkRunner": "function", - "VitestTestRunner": "function", - }, - "./snapshot": { - "VitestSnapshotEnvironment": "function", - }, - "./suite": { - "createChainable": "function", - "createTaskCollector": "function", - "getBenchFn": "function", - "getBenchOptions": "function", - "getCurrentSuite": "function", - "getCurrentTest": "function", - "getFn": "function", - "getHooks": "function", - "setFn": "function", - "setHooks": "function", - }, - "./worker": { - "init": "function", - "runBaseTests": "function", - "setupEnvironment": "function", - }, - } - `) - } + manifest.exports['./node'].rolldownVersion = 'custom' + + expect(manifest.exports).toMatchInlineSnapshot(` + { + ".": { + "BenchmarkRunner": "function", + "EvaluatedModules": "function", + "TestRunner": "function", + "afterAll": "function", + "afterEach": "function", + "assert": "function", + "assertType": "function", + "beforeAll": "function", + "beforeEach": "function", + "bench": "function", + "chai": "object", + "createExpect": "function", + "describe": "function", + "expect": "function", + "expectTypeOf": "function", + "inject": "function", + "it": "function", + "onTestFailed": "function", + "onTestFinished": "function", + "recordArtifact": "function", + "should": "function", + "suite": "function", + "test": "function", + "vi": "object", + "vitest": "object", + }, + "./config": { + "configDefaults": "object", + "coverageConfigDefaults": "object", + "defaultBrowserPort": "number", + "defaultExclude": "object", + "defaultInclude": "object", + "defineConfig": "function", + "defineProject": "function", + "mergeConfig": "function", + }, + "./coverage": { + "BaseCoverageProvider": "function", + }, + "./environments": { + "builtinEnvironments": "object", + "populateGlobal": "function", + }, + "./internal/browser": { + "DecodedMap": "function", + "SpyModule": "object", + "Traces": "function", + "__INTERNAL": "object", + "browserFormat": "function", + "collectTests": "function", + "format": "function", + "getOriginalPosition": "function", + "getSafeTimers": "function", + "getType": "function", + "inspect": "function", + "loadDiffConfig": "function", + "loadSnapshotSerializers": "function", + "processError": "function", + "setSafeTimers": "function", + "setupCommonEnv": "function", + "startCoverageInsideWorker": "function", + "startTests": "function", + "stopCoverageInsideWorker": "function", + "stringify": "function", + "takeCoverageInsideWorker": "function", + }, + "./node": { + "BaseCoverageProvider": "function", + "BaseSequencer": "function", + "BenchmarkReporter": "function", + "BenchmarkReportsMap": "object", + "DefaultReporter": "function", + "DotReporter": "function", + "ForksPoolWorker": "function", + "GitNotFoundError": "function", + "GithubActionsReporter": "function", + "HangingProcessReporter": "function", + "JUnitReporter": "function", + "JsonReporter": "function", + "ReportersMap": "object", + "TapFlatReporter": "function", + "TapReporter": "function", + "TestsNotFoundError": "function", + "ThreadsPoolWorker": "function", + "TypecheckPoolWorker": "function", + "VerboseBenchmarkReporter": "function", + "VerboseReporter": "function", + "VitestPackageInstaller": "function", + "VitestPlugin": "function", + "VmForksPoolWorker": "function", + "VmThreadsPoolWorker": "function", + "createDebugger": "function", + "createMethodsRPC": "function", + "createViteLogger": "function", + "createViteServer": "function", + "createVitest": "function", + "distDir": "string", + "esbuildVersion": "string", + "escapeTestName": "function", + "experimental_getRunnerTask": "function", + "generateFileHash": "function", + "getFilePoolName": "function", + "isCSSRequest": "function", + "isFileLoadingAllowed": "function", + "isFileServingAllowed": "function", + "isValidApiRequest": "function", + "parseAst": "function", + "parseAstAsync": "function", + "parseCLI": "function", + "registerConsoleShortcuts": "function", + "resolveApiServerConfig": "function", + "resolveConfig": "function", + "resolveFsAllow": "function", + "rolldownVersion": "custom", + "rollupVersion": "string", + "rootDir": "string", + "startVitest": "function", + "version": "string", + "viteVersion": "string", + }, + "./reporters": { + "BenchmarkReporter": "function", + "BenchmarkReportsMap": "object", + "DefaultReporter": "function", + "DotReporter": "function", + "GithubActionsReporter": "function", + "HangingProcessReporter": "function", + "JUnitReporter": "function", + "JsonReporter": "function", + "ReportersMap": "object", + "TapFlatReporter": "function", + "TapReporter": "function", + "VerboseBenchmarkReporter": "function", + "VerboseReporter": "function", + }, + "./runners": { + "NodeBenchmarkRunner": "function", + "VitestTestRunner": "function", + }, + "./runtime": { + "VitestSnapshotEnvironment": "function", + "__INTERNAL": "object", + "builtinEnvironments": "object", + "populateGlobal": "function", + }, + "./snapshot": { + "VitestSnapshotEnvironment": "function", + }, + "./suite": { + "createChainable": "function", + "createTaskCollector": "function", + "getBenchFn": "function", + "getBenchOptions": "function", + "getCurrentSuite": "function", + "getCurrentTest": "function", + "getFn": "function", + "getHooks": "function", + "setFn": "function", + "setHooks": "function", + }, + "./worker": { + "init": "function", + "runBaseTests": "function", + "setupEnvironment": "function", + }, + } + `) }) From 36f2dc54cbc111e10e5470daa79e09a6897e27bf Mon Sep 17 00:00:00 2001 From: Vladimir Sheremet Date: Sat, 27 Dec 2025 21:17:32 +0100 Subject: [PATCH 6/7] test: update import --- docs/api/advanced/reporters.md | 2 +- docs/guide/advanced/reporters.md | 4 ++-- docs/guide/environment.md | 6 +++--- packages/browser/src/client/tester/snapshot.ts | 2 +- packages/ui/node/reporter.ts | 3 +-- test/browser/specs/runner.test.ts | 3 +-- test/cli/custom.ts | 2 +- test/cli/test/console.test.ts | 2 +- test/core/test/cli-test.test.ts | 2 +- test/core/vitest-environment-custom/index.ts | 2 +- test/reporters/tests/console.test.ts | 4 ++-- test/reporters/tests/default.test.ts | 2 +- test/reporters/tests/silent.test.ts | 2 +- .../custom-snapshot-environment/snapshot-environment.ts | 2 +- 14 files changed, 18 insertions(+), 20 deletions(-) diff --git a/docs/api/advanced/reporters.md b/docs/api/advanced/reporters.md index 9060c9b8dfc6..765ac6a69ba5 100644 --- a/docs/api/advanced/reporters.md +++ b/docs/api/advanced/reporters.md @@ -36,7 +36,7 @@ Note that since test modules can run in parallel, Vitest will report them in par This guide lists all supported reporter methods. However, don't forget that instead of creating your own reporter, you can [extend existing one](/guide/advanced/reporters) instead: ```ts [custom-reporter.js] -import { BaseReporter } from 'vitest/reporters' +import { BaseReporter } from 'vitest/node' export default class CustomReporter extends BaseReporter { onTestRunEnd(testModules, errors) { diff --git a/docs/guide/advanced/reporters.md b/docs/guide/advanced/reporters.md index 8fd9c4a1bb4e..704d6dc5a328 100644 --- a/docs/guide/advanced/reporters.md +++ b/docs/guide/advanced/reporters.md @@ -11,7 +11,7 @@ You can import reporters from `vitest/reporters` and extend them to create your In general, you don't need to create your reporter from scratch. `vitest` comes with several default reporting programs that you can extend. ```ts -import { DefaultReporter } from 'vitest/reporters' +import { DefaultReporter } from 'vitest/node' export default class MyDefaultReporter extends DefaultReporter { // do something @@ -23,7 +23,7 @@ Of course, you can create your reporter from scratch. Just extend the `BaseRepor And here is an example of a custom reporter: ```ts [custom-reporter.js] -import { BaseReporter } from 'vitest/reporters' +import { BaseReporter } from 'vitest/node' export default class CustomReporter extends BaseReporter { onTestModuleCollected() { diff --git a/docs/guide/environment.md b/docs/guide/environment.md index a5759f16f56a..eb7eaabde759 100644 --- a/docs/guide/environment.md +++ b/docs/guide/environment.md @@ -44,7 +44,7 @@ test('test', () => { You can create your own package to extend Vitest environment. To do so, create package with the name `vitest-environment-${name}` or specify a path to a valid JS/TS file. That package should export an object with the shape of `Environment`: ```ts -import type { Environment } from 'vitest/environments' +import type { Environment } from 'vitest/runtime' export default { name: 'custom', @@ -77,10 +77,10 @@ export default { Vitest requires `viteEnvironment` option on environment object (fallbacks to the Vitest environment name by default). It should be equal to `ssr`, `client` or any custom [Vite environment](https://vite.dev/guide/api-environment) name. This value determines which environment is used to process file. ::: -You also have access to default Vitest environments through `vitest/environments` entry: +You also have access to default Vitest environments through `vitest/runtime` entry: ```ts -import { builtinEnvironments, populateGlobal } from 'vitest/environments' +import { builtinEnvironments, populateGlobal } from 'vitest/runtime' console.log(builtinEnvironments) // { jsdom, happy-dom, node, edge-runtime } ``` diff --git a/packages/browser/src/client/tester/snapshot.ts b/packages/browser/src/client/tester/snapshot.ts index b3209197fdef..5cc7a8130109 100644 --- a/packages/browser/src/client/tester/snapshot.ts +++ b/packages/browser/src/client/tester/snapshot.ts @@ -1,6 +1,6 @@ import type { VitestBrowserClient } from '@vitest/browser/client' import type { ParsedStack } from 'vitest/internal/browser' -import type { SnapshotEnvironment } from 'vitest/snapshot' +import type { SnapshotEnvironment } from 'vitest/runtime' import { DecodedMap, getOriginalPosition } from 'vitest/internal/browser' export class VitestBrowserSnapshotEnvironment implements SnapshotEnvironment { diff --git a/packages/ui/node/reporter.ts b/packages/ui/node/reporter.ts index dbc9275db3d7..8ad956bc37b7 100644 --- a/packages/ui/node/reporter.ts +++ b/packages/ui/node/reporter.ts @@ -1,7 +1,6 @@ import type { Task, TestAttachment } from '@vitest/runner' import type { ModuleGraphData, RunnerTestFile, SerializedConfig } from 'vitest' -import type { HTMLOptions, Vitest } from 'vitest/node' -import type { Reporter } from 'vitest/reporters' +import type { HTMLOptions, Reporter, Vitest } from 'vitest/node' import crypto from 'node:crypto' import { promises as fs } from 'node:fs' import { readFile, writeFile } from 'node:fs/promises' diff --git a/test/browser/specs/runner.test.ts b/test/browser/specs/runner.test.ts index 68c95a8264ca..35e8c89e2c83 100644 --- a/test/browser/specs/runner.test.ts +++ b/test/browser/specs/runner.test.ts @@ -1,5 +1,4 @@ -import type { Vitest } from 'vitest/node' -import type { JsonTestResults } from 'vitest/reporters' +import type { JsonTestResults, Vitest } from 'vitest/node' import { readdirSync } from 'node:fs' import { readFile } from 'node:fs/promises' import { beforeAll, describe, expect, onTestFailed, test } from 'vitest' diff --git a/test/cli/custom.ts b/test/cli/custom.ts index 01323c1ed4f6..dc8da0c75c5e 100644 --- a/test/cli/custom.ts +++ b/test/cli/custom.ts @@ -1,4 +1,4 @@ -import type { Environment } from 'vitest/environments' +import type { Environment } from 'vitest/runtime' import vm from 'node:vm' import { createDebug } from 'obug' diff --git a/test/cli/test/console.test.ts b/test/cli/test/console.test.ts index f1fa11783acb..777ae4152f1e 100644 --- a/test/cli/test/console.test.ts +++ b/test/cli/test/console.test.ts @@ -1,6 +1,6 @@ import { relative, resolve } from 'pathe' import { expect, test } from 'vitest' -import { DefaultReporter } from 'vitest/reporters' +import { DefaultReporter } from 'vitest/node' import { runInlineTests, runVitest } from '../../test-utils' test('can run custom pools with Vitest', async () => { diff --git a/test/core/test/cli-test.test.ts b/test/core/test/cli-test.test.ts index 94bf11ca8ab2..90ac28d55edd 100644 --- a/test/core/test/cli-test.test.ts +++ b/test/core/test/cli-test.test.ts @@ -1,6 +1,6 @@ import { resolveConfig as viteResolveConfig } from 'vite' import { expect, test } from 'vitest' -import { ReportersMap } from 'vitest/reporters' +import { ReportersMap } from 'vitest/node' import { createCLI, parseCLI } from '../../../packages/vitest/src/node/cli/cac.js' import { resolveConfig } from '../../../packages/vitest/src/node/config/resolveConfig.js' diff --git a/test/core/vitest-environment-custom/index.ts b/test/core/vitest-environment-custom/index.ts index dbfdd1ac930d..f03f22f92de4 100644 --- a/test/core/vitest-environment-custom/index.ts +++ b/test/core/vitest-environment-custom/index.ts @@ -1,4 +1,4 @@ -import type { Environment } from 'vitest/environments' +import type { Environment } from 'vitest/runtime' import vm from 'node:vm' import { createDebug } from 'obug' diff --git a/test/reporters/tests/console.test.ts b/test/reporters/tests/console.test.ts index b261daf2a7cf..c58c52493d0e 100644 --- a/test/reporters/tests/console.test.ts +++ b/test/reporters/tests/console.test.ts @@ -1,8 +1,8 @@ import type { UserConsoleLog } from 'vitest' -import type { Reporter } from 'vitest/reporters' +import type { Reporter } from 'vitest/node' import { resolve } from 'pathe' import { expect, test } from 'vitest' -import { DefaultReporter } from 'vitest/reporters' +import { DefaultReporter } from 'vitest/node' import { runVitest } from '../../test-utils' class LogReporter extends DefaultReporter { diff --git a/test/reporters/tests/default.test.ts b/test/reporters/tests/default.test.ts index 89f365f7e66d..cdb29912f2fa 100644 --- a/test/reporters/tests/default.test.ts +++ b/test/reporters/tests/default.test.ts @@ -1,6 +1,6 @@ import type { RunnerTask } from 'vitest/node' import { describe, expect, test } from 'vitest' -import { DefaultReporter } from 'vitest/reporters' +import { DefaultReporter } from 'vitest/node' import { runVitest, runVitestCli, StableTestFileOrderSorter } from '../../test-utils' import { trimReporterOutput } from './utils' diff --git a/test/reporters/tests/silent.test.ts b/test/reporters/tests/silent.test.ts index 72a530802f44..1898a683a198 100644 --- a/test/reporters/tests/silent.test.ts +++ b/test/reporters/tests/silent.test.ts @@ -1,5 +1,5 @@ import { expect, test } from 'vitest' -import { DefaultReporter } from 'vitest/reporters' +import { DefaultReporter } from 'vitest/node' import { runVitest } from '../../test-utils' test('{ silent: true } hides all console logs', async () => { diff --git a/test/snapshots/test/fixtures/custom-snapshot-environment/snapshot-environment.ts b/test/snapshots/test/fixtures/custom-snapshot-environment/snapshot-environment.ts index 1675ee9395cf..f97d5e2a6c69 100644 --- a/test/snapshots/test/fixtures/custom-snapshot-environment/snapshot-environment.ts +++ b/test/snapshots/test/fixtures/custom-snapshot-environment/snapshot-environment.ts @@ -1,5 +1,5 @@ import { relative as _relative } from 'pathe' -import { VitestSnapshotEnvironment } from 'vitest/snapshot' +import { VitestSnapshotEnvironment } from 'vitest/runtime' function relative(file: string) { return _relative(process.cwd(), file) From d13c97493dcee1f668d3145f809d6113acbcbabf Mon Sep 17 00:00:00 2001 From: Vladimir Date: Sun, 4 Jan 2026 13:12:15 +0100 Subject: [PATCH 7/7] Update packages/vitest/src/public/runners.ts --- packages/vitest/src/public/runners.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/vitest/src/public/runners.ts b/packages/vitest/src/public/runners.ts index 267aa89881e0..b61bce3d4321 100644 --- a/packages/vitest/src/public/runners.ts +++ b/packages/vitest/src/public/runners.ts @@ -2,4 +2,4 @@ export { NodeBenchmarkRunner } from '../runtime/runners/benchmark' export { TestRunner as VitestTestRunner } from '../runtime/runners/test' export type { VitestRunner } from '@vitest/runner' -console.warn('Importing from "vitest/runners" is deprecated since Vitest 4.1. Please use "vitest/runtime" instead.') +console.warn('Importing from "vitest/runners" is deprecated since Vitest 4.1. Please use "vitest" instead.')