From fd45928be3a24a0ee05751184736e3812c408181 Mon Sep 17 00:00:00 2001 From: Vladimir Date: Mon, 12 Jan 2026 14:24:46 +0100 Subject: [PATCH] fix: deprecate several vitest/* entry points (#9347) --- docs/api/advanced/reporters.md | 2 +- docs/api/advanced/runner.md | 18 +- docs/api/advanced/test-suite.md | 5 +- docs/guide/advanced/reporters.md | 4 +- docs/guide/environment.md | 6 +- packages/browser/src/client/tester/runner.ts | 4 +- .../browser/src/client/tester/snapshot.ts | 2 +- packages/browser/src/node/plugin.ts | 1 - packages/coverage-istanbul/src/provider.ts | 3 +- packages/coverage-v8/src/provider.ts | 3 +- packages/ui/node/reporter.ts | 3 +- packages/vitest/package.json | 10 +- packages/vitest/rollup.config.js | 5 +- 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/mocker.ts | 1 - packages/vitest/src/public/module-runner.ts | 14 - packages/vitest/src/public/node.ts | 34 +- packages/vitest/src/public/reporters.ts | 2 + packages/vitest/src/public/runners.ts | 4 +- packages/vitest/src/public/runtime.ts | 44 ++ 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 +- packages/web-worker/src/runner.ts | 14 +- test/browser/specs/runner.test.ts | 3 +- test/cli/custom.ts | 2 +- .../cli/fixtures/custom-runner/test-runner.ts | 6 +- test/cli/test/console.test.ts | 2 +- test/cli/test/expect-soft.test.ts | 5 +- test/core/test/cli-test.test.ts | 2 +- test/core/test/custom.test.ts | 6 +- test/core/test/exports.test.ts | 506 ++++++------------ test/core/test/task-collector.test.ts | 9 +- test/core/vitest-environment-custom/index.ts | 2 +- .../test/threshold-auto-update.unit.test.ts | 2 +- test/coverage-test/utils.ts | 5 +- test/reporters/tests/console.test.ts | 4 +- test/reporters/tests/default.test.ts | 2 +- test/reporters/tests/silent.test.ts | 2 +- .../snapshot-environment.ts | 2 +- test/test-utils/index.ts | 5 +- tsconfig.base.json | 1 - 45 files changed, 356 insertions(+), 440 deletions(-) delete mode 100644 packages/vitest/src/public/mocker.ts delete mode 100644 packages/vitest/src/public/module-runner.ts create mode 100644 packages/vitest/src/public/runtime.ts diff --git a/docs/api/advanced/reporters.md b/docs/api/advanced/reporters.md index 9060c9b8d..765ac6a69 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/api/advanced/runner.md b/docs/api/advanced/runner.md index 4b7d3fd49..acbf384b7 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 db2f98e71..88260d311 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/docs/guide/advanced/reporters.md b/docs/guide/advanced/reporters.md index 8fd9c4a1b..704d6dc5a 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 a5759f16f..eb7eaabde 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/runner.ts b/packages/browser/src/client/tester/runner.ts index cd780b05a..767555fbf 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/client/tester/snapshot.ts b/packages/browser/src/client/tester/snapshot.ts index b3209197f..5cc7a8130 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/browser/src/node/plugin.ts b/packages/browser/src/node/plugin.ts index 29baa6592..0b23b6dd4 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/coverage-istanbul/src/provider.ts b/packages/coverage-istanbul/src/provider.ts index 4fdef9629..2934ee82e 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 2ba05c007..2d68e337c 100644 --- a/packages/coverage-v8/src/provider.ts +++ b/packages/coverage-v8/src/provider.ts @@ -15,8 +15,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/ui/node/reporter.ts b/packages/ui/node/reporter.ts index dbc9275db..8ad956bc3 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/packages/vitest/package.json b/packages/vitest/package.json index 887454ae4..ab2d00166 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" @@ -101,9 +97,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 ce0da7b0c..60797b08e 100644 --- a/packages/vitest/rollup.config.js +++ b/packages/vitest/rollup.config.js @@ -25,12 +25,11 @@ 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', - '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 @@ -51,11 +50,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 916a865bd..50daddeee 100644 --- a/packages/vitest/src/public/coverage.ts +++ b/packages/vitest/src/public/coverage.ts @@ -1 +1,3 @@ export { BaseCoverageProvider } from '../node/coverage' + +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 06e168b9a..75cc6c75a 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' + +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 df2e69c9e..6ee9bdbda 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/mocker.ts b/packages/vitest/src/public/mocker.ts deleted file mode 100644 index f898a39ad..000000000 --- a/packages/vitest/src/public/mocker.ts +++ /dev/null @@ -1 +0,0 @@ -export * from '@vitest/mocker' diff --git a/packages/vitest/src/public/module-runner.ts b/packages/vitest/src/public/module-runner.ts deleted file mode 100644 index 841257fdb..000000000 --- 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/node.ts b/packages/vitest/src/public/node.ts index dae69dc67..01c04eed9 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' @@ -160,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' diff --git a/packages/vitest/src/public/reporters.ts b/packages/vitest/src/public/reporters.ts index b10c9791a..60d0eac90 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' + +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 8691e331e..b61bce3d4 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 { 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" instead.') diff --git a/packages/vitest/src/public/runtime.ts b/packages/vitest/src/public/runtime.ts new file mode 100644 index 000000000..19b12d540 --- /dev/null +++ b/packages/vitest/src/public/runtime.ts @@ -0,0 +1,44 @@ +// #region internal +import { VitestModuleEvaluator } from '../runtime/moduleRunner/moduleEvaluator' +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' +export type { + Environment, + EnvironmentReturn, + VmEnvironmentReturn, +} from '../types/environment' +export type { VitestRunner, VitestRunnerConfig } from '@vitest/runner' +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/vitest/src/public/snapshot.ts b/packages/vitest/src/public/snapshot.ts index 0e24c2ec0..2f438d931 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' + +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 9e65e3953..4f9afa44a 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' + +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 056e4fc8f..e3f5aca59 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 477173388..b0f52fe4c 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/packages/web-worker/src/runner.ts b/packages/web-worker/src/runner.ts index 42e0bf8c4..e847ec530 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/browser/specs/runner.test.ts b/test/browser/specs/runner.test.ts index 68c95a826..35e8c89e2 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 01323c1ed..dc8da0c75 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/fixtures/custom-runner/test-runner.ts b/test/cli/fixtures/custom-runner/test-runner.ts index 611671a26..b1d8ebdc3 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/console.test.ts b/test/cli/test/console.test.ts index f1fa11783..777ae4152 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/cli/test/expect-soft.test.ts b/test/cli/test/expect-soft.test.ts index 8dd750a50..493556216 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/cli-test.test.ts b/test/core/test/cli-test.test.ts index 94bf11ca8..90ac28d55 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/test/custom.test.ts b/test/core/test/custom.test.ts index ecc073672..28f08d2c5 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/exports.test.ts b/test/core/test/exports.test.ts index f26e9ff76..1097f0fd4 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,337 +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", - }, - "./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", - "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", - }, - "./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", - "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", + }, + } + `) }) diff --git a/test/core/test/task-collector.test.ts b/test/core/test/task-collector.test.ts index 01295139f..c44698ef4 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/core/vitest-environment-custom/index.ts b/test/core/vitest-environment-custom/index.ts index dbfdd1ac9..f03f22f92 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/coverage-test/test/threshold-auto-update.unit.test.ts b/test/coverage-test/test/threshold-auto-update.unit.test.ts index b27c4d511..95356bb2d 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 } diff --git a/test/coverage-test/utils.ts b/test/coverage-test/utils.ts index a5ae36319..203f6a7f6 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) { @@ -60,7 +59,7 @@ export async function runVitest(config: TestUserConfig, options = { throwOnError $viteConfig: viteOverrides, }) - if (getCurrentTest()) { + if (TestRunner.getCurrentTest()) { onTestFailed(() => { console.error('stderr:', result.stderr) console.error('stdout:', result.stdout) diff --git a/test/reporters/tests/console.test.ts b/test/reporters/tests/console.test.ts index b261daf2a..c58c52493 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 89f365f7e..cdb29912f 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 72a530802..1898a683a 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 1675ee939..f97d5e2a6 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) diff --git a/test/test-utils/index.ts b/test/test-utils/index.ts index b0ff7ce55..ae90c7de8 100644 --- a/test/test-utils/index.ts +++ b/test/test-utils/index.ts @@ -18,9 +18,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 @@ -197,7 +196,7 @@ export async function runVitest( exitCode = process.exitCode process.exitCode = 0 - if (getCurrentTest()) { + if (TestRunner.getCurrentTest()) { onTestFinished(async () => { await ctx?.close() process.exit = exit diff --git a/tsconfig.base.json b/tsconfig.base.json index 4e56cc8d9..08ceb3685 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/*"] -- 2.51.2