Skip to content
Merged
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
* text=auto eol=lf

test/reporters/fixtures/indicator-position.test.js eol=crlf
test/cli/fixtures/reporters/indicator-position.test.js eol=crlf
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
1 change: 1 addition & 0 deletions docs/guide/browser/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,7 @@ However, Vitest also provides packages to render components for several popular
- [`vitest-browser-vue`](https://github.com/vitest-dev/vitest-browser-vue) to render [vue](https://vuejs.org) components
- [`vitest-browser-svelte`](https://github.com/vitest-dev/vitest-browser-svelte) to render [svelte](https://svelte.dev) components
- [`vitest-browser-react`](https://github.com/vitest-dev/vitest-browser-react) to render [react](https://react.dev) components
- [`vitest-browser-angular`](https://github.com/vitest-community/vitest-browser-angular) to render [Angular](https://angular.dev) components

Community packages are available for other frameworks:

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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@vitest/monorepo",
"type": "module",
"version": "4.0.16",
"version": "4.0.17",
"private": true,
"packageManager": "[email protected]",
"description": "Next generation testing framework powered by Vite",
Expand Down
2 changes: 1 addition & 1 deletion packages/browser-playwright/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@vitest/browser-playwright",
"type": "module",
"version": "4.0.16",
"version": "4.0.17",
"description": "Browser running for Vitest using playwright",
"license": "MIT",
"funding": "https://opencollective.com/vitest",
Expand Down
2 changes: 1 addition & 1 deletion packages/browser-preview/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@vitest/browser-preview",
"type": "module",
"version": "4.0.16",
"version": "4.0.17",
"description": "Browser running for Vitest using your browser of choice",
"license": "MIT",
"funding": "https://opencollective.com/vitest",
Expand Down
2 changes: 1 addition & 1 deletion packages/browser-webdriverio/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@vitest/browser-webdriverio",
"type": "module",
"version": "4.0.16",
"version": "4.0.17",
"description": "Browser running for Vitest using webdriverio",
"license": "MIT",
"funding": "https://opencollective.com/vitest",
Expand Down
2 changes: 1 addition & 1 deletion packages/browser/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@vitest/browser",
"type": "module",
"version": "4.0.16",
"version": "4.0.17",
"description": "Browser running for Vitest",
"license": "MIT",
"funding": "https://opencollective.com/vitest",
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
22 changes: 8 additions & 14 deletions packages/browser/src/node/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import type {
import type { ParentBrowserProject } from './projectParent'
import { existsSync } from 'node:fs'
import { readFile } from 'node:fs/promises'
import { fileURLToPath } from 'node:url'
import { resolve } from 'pathe'
import { distRoot } from './constants'
import { BrowserServerState } from './state'
import { getBrowserProvider } from './utils'

Expand All @@ -25,41 +25,35 @@ export class ProjectBrowser implements IProjectBrowser {

public provider!: BrowserProvider
public vitest: Vitest
public vite: ViteDevServer
public config: ResolvedConfig
public children: Set<ProjectBrowser> = new Set<ProjectBrowser>()

public parent!: ParentBrowserProject

public state: BrowserServerState = new BrowserServerState()

constructor(
public parent: ParentBrowserProject,
public project: TestProject,
public base: string,
) {
this.vitest = project.vitest
this.config = project.config
this.vite = parent.vite

const pkgRoot = resolve(fileURLToPath(import.meta.url), '../..')
const distRoot = resolve(pkgRoot, 'dist')

// instances can override testerHtmlPath
const testerHtmlPath = project.config.browser.testerHtmlPath
? resolve(project.config.root, project.config.browser.testerHtmlPath)
: resolve(distRoot, 'client/tester/tester.html')
// TODO: when config resolution is rewritten, project and parentProject should be created before the vite server is started
if (!existsSync(testerHtmlPath)) {
throw new Error(`Tester HTML file "${testerHtmlPath}" doesn't exist.`)
}
this.testerFilepath = testerHtmlPath

this.testerHtml = readFile(
testerHtmlPath,
this.testerFilepath,
'utf8',
).then(html => (this.testerHtml = html))
}

get vite(): ViteDevServer {
return this.parent.vite
}

private commands = {} as Record<string, BrowserCommand<any, any>>

public registerCommand<K extends keyof BrowserCommands>(
Expand Down Expand Up @@ -130,7 +124,7 @@ export class ProjectBrowser implements IProjectBrowser {
}

async close(): Promise<void> {
await this.parent.vite.close()
await this.vite.close()
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/browser/src/node/projectParent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,10 @@ export class ParentBrowserProject {
throw new Error(`Cannot spawn child server without a parent dev server.`)
}
const clone = new ProjectBrowser(
this,
project,
'/',
)
clone.parent = this
this.children.add(clone)
return clone
}
Expand Down
2 changes: 1 addition & 1 deletion packages/coverage-istanbul/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@vitest/coverage-istanbul",
"type": "module",
"version": "4.0.16",
"version": "4.0.17",
"description": "Istanbul coverage provider for Vitest",
"author": "Anthony Fu <[email protected]>",
"license": "MIT",
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
2 changes: 1 addition & 1 deletion packages/coverage-v8/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@vitest/coverage-v8",
"type": "module",
"version": "4.0.16",
"version": "4.0.17",
"description": "V8 coverage provider for Vitest",
"author": "Anthony Fu <[email protected]>",
"license": "MIT",
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
2 changes: 1 addition & 1 deletion packages/expect/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@vitest/expect",
"type": "module",
"version": "4.0.16",
"version": "4.0.17",
"description": "Jest's expect matchers as a Chai plugin",
"license": "MIT",
"funding": "https://opencollective.com/vitest",
Expand Down
2 changes: 1 addition & 1 deletion packages/mocker/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@vitest/mocker",
"type": "module",
"version": "4.0.16",
"version": "4.0.17",
"description": "Vitest module mocker implementation",
"license": "MIT",
"funding": "https://opencollective.com/vitest",
Expand Down
2 changes: 1 addition & 1 deletion packages/pretty-format/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@vitest/pretty-format",
"type": "module",
"version": "4.0.16",
"version": "4.0.17",
"description": "Fork of pretty-format with support for ESM",
"license": "MIT",
"funding": "https://opencollective.com/vitest",
Expand Down
2 changes: 1 addition & 1 deletion packages/runner/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@vitest/runner",
"type": "module",
"version": "4.0.16",
"version": "4.0.17",
"description": "Vitest test runner",
"license": "MIT",
"funding": "https://opencollective.com/vitest",
Expand Down
2 changes: 1 addition & 1 deletion packages/snapshot/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@vitest/snapshot",
"type": "module",
"version": "4.0.16",
"version": "4.0.17",
"description": "Vitest snapshot manager",
"license": "MIT",
"funding": "https://opencollective.com/vitest",
Expand Down
2 changes: 1 addition & 1 deletion packages/spy/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@vitest/spy",
"type": "module",
"version": "4.0.16",
"version": "4.0.17",
"description": "Lightweight Jest compatible spy implementation",
"license": "MIT",
"funding": "https://opencollective.com/vitest",
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
2 changes: 1 addition & 1 deletion packages/ui/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@vitest/ui",
"type": "module",
"version": "4.0.16",
"version": "4.0.17",
"description": "UI for Vitest",
"license": "MIT",
"funding": "https://opencollective.com/vitest",
Expand Down
Loading
Loading