Skip to content

Commit fd45928

Browse files
authored
fix: deprecate several vitest/* entry points (#9347)
1 parent dd54e94 commit fd45928

File tree

45 files changed

+356
-440
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+356
-440
lines changed

docs/api/advanced/reporters.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Note that since test modules can run in parallel, Vitest will report them in par
3636
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:
3737

3838
```ts [custom-reporter.js]
39-
import { BaseReporter } from 'vitest/reporters'
39+
import { BaseReporter } from 'vitest/node'
4040

4141
export default class CustomReporter extends BaseReporter {
4242
onTestRunEnd(testModules, errors) {

docs/api/advanced/runner.md

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -106,14 +106,12 @@ export interface VitestRunner {
106106
When initiating this class, Vitest passes down Vitest config, - you should expose it as a `config` property:
107107

108108
```ts [runner.ts]
109-
import type { RunnerTestFile } from 'vitest'
110-
import type { VitestRunner, VitestRunnerConfig } from 'vitest/suite'
111-
import { VitestTestRunner } from 'vitest/runners'
109+
import type { RunnerTestFile, SerializedConfig, TestRunner, VitestTestRunner } from 'vitest'
112110

113-
class CustomRunner extends VitestTestRunner implements VitestRunner {
114-
public config: VitestRunnerConfig
111+
class CustomRunner extends TestRunner implements VitestTestRunner {
112+
public config: SerializedConfig
115113

116-
constructor(config: VitestRunnerConfig) {
114+
constructor(config: SerializedConfig) {
117115
this.config = config
118116
}
119117

@@ -281,17 +279,15 @@ Vitest exposes `createTaskCollector` utility to create your own `test` method. I
281279
A task is an object that is part of a suite. It is automatically added to the current suite with a `suite.task` method:
282280

283281
```js [custom.js]
284-
import { createTaskCollector, getCurrentSuite } from 'vitest/suite'
285-
286-
export { afterAll, beforeAll, describe } from 'vitest'
282+
export { afterAll, beforeAll, describe, TestRunner } from 'vitest'
287283

288284
// this function will be called during collection phase:
289285
// don't call function handler here, add it to suite tasks
290286
// with "getCurrentSuite().task()" method
291287
// note: createTaskCollector provides support for "todo"/"each"/...
292-
export const myCustomTask = createTaskCollector(
288+
export const myCustomTask = TestRunner.createTaskCollector(
293289
function (name, fn, timeout) {
294-
getCurrentSuite().task(name, {
290+
TestRunner.getCurrentSuite().task(name, {
295291
...this, // so "todo"/"skip"/... is tracked correctly
296292
meta: {
297293
customPropertyToDifferentiateTask: true

docs/api/advanced/test-suite.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,12 +200,11 @@ function meta(): TaskMeta
200200
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:
201201

202202
```ts {7,12}
203-
import { test } from 'vitest'
204-
import { getCurrentSuite } from 'vitest/suite'
203+
import { describe, test, TestRunner } from 'vitest'
205204
206205
describe('the validation works correctly', () => {
207206
// assign "decorated" during collection
208-
const { suite } = getCurrentSuite()
207+
const { suite } = TestRunner.getCurrentSuite()
209208
suite!.meta.decorated = true
210209
211210
test('some test', ({ task }) => {

docs/guide/advanced/reporters.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ You can import reporters from `vitest/reporters` and extend them to create your
1111
In general, you don't need to create your reporter from scratch. `vitest` comes with several default reporting programs that you can extend.
1212

1313
```ts
14-
import { DefaultReporter } from 'vitest/reporters'
14+
import { DefaultReporter } from 'vitest/node'
1515

1616
export default class MyDefaultReporter extends DefaultReporter {
1717
// do something
@@ -23,7 +23,7 @@ Of course, you can create your reporter from scratch. Just extend the `BaseRepor
2323
And here is an example of a custom reporter:
2424

2525
```ts [custom-reporter.js]
26-
import { BaseReporter } from 'vitest/reporters'
26+
import { BaseReporter } from 'vitest/node'
2727

2828
export default class CustomReporter extends BaseReporter {
2929
onTestModuleCollected() {

docs/guide/environment.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ test('test', () => {
4444
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`:
4545

4646
```ts
47-
import type { Environment } from 'vitest/environments'
47+
import type { Environment } from 'vitest/runtime'
4848

4949
export default <Environment>{
5050
name: 'custom',
@@ -77,10 +77,10 @@ export default <Environment>{
7777
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.
7878
:::
7979

80-
You also have access to default Vitest environments through `vitest/environments` entry:
80+
You also have access to default Vitest environments through `vitest/runtime` entry:
8181

8282
```ts
83-
import { builtinEnvironments, populateGlobal } from 'vitest/environments'
83+
import { builtinEnvironments, populateGlobal } from 'vitest/runtime'
8484

8585
console.log(builtinEnvironments) // { jsdom, happy-dom, node, edge-runtime }
8686
```

packages/browser/src/client/tester/runner.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import type { VitestBrowserClientMocker } from './mocker'
1818
import type { CommandsManager } from './tester-utils'
1919
import { globalChannel, onCancel } from '@vitest/browser/client'
2020
import { getTestName } from '@vitest/runner/utils'
21+
import { BenchmarkRunner, TestRunner } from 'vitest'
2122
import { page, userEvent } from 'vitest/browser'
2223
import {
2324
DecodedMap,
@@ -26,7 +27,6 @@ import {
2627
loadSnapshotSerializers,
2728
takeCoverageInsideWorker,
2829
} from 'vitest/internal/browser'
29-
import { NodeBenchmarkRunner, VitestTestRunner } from 'vitest/runners'
3030
import { createStackString, parseStacktrace } from '../../../../utils/src/source-map'
3131
import { getBrowserState, getWorkerState, moduleRunner } from '../utils'
3232
import { rpc } from './rpc'
@@ -323,7 +323,7 @@ export async function initiateRunner(
323323
return cachedRunner
324324
}
325325
const runnerClass
326-
= config.mode === 'test' ? VitestTestRunner : NodeBenchmarkRunner
326+
= config.mode === 'test' ? TestRunner : BenchmarkRunner
327327

328328
const BrowserRunner = createBrowserRunner(runnerClass, mocker, state, {
329329
takeCoverage: () =>

packages/browser/src/client/tester/snapshot.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { VitestBrowserClient } from '@vitest/browser/client'
22
import type { ParsedStack } from 'vitest/internal/browser'
3-
import type { SnapshotEnvironment } from 'vitest/snapshot'
3+
import type { SnapshotEnvironment } from 'vitest/runtime'
44
import { DecodedMap, getOriginalPosition } from 'vitest/internal/browser'
55

66
export class VitestBrowserSnapshotEnvironment implements SnapshotEnvironment {

packages/browser/src/node/plugin.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,6 @@ export default (parentServer: ParentBrowserProject, base = '/'): Plugin[] => {
242242
'vitest',
243243
'vitest/browser',
244244
'vitest/internal/browser',
245-
'vitest/runners',
246245
'vite/module-runner',
247246
'@vitest/browser/utils',
248247
'@vitest/browser/context',

packages/coverage-istanbul/src/provider.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ import reports from 'istanbul-reports'
1515
import { parseModule } from 'magicast'
1616
import { createDebug } from 'obug'
1717
import c from 'tinyrainbow'
18-
import { BaseCoverageProvider } from 'vitest/coverage'
19-
import { isCSSRequest } from 'vitest/node'
18+
import { BaseCoverageProvider, isCSSRequest } from 'vitest/node'
2019
import { version } from '../package.json' with { type: 'json' }
2120
import { COVERAGE_STORE_KEY } from './constants'
2221

packages/coverage-v8/src/provider.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ import { createDebug } from 'obug'
1515
import { normalize } from 'pathe'
1616
import { provider } from 'std-env'
1717
import c from 'tinyrainbow'
18-
import { BaseCoverageProvider } from 'vitest/coverage'
19-
import { parseAstAsync } from 'vitest/node'
18+
import { BaseCoverageProvider, parseAstAsync } from 'vitest/node'
2019
import { version } from '../package.json' with { type: 'json' }
2120

2221
export interface ScriptCoverageWithOffset extends Profiler.ScriptCoverage {

0 commit comments

Comments
 (0)