@@ -11,16 +11,15 @@ import type { ResolvedConfig, TestProjectConfiguration, UserConfig, VitestRunMod
1111import type { CoverageProvider } from './types/coverage'
1212import type { Reporter } from './types/reporter'
1313import type { TestRunResult } from './types/tests'
14- import { promises as fs } from 'node:fs'
1514import { getTasks , hasFailed } from '@vitest/runner/utils'
1615import { SnapshotManager } from '@vitest/snapshot/manager'
1716import { noop , toArray } from '@vitest/utils'
18- import { dirname , join , normalize , relative , resolve } from 'pathe'
17+ import { normalize , relative } from 'pathe'
1918import { ViteNodeRunner } from 'vite-node/client'
2019import { ViteNodeServer } from 'vite-node/server'
2120import { version } from '../../package.json' with { type : 'json' }
2221import { WebSocketReporter } from '../api/setup'
23- import { defaultBrowserPort , workspacesFiles as workspaceFiles } from '../constants'
22+ import { defaultBrowserPort } from '../constants'
2423import { distDir } from '../paths'
2524import { wildcardPatternToRegExp } from '../utils/base'
2625import { convertTasksToEvents } from '../utils/tasks'
@@ -90,11 +89,6 @@ export class Vitest {
9089 /** @internal */ closingPromise ?: Promise < void >
9190 /** @internal */ isCancelling = false
9291 /** @internal */ coreWorkspaceProject : TestProject | undefined
93- /**
94- * @internal
95- * @deprecated
96- */
97- resolvedProjects : TestProject [ ] = [ ]
9892 /** @internal */ _browserLastPort = defaultBrowserPort
9993 /** @internal */ _browserSessions = new BrowserSessions ( )
10094 /** @internal */ _cliOptions : CliOptions = { }
@@ -114,7 +108,6 @@ export class Vitest {
114108 private _state ?: StateManager
115109 private _cache ?: VitestCache
116110 private _snapshot ?: SnapshotManager
117- private _workspaceConfigPath ?: string
118111
119112 constructor (
120113 public readonly mode : VitestRunMode ,
@@ -208,8 +201,6 @@ export class Vitest {
208201 this . pool = undefined
209202 this . closingPromise = undefined
210203 this . projects = [ ]
211- this . resolvedProjects = [ ]
212- this . _workspaceConfigPath = undefined
213204 this . coverageProvider = undefined
214205 this . runningPromise = undefined
215206 this . coreWorkspaceProject = undefined
@@ -261,7 +252,6 @@ export class Vitest {
261252 file = normalize ( file )
262253 const isConfig = file === server . config . configFile
263254 || this . projects . some ( p => p . vite . config . configFile === file )
264- || file === this . _workspaceConfigPath
265255 if ( isConfig ) {
266256 await Promise . all ( this . _onRestartListeners . map ( fn => fn ( 'config' ) ) )
267257 this . report ( 'onServerRestart' , 'config' )
@@ -278,7 +268,6 @@ export class Vitest {
278268 catch { }
279269
280270 const projects = await this . resolveProjects ( this . _cliOptions )
281- this . resolvedProjects = projects
282271 this . projects = projects
283272
284273 await Promise . all ( projects . flatMap ( ( project ) => {
@@ -404,38 +393,10 @@ export class Vitest {
404393 return this . runner . executeId ( moduleId )
405394 }
406395
407- private async resolveWorkspaceConfigPath ( ) : Promise < string | undefined > {
408- if ( typeof this . config . workspace === 'string' ) {
409- return this . config . workspace
410- }
411-
412- const configDir = this . vite . config . configFile
413- ? dirname ( this . vite . config . configFile )
414- : this . config . root
415-
416- const rootFiles = await fs . readdir ( configDir )
417-
418- const workspaceConfigName = workspaceFiles . find ( ( configFile ) => {
419- return rootFiles . includes ( configFile )
420- } )
421-
422- if ( ! workspaceConfigName ) {
423- return undefined
424- }
425-
426- return join ( configDir , workspaceConfigName )
427- }
428-
429396 private async resolveProjects ( cliOptions : UserConfig ) : Promise < TestProject [ ] > {
430397 const names = new Set < string > ( )
431398
432399 if ( this . config . projects ) {
433- if ( typeof this . config . workspace !== 'undefined' ) {
434- this . logger . warn (
435- 'Both `test.projects` and `test.workspace` are defined. Ignoring the `test.workspace` option.' ,
436- )
437- }
438-
439400 return resolveProjects (
440401 this ,
441402 cliOptions ,
@@ -445,57 +406,17 @@ export class Vitest {
445406 )
446407 }
447408
448- if ( Array . isArray ( this . config . workspace ) ) {
449- this . logger . deprecate (
450- '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`.' ,
451- )
452- return resolveProjects (
453- this ,
454- cliOptions ,
455- undefined ,
456- this . config . workspace ,
457- names ,
458- )
459- }
460-
461- const workspaceConfigPath = await this . resolveWorkspaceConfigPath ( )
462-
463- this . _workspaceConfigPath = workspaceConfigPath
464-
465- // user doesn't have a workspace config, return default project
466- if ( ! workspaceConfigPath ) {
467- // user can filter projects with --project flag, `getDefaultTestProject`
468- // returns the project only if it matches the filter
469- const project = getDefaultTestProject ( this )
470- if ( ! project ) {
471- return [ ]
472- }
473- return resolveBrowserProjects ( this , new Set ( [ project . name ] ) , [ project ] )
409+ if ( 'workspace' in this . config ) {
410+ 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.' )
474411 }
475412
476- const configFile = this . vite . config . configFile
477- ? resolve ( this . vite . config . root , this . vite . config . configFile )
478- : 'the root config file'
479-
480- this . logger . deprecate (
481- `The workspace file is deprecated and will be removed in the next major. Please, use the \`test.projects\` field in ${ configFile } instead.` ,
482- )
483-
484- const workspaceModule = await this . import < {
485- default : TestProjectConfiguration [ ]
486- } > ( workspaceConfigPath )
487-
488- if ( ! workspaceModule . default || ! Array . isArray ( workspaceModule . default ) ) {
489- throw new TypeError ( `Workspace config file "${ workspaceConfigPath } " must export a default array of project paths.` )
413+ // user can filter projects with --project flag, `getDefaultTestProject`
414+ // returns the project only if it matches the filter
415+ const project = getDefaultTestProject ( this )
416+ if ( ! project ) {
417+ return [ ]
490418 }
491-
492- return resolveProjects (
493- this ,
494- cliOptions ,
495- workspaceConfigPath ,
496- workspaceModule . default ,
497- names ,
498- )
419+ return resolveBrowserProjects ( this , new Set ( [ project . name ] ) , [ project ] )
499420 }
500421
501422 /**
0 commit comments