| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -36,7 +36,7 @@ Note that since test modules can run in parallel, Vitest will report them in par | |||
| 36 | 36 | 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: | |
| 37 | 37 | ||
| 38 | 38 | ```ts [custom-reporter.js] | |
| 39 | - import { BaseReporter } from 'vitest/reporters' | ||
| 39 | + import { BaseReporter } from 'vitest/node' | ||
| 40 | 40 | ||
| 41 | 41 | export default class CustomReporter extends BaseReporter { | |
| 42 | 42 | onTestRunEnd(testModules, errors) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -106,14 +106,12 @@ export interface VitestRunner { | |||
| 106 | 106 | When initiating this class, Vitest passes down Vitest config, - you should expose it as a `config` property: | |
| 107 | 107 | ||
| 108 | 108 | ```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' | ||
| 112 | 110 | ||
| 113 | - class CustomRunner extends VitestTestRunner implements VitestRunner { | ||
| 114 | - public config: VitestRunnerConfig | ||
| 111 | + class CustomRunner extends TestRunner implements VitestTestRunner { | ||
| 112 | + public config: SerializedConfig | ||
| 115 | 113 | ||
| 116 | - constructor(config: VitestRunnerConfig) { | ||
| 114 | + constructor(config: SerializedConfig) { | ||
| 117 | 115 | this.config = config | |
| 118 | 116 | } | |
| 119 | 117 | ||
@@ -281,17 +279,15 @@ Vitest exposes `createTaskCollector` utility to create your own `test` method. I | |||
| 281 | 279 | A task is an object that is part of a suite. It is automatically added to the current suite with a `suite.task` method: | |
| 282 | 280 | ||
| 283 | 281 | ```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' | ||
| 287 | 283 | ||
| 288 | 284 | // this function will be called during collection phase: | |
| 289 | 285 | // don't call function handler here, add it to suite tasks | |
| 290 | 286 | // with "getCurrentSuite().task()" method | |
| 291 | 287 | // note: createTaskCollector provides support for "todo"/"each"/... | |
| 292 | - export const myCustomTask = createTaskCollector( | ||
| 288 | + export const myCustomTask = TestRunner.createTaskCollector( | ||
| 293 | 289 | function (name, fn, timeout) { | |
| 294 | - getCurrentSuite().task(name, { | ||
| 290 | + TestRunner.getCurrentSuite().task(name, { | ||
| 295 | 291 | ...this, // so "todo"/"skip"/... is tracked correctly | |
| 296 | 292 | meta: { | |
| 297 | 293 | customPropertyToDifferentiateTask: true | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -200,12 +200,11 @@ function meta(): TaskMeta | |||
| 200 | 200 | 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: | |
| 201 | 201 | ||
| 202 | 202 | ```ts {7,12} | |
| 203 | - import { test } from 'vitest' | ||
| 204 | - import { getCurrentSuite } from 'vitest/suite' | ||
| 203 | + import { describe, test, TestRunner } from 'vitest' | ||
| 205 | 204 | ||
| 206 | 205 | describe('the validation works correctly', () => { | |
| 207 | 206 | // assign "decorated" during collection | |
| 208 | - const { suite } = getCurrentSuite() | ||
| 207 | + const { suite } = TestRunner.getCurrentSuite() | ||
| 209 | 208 | suite!.meta.decorated = true | |
| 210 | 209 | ||
| 211 | 210 | test('some test', ({ task }) => { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -11,7 +11,7 @@ You can import reporters from `vitest/reporters` and extend them to create your | |||
| 11 | 11 | In general, you don't need to create your reporter from scratch. `vitest` comes with several default reporting programs that you can extend. | |
| 12 | 12 | ||
| 13 | 13 | ```ts | |
| 14 | - import { DefaultReporter } from 'vitest/reporters' | ||
| 14 | + import { DefaultReporter } from 'vitest/node' | ||
| 15 | 15 | ||
| 16 | 16 | export default class MyDefaultReporter extends DefaultReporter { | |
| 17 | 17 | // do something | |
@@ -23,7 +23,7 @@ Of course, you can create your reporter from scratch. Just extend the `BaseRepor | |||
| 23 | 23 | And here is an example of a custom reporter: | |
| 24 | 24 | ||
| 25 | 25 | ```ts [custom-reporter.js] | |
| 26 | - import { BaseReporter } from 'vitest/reporters' | ||
| 26 | + import { BaseReporter } from 'vitest/node' | ||
| 27 | 27 | ||
| 28 | 28 | export default class CustomReporter extends BaseReporter { | |
| 29 | 29 | onTestModuleCollected() { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -44,7 +44,7 @@ test('test', () => { | |||
| 44 | 44 | 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`: | |
| 45 | 45 | ||
| 46 | 46 | ```ts | |
| 47 | - import type { Environment } from 'vitest/environments' | ||
| 47 | + import type { Environment } from 'vitest/runtime' | ||
| 48 | 48 | ||
| 49 | 49 | export default <Environment>{ | |
| 50 | 50 | name: 'custom', | |
@@ -77,10 +77,10 @@ export default <Environment>{ | |||
| 77 | 77 | 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. | |
| 78 | 78 | ::: | |
| 79 | 79 | ||
| 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: | ||
| 81 | 81 | ||
| 82 | 82 | ```ts | |
| 83 | - import { builtinEnvironments, populateGlobal } from 'vitest/environments' | ||
| 83 | + import { builtinEnvironments, populateGlobal } from 'vitest/runtime' | ||
| 84 | 84 | ||
| 85 | 85 | console.log(builtinEnvironments) // { jsdom, happy-dom, node, edge-runtime } | |
| 86 | 86 | ``` | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -18,6 +18,7 @@ import type { VitestBrowserClientMocker } from './mocker' | |||
| 18 | 18 | import type { CommandsManager } from './tester-utils' | |
| 19 | 19 | import { globalChannel, onCancel } from '@vitest/browser/client' | |
| 20 | 20 | import { getTestName } from '@vitest/runner/utils' | |
| 21 | + import { BenchmarkRunner, TestRunner } from 'vitest' | ||
| 21 | 22 | import { page, userEvent } from 'vitest/browser' | |
| 22 | 23 | import { | |
| 23 | 24 | DecodedMap, | |
@@ -26,7 +27,6 @@ import { | |||
| 26 | 27 | loadSnapshotSerializers, | |
| 27 | 28 | takeCoverageInsideWorker, | |
| 28 | 29 | } from 'vitest/internal/browser' | |
| 29 | - import { NodeBenchmarkRunner, VitestTestRunner } from 'vitest/runners' | ||
| 30 | 30 | import { createStackString, parseStacktrace } from '../../../../utils/src/source-map' | |
| 31 | 31 | import { getBrowserState, getWorkerState, moduleRunner } from '../utils' | |
| 32 | 32 | import { rpc } from './rpc' | |
@@ -323,7 +323,7 @@ export async function initiateRunner( | |||
| 323 | 323 | return cachedRunner | |
| 324 | 324 | } | |
| 325 | 325 | const runnerClass | |
| 326 | - = config.mode === 'test' ? VitestTestRunner : NodeBenchmarkRunner | ||
| 326 | + = config.mode === 'test' ? TestRunner : BenchmarkRunner | ||
| 327 | 327 | ||
| 328 | 328 | const BrowserRunner = createBrowserRunner(runnerClass, mocker, state, { | |
| 329 | 329 | takeCoverage: () => | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,6 +1,6 @@ | |||
| 1 | 1 | import type { VitestBrowserClient } from '@vitest/browser/client' | |
| 2 | 2 | import type { ParsedStack } from 'vitest/internal/browser' | |
| 3 | - import type { SnapshotEnvironment } from 'vitest/snapshot' | ||
| 3 | + import type { SnapshotEnvironment } from 'vitest/runtime' | ||
| 4 | 4 | import { DecodedMap, getOriginalPosition } from 'vitest/internal/browser' | |
| 5 | 5 | ||
| 6 | 6 | export class VitestBrowserSnapshotEnvironment implements SnapshotEnvironment { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -242,7 +242,6 @@ export default (parentServer: ParentBrowserProject, base = '/'): Plugin[] => { | |||
| 242 | 242 | 'vitest', | |
| 243 | 243 | 'vitest/browser', | |
| 244 | 244 | 'vitest/internal/browser', | |
| 245 | - 'vitest/runners', | ||
| 246 | 245 | 'vite/module-runner', | |
| 247 | 246 | '@vitest/browser/utils', | |
| 248 | 247 | '@vitest/browser/context', | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -15,8 +15,7 @@ import reports from 'istanbul-reports' | |||
| 15 | 15 | import { parseModule } from 'magicast' | |
| 16 | 16 | import { createDebug } from 'obug' | |
| 17 | 17 | import c from 'tinyrainbow' | |
| 18 | - import { BaseCoverageProvider } from 'vitest/coverage' | ||
| 19 | - import { isCSSRequest } from 'vitest/node' | ||
| 18 | + import { BaseCoverageProvider, isCSSRequest } from 'vitest/node' | ||
| 20 | 19 | import { version } from '../package.json' with { type: 'json' } | |
| 21 | 20 | import { COVERAGE_STORE_KEY } from './constants' | |
| 22 | 21 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -15,8 +15,7 @@ import { createDebug } from 'obug' | |||
| 15 | 15 | import { normalize } from 'pathe' | |
| 16 | 16 | import { provider } from 'std-env' | |
| 17 | 17 | import c from 'tinyrainbow' | |
| 18 | - import { BaseCoverageProvider } from 'vitest/coverage' | ||
| 19 | - import { parseAstAsync } from 'vitest/node' | ||
| 18 | + import { BaseCoverageProvider, parseAstAsync } from 'vitest/node' | ||
| 20 | 19 | import { version } from '../package.json' with { type: 'json' } | |
| 21 | 20 | ||
| 22 | 21 | export interface ScriptCoverageWithOffset extends Profiler.ScriptCoverage { | |
| Back | FazBrowse Home | New Git URL |
0 commit comments