Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/api/advanced/reporters.md
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
18 changes: 7 additions & 11 deletions docs/api/advanced/runner.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions docs/api/advanced/test-suite.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 }) => {
Expand Down
4 changes: 2 additions & 2 deletions docs/guide/advanced/reporters.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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() {
Expand Down
6 changes: 3 additions & 3 deletions docs/guide/environment.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <Environment>{
name: 'custom',
Expand Down Expand Up @@ -77,10 +77,10 @@ export default <Environment>{
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 }
```
Expand Down
4 changes: 2 additions & 2 deletions packages/browser/src/client/tester/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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'
Expand Down Expand Up @@ -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: () =>
Expand Down
2 changes: 1 addition & 1 deletion packages/browser/src/client/tester/snapshot.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
1 change: 0 additions & 1 deletion packages/browser/src/node/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
3 changes: 1 addition & 2 deletions packages/coverage-istanbul/src/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down
3 changes: 1 addition & 2 deletions packages/coverage-v8/src/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 1 addition & 2 deletions packages/ui/node/reporter.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
10 changes: 3 additions & 7 deletions packages/vitest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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",
Expand Down
5 changes: 2 additions & 3 deletions packages/vitest/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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',
Expand Down
2 changes: 2 additions & 0 deletions packages/vitest/src/public/coverage.ts
Original file line number Diff line number Diff line change
@@ -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.')
2 changes: 2 additions & 0 deletions packages/vitest/src/public/environments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.')
7 changes: 6 additions & 1 deletion packages/vitest/src/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -135,6 +137,9 @@ export type {
TestContext,
TestFunction,
TestOptions,

VitestRunnerConfig as TestRunnerConfig,
VitestRunner as VitestTestRunner,
} from '@vitest/runner'

export type { CancelReason } from '@vitest/runner'
Expand Down
1 change: 0 additions & 1 deletion packages/vitest/src/public/mocker.ts

This file was deleted.

14 changes: 0 additions & 14 deletions packages/vitest/src/public/module-runner.ts

This file was deleted.

34 changes: 29 additions & 5 deletions packages/vitest/src/public/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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'

Expand Down Expand Up @@ -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'

Expand Down
2 changes: 2 additions & 0 deletions packages/vitest/src/public/reporters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.')
4 changes: 3 additions & 1 deletion packages/vitest/src/public/runners.ts
Original file line number Diff line number Diff line change
@@ -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.')
44 changes: 44 additions & 0 deletions packages/vitest/src/public/runtime.ts
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions packages/vitest/src/public/snapshot.ts
Original file line number Diff line number Diff line change
@@ -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.')
Loading
Loading