@@ -2,6 +2,7 @@ import type { Vitest } from '../core'
22import type { UserConfig , UserWorkspaceConfig , WorkspaceProjectConfiguration } from '../types/config'
33import type { WorkspaceProject } from '../workspace'
44import { existsSync , promises as fs } from 'node:fs'
5+ import { limitConcurrency } from '@vitest/runner/utils'
56import fg from 'fast-glob'
67import { relative , resolve } from 'pathe'
78import { mergeConfig } from 'vite'
@@ -48,47 +49,40 @@ export async function resolveWorkspace(
4849 return acc
4950 } , { } as UserConfig )
5051
51- const projects : WorkspaceProject [ ] = [ ]
52+ const projectPromises : Promise < WorkspaceProject > [ ] = [ ]
5253 const fileProjects = [ ...configFiles , ...nonConfigDirectories ]
54+ const concurrent = limitConcurrency ( 5 )
5355
54- // we have to resolve them one by one because CWD should depend on the project
5556 for ( const filepath of fileProjects ) {
5657 // if file leads to the root config, then we can just reuse it because we already initialized it
5758 if ( vitest . server . config . configFile === filepath ) {
58- const project = await vitest . _createCoreProject ( )
59- projects . push ( project )
59+ projectPromises . push ( concurrent ( ( ) => vitest . _createCoreProject ( ) ) )
6060 continue
6161 }
6262
63- projects . push (
64- await initializeProject (
63+ projectPromises . push (
64+ concurrent ( ( ) => initializeProject (
6565 filepath ,
6666 vitest ,
6767 { workspaceConfigPath, test : cliOverrides } ,
68- ) ,
68+ ) ) ,
6969 )
7070 }
7171
72- const projectPromises : Promise < WorkspaceProject > [ ] = [ ]
73-
7472 projectConfigs . forEach ( ( options , index ) => {
75- // we can resolve these in parallel because process.cwd() is not changed
76- projectPromises . push ( initializeProject (
73+ projectPromises . push ( concurrent ( ( ) => initializeProject (
7774 index ,
7875 vitest ,
7976 mergeConfig ( options , { workspaceConfigPath, test : cliOverrides } ) as any ,
80- ) )
77+ ) ) )
8178 } )
8279
8380 // pretty rare case - the glob didn't match anything and there are no inline configs
84- if ( ! projects . length && ! projectPromises . length ) {
81+ if ( ! projectPromises . length ) {
8582 return [ await vitest . _createCoreProject ( ) ]
8683 }
8784
88- const resolvedProjects = await Promise . all ( [
89- ...projects ,
90- ...projectPromises ,
91- ] )
85+ const resolvedProjects = await Promise . all ( projectPromises )
9286 const names = new Set < string > ( )
9387
9488 // project names are guaranteed to be unique
0 commit comments