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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion docs/.vitepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ export default ({ mode }: { mode: string }) => {
customIcon: {
'CLI': 'vscode-icons:file-type-shell',
'vitest.shims': 'vscode-icons:file-type-vitest',
'vitest.workspace': 'vscode-icons:file-type-vitest',
'vitest.config': 'vscode-icons:file-type-vitest',
'.spec.ts': 'vscode-icons:file-type-testts',
'.test.ts': 'vscode-icons:file-type-testts',
Expand Down
14 changes: 0 additions & 14 deletions docs/config/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -2362,20 +2362,6 @@ Relevant only when using with `shouldAdvanceTime: true`. increment mocked time b

Tells fake timers to clear "native" (i.e. not fake) timers by delegating to their respective handlers. When disabled, it can lead to potentially unexpected behavior if timers existed prior to starting fake timers session.

### workspace<NonProjectOption /> {#workspace}

::: danger DEPRECATED
This options is deprecated and will be removed in the next major. Please, use [`projects`](#projects) instead.
:::

- **Type:** `string | TestProjectConfiguration[]`
- **CLI:** `--workspace=./file.js`
- **Default:** `vitest.{workspace,projects}.{js,ts,json}` close to the config file or root

Path to a [workspace](/guide/projects) config file relative to [root](#root).

Since Vitest 3, you can also define the workspace array in the root config. If the `workspace` is defined in the config manually, Vitest will ignore the `vitest.workspace` file in the root.

### projects<NonProjectOption /> {#projects}

- **Type:** `TestProjectConfiguration[]`
Expand Down
7 changes: 0 additions & 7 deletions docs/guide/cli-generated.md
Original file line number Diff line number Diff line change
Expand Up @@ -272,13 +272,6 @@ High and low watermarks for functions in the format of `<high>,<low>`

Override Vite mode (default: `test` or `benchmark`)

### workspace

- **CLI:** `--workspace <path>`
- **Config:** [workspace](/config/#workspace)

[deprecated] Path to a workspace configuration file

### isolate

- **CLI:** `--isolate`
Expand Down
1 change: 1 addition & 0 deletions docs/guide/migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ Vitest 4.0 removes some deprecated APIs, including:

- `poolMatchGlobs` config option. Use [`projects`](/guide/projects) instead.
- `environmentMatchGlobs` config option. Use [`projects`](/guide/projects) instead.
- `workspace` config option. Use [`projects`](/guide/projects) instead.

## Migrating from Jest {#jest}

Expand Down
8 changes: 0 additions & 8 deletions packages/vitest/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,12 @@ export const extraInlineDeps: RegExp[] = [

export const CONFIG_NAMES: string[] = ['vitest.config', 'vite.config']

const WORKSPACES_NAMES = ['vitest.workspace', 'vitest.projects']

export const CONFIG_EXTENSIONS: string[] = ['.ts', '.mts', '.cts', '.js', '.mjs', '.cjs']

export const configFiles: string[] = CONFIG_NAMES.flatMap(name =>
CONFIG_EXTENSIONS.map(ext => name + ext),
)

const WORKSPACES_EXTENSIONS = [...CONFIG_EXTENSIONS, '.json']

export const workspacesFiles: string[] = WORKSPACES_NAMES.flatMap(name =>
WORKSPACES_EXTENSIONS.map(ext => name + ext),
)

export const globalApis: string[] = [
// suite
'suite',
Expand Down
5 changes: 0 additions & 5 deletions packages/vitest/src/node/cli/cli-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -334,11 +334,6 @@ export const cliOptionsConfig: VitestCLIOptions = {
description: 'Override Vite mode (default: `test` or `benchmark`)',
argument: '<name>',
},
workspace: {
description: '[deprecated] Path to a workspace configuration file',
argument: '<path>',
normalize: true,
},
isolate: {
description:
'Run every test file in isolation. To disable isolation, use `--no-isolate` (default: `true`)',
Expand Down
10 changes: 0 additions & 10 deletions packages/vitest/src/node/config/resolveConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import {
defaultInspectPort,
defaultPort,
extraInlineDeps,
workspacesFiles,
} from '../../constants'
import { benchmarkConfigDefaults, configDefaults } from '../../defaults'
import { isCI, stdProvider } from '../../utils/env'
Expand Down Expand Up @@ -387,7 +386,6 @@ export function resolveConfig(
// Configs
resolved.config && slash(resolved.config),
...configFiles,
...workspacesFiles,

// Vite internal
'**\/virtual:*',
Expand Down Expand Up @@ -598,14 +596,6 @@ export function resolveConfig(
}
}

if (typeof resolved.workspace === 'string') {
// if passed down from the CLI and it's relative, resolve relative to CWD
resolved.workspace
= typeof options.workspace === 'string' && options.workspace[0] === '.'
? resolve(process.cwd(), options.workspace)
: resolvePath(resolved.workspace, resolved.root)
}

if (!builtinPools.includes(resolved.pool as BuiltinPool)) {
resolved.pool = resolvePath(resolved.pool, resolved.root)
}
Expand Down
99 changes: 10 additions & 89 deletions packages/vitest/src/node/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,15 @@ import type { ResolvedConfig, TestProjectConfiguration, UserConfig, VitestRunMod
import type { CoverageProvider } from './types/coverage'
import type { Reporter } from './types/reporter'
import type { TestRunResult } from './types/tests'
import { promises as fs } from 'node:fs'
import { getTasks, hasFailed } from '@vitest/runner/utils'
import { SnapshotManager } from '@vitest/snapshot/manager'
import { noop, toArray } from '@vitest/utils'
import { dirname, join, normalize, relative, resolve } from 'pathe'
import { normalize, relative } from 'pathe'
import { ViteNodeRunner } from 'vite-node/client'
import { ViteNodeServer } from 'vite-node/server'
import { version } from '../../package.json' with { type: 'json' }
import { WebSocketReporter } from '../api/setup'
import { defaultBrowserPort, workspacesFiles as workspaceFiles } from '../constants'
import { defaultBrowserPort } from '../constants'
import { distDir } from '../paths'
import { wildcardPatternToRegExp } from '../utils/base'
import { convertTasksToEvents } from '../utils/tasks'
Expand Down Expand Up @@ -90,11 +89,6 @@ export class Vitest {
/** @internal */ closingPromise?: Promise<void>
/** @internal */ isCancelling = false
/** @internal */ coreWorkspaceProject: TestProject | undefined
/**
* @internal
* @deprecated
*/
resolvedProjects: TestProject[] = []
/** @internal */ _browserLastPort = defaultBrowserPort
/** @internal */ _browserSessions = new BrowserSessions()
/** @internal */ _cliOptions: CliOptions = {}
Expand All @@ -114,7 +108,6 @@ export class Vitest {
private _state?: StateManager
private _cache?: VitestCache
private _snapshot?: SnapshotManager
private _workspaceConfigPath?: string

constructor(
public readonly mode: VitestRunMode,
Expand Down Expand Up @@ -208,8 +201,6 @@ export class Vitest {
this.pool = undefined
this.closingPromise = undefined
this.projects = []
this.resolvedProjects = []
this._workspaceConfigPath = undefined
this.coverageProvider = undefined
this.runningPromise = undefined
this.coreWorkspaceProject = undefined
Expand Down Expand Up @@ -261,7 +252,6 @@ export class Vitest {
file = normalize(file)
const isConfig = file === server.config.configFile
|| this.projects.some(p => p.vite.config.configFile === file)
|| file === this._workspaceConfigPath
if (isConfig) {
await Promise.all(this._onRestartListeners.map(fn => fn('config')))
this.report('onServerRestart', 'config')
Expand All @@ -278,7 +268,6 @@ export class Vitest {
catch { }

const projects = await this.resolveProjects(this._cliOptions)
this.resolvedProjects = projects
this.projects = projects

await Promise.all(projects.flatMap((project) => {
Expand Down Expand Up @@ -404,38 +393,10 @@ export class Vitest {
return this.runner.executeId(moduleId)
}

private async resolveWorkspaceConfigPath(): Promise<string | undefined> {
if (typeof this.config.workspace === 'string') {
return this.config.workspace
}

const configDir = this.vite.config.configFile
? dirname(this.vite.config.configFile)
: this.config.root

const rootFiles = await fs.readdir(configDir)

const workspaceConfigName = workspaceFiles.find((configFile) => {
return rootFiles.includes(configFile)
})

if (!workspaceConfigName) {
return undefined
}

return join(configDir, workspaceConfigName)
}

private async resolveProjects(cliOptions: UserConfig): Promise<TestProject[]> {
const names = new Set<string>()

if (this.config.projects) {
if (typeof this.config.workspace !== 'undefined') {
this.logger.warn(
'Both `test.projects` and `test.workspace` are defined. Ignoring the `test.workspace` option.',
)
}

return resolveProjects(
this,
cliOptions,
Expand All @@ -445,57 +406,17 @@ export class Vitest {
)
}

if (Array.isArray(this.config.workspace)) {
this.logger.deprecate(
'The `test.workspace` option is deprecated and will be removed in the next major. To hide this warning, rename `test.workspace` option to `test.projects`.',
)
return resolveProjects(
this,
cliOptions,
undefined,
this.config.workspace,
names,
)
}

const workspaceConfigPath = await this.resolveWorkspaceConfigPath()

this._workspaceConfigPath = workspaceConfigPath

// user doesn't have a workspace config, return default project
if (!workspaceConfigPath) {
// user can filter projects with --project flag, `getDefaultTestProject`
// returns the project only if it matches the filter
const project = getDefaultTestProject(this)
if (!project) {
return []
}
return resolveBrowserProjects(this, new Set([project.name]), [project])
if ('workspace' in this.config) {
throw new Error('The `test.workspace` option was removed in Vitest 4. Please, migrate to `test.projects` instead. See https://vitest.dev/guide/projects for examples.')
}

const configFile = this.vite.config.configFile
? resolve(this.vite.config.root, this.vite.config.configFile)
: 'the root config file'

this.logger.deprecate(
`The workspace file is deprecated and will be removed in the next major. Please, use the \`test.projects\` field in ${configFile} instead.`,
)

const workspaceModule = await this.import<{
default: TestProjectConfiguration[]
}>(workspaceConfigPath)

if (!workspaceModule.default || !Array.isArray(workspaceModule.default)) {
throw new TypeError(`Workspace config file "${workspaceConfigPath}" must export a default array of project paths.`)
// user can filter projects with --project flag, `getDefaultTestProject`
// returns the project only if it matches the filter
const project = getDefaultTestProject(this)
if (!project) {
return []
}

return resolveProjects(
this,
cliOptions,
workspaceConfigPath,
workspaceModule.default,
names,
)
return resolveBrowserProjects(this, new Set([project.name]), [project])
}

/**
Expand Down
8 changes: 7 additions & 1 deletion packages/vitest/src/node/projects/resolveProjects.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import type { GlobOptions } from 'tinyglobby'
import type { Vitest } from '../core'
import type { BrowserInstanceOption, ResolvedConfig, TestProjectConfiguration, UserConfig, UserWorkspaceConfig } from '../types/config'
import type {
BrowserInstanceOption,
ResolvedConfig,
TestProjectConfiguration,
UserConfig,
UserWorkspaceConfig,
} from '../types/config'
import { existsSync, promises as fs } from 'node:fs'
import os from 'node:os'
import { limitConcurrency } from '@vitest/runner/utils'
Expand Down
7 changes: 0 additions & 7 deletions packages/vitest/src/node/types/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -377,12 +377,6 @@ export interface InlineConfig {
*/
projects?: TestProjectConfiguration[]

/**
* Path to a workspace configuration file
* @deprecated use `projects` instead
*/
workspace?: string | TestProjectConfiguration[]

/**
* Update snapshot
*
Expand Down Expand Up @@ -1110,7 +1104,6 @@ type NonProjectOptions =
| 'maxWorkers'
| 'minWorkers'
| 'fileParallelism'
| 'workspace'
| 'watchTriggerPatterns'

export type ProjectConfig = Omit<
Expand Down
13 changes: 0 additions & 13 deletions test/config/fixtures/workspace/browser/workspace-with-browser.ts

This file was deleted.

1 change: 0 additions & 1 deletion test/config/fixtures/workspace/nested/e2e.projects.js

This file was deleted.

21 changes: 20 additions & 1 deletion test/config/test/failures.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,18 @@ Use either:
test('v8 coverage provider cannot be used in workspace without playwright + chromium', async () => {
const { stderr } = await runVitest({
coverage: { enabled: true },
workspace: './fixtures/workspace/browser/workspace-with-browser.ts',
projects: [
{
test: {
name: 'Browser project',
browser: {
enabled: true,
provider: 'webdriverio',
instances: [{ browser: 'chrome' }],
},
},
},
],
}, {}, { fails: true })
expect(stderr).toMatch(
`Error: @vitest/coverage-v8 does not work with
Expand Down Expand Up @@ -585,3 +596,11 @@ test('minWorkers higher than maxWorkers does not crash', async ({ skip }) => {
expect(stdout).toMatch('✓ example.test.ts > it works')
expect(stderr).toBe('')
})

test('cannot set the `workspace` options', async () => {
const { stderr } = await runVitest({
// @ts-expect-error workspace was removed in Vitest 4, but we show an error
workspace: 'some-options',
})
expect(stderr).toContain('The `test.workspace` option was removed in Vitest 4. Please, migrate to `test.projects` instead. See https://vitest.dev/guide/projects for examples.')
})
11 changes: 0 additions & 11 deletions test/config/test/projects.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,6 @@ import { resolve } from 'pathe'
import { expect, it } from 'vitest'
import { runVitest } from '../../test-utils'

it('correctly runs workspace tests when workspace config path is specified', async () => {
// TODO: remove the test in Vitest 4
const { stderr, stdout } = await runVitest({
root: 'fixtures/workspace',
workspace: 'nested/e2e.projects.js',
})
expect(stderr).toContain('The workspace file is deprecated and will be removed in the next major')
expect(stdout).toContain('1 + 1 = 2')
expect(stdout).not.toContain('2 + 2 = 4')
})

it('runs the workspace if there are several vitest config files', async () => {
const { stderr, stdout } = await runVitest({
root: 'fixtures/workspace/several-configs',
Expand Down
3 changes: 1 addition & 2 deletions test/coverage-test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
"type": "module",
"private": true,
"scripts": {
"test": "vitest --workspace=vitest.workspace.custom.ts",
"vitest": "vitest"
"test": "vitest"
},
"devDependencies": {
"@ampproject/remapping": "^2.3.0",
Expand Down
Loading
Loading