@@ -83,6 +83,7 @@ export class Vitest {
8383 public distPath = distDir
8484
8585 private _cachedSpecs = new Map < string , WorkspaceSpec [ ] > ( )
86+ private _workspaceConfigPath ?: string
8687
8788 /** @deprecated use `_cachedSpecs` */
8889 projectTestFiles = this . _cachedSpecs
@@ -110,6 +111,9 @@ export class Vitest {
110111 this . _browserLastPort = defaultBrowserPort
111112 this . pool ?. close ?.( )
112113 this . pool = undefined
114+ this . projects = [ ]
115+ this . resolvedProjects = [ ]
116+ this . _workspaceConfigPath = undefined
113117 this . coverageProvider = undefined
114118 this . runningPromise = undefined
115119 this . _cachedSpecs . clear ( )
@@ -155,6 +159,8 @@ export class Vitest {
155159 server . watcher . on ( 'change' , async ( file ) => {
156160 file = normalize ( file )
157161 const isConfig = file === server . config . configFile
162+ || this . resolvedProjects . some ( p => p . server . config . configFile === file )
163+ || file === this . _workspaceConfigPath
158164 if ( isConfig ) {
159165 await Promise . all ( this . _onRestartListeners . map ( fn => fn ( 'config' ) ) )
160166 await serverRestart ( )
@@ -175,8 +181,6 @@ export class Vitest {
175181 }
176182 catch { }
177183
178- await Promise . all ( this . _onSetServer . map ( fn => fn ( ) ) )
179-
180184 const projects = await this . resolveWorkspace ( cliOptions )
181185 this . resolvedProjects = projects
182186 this . projects = projects
@@ -193,6 +197,8 @@ export class Vitest {
193197 if ( this . config . testNamePattern ) {
194198 this . configOverride . testNamePattern = this . config . testNamePattern
195199 }
200+
201+ await Promise . all ( this . _onSetServer . map ( fn => fn ( ) ) )
196202 }
197203
198204 public provide < T extends keyof ProvidedContext & string > ( key : T , value : ProvidedContext [ T ] ) {
@@ -235,7 +241,7 @@ export class Vitest {
235241 || this . projects [ 0 ]
236242 }
237243
238- private async getWorkspaceConfigPath ( ) : Promise < string | null > {
244+ private async getWorkspaceConfigPath ( ) : Promise < string | undefined > {
239245 if ( this . config . workspace ) {
240246 return this . config . workspace
241247 }
@@ -251,7 +257,7 @@ export class Vitest {
251257 } )
252258
253259 if ( ! workspaceConfigName ) {
254- return null
260+ return undefined
255261 }
256262
257263 return join ( configDir , workspaceConfigName )
@@ -260,6 +266,8 @@ export class Vitest {
260266 private async resolveWorkspace ( cliOptions : UserConfig ) {
261267 const workspaceConfigPath = await this . getWorkspaceConfigPath ( )
262268
269+ this . _workspaceConfigPath = workspaceConfigPath
270+
263271 if ( ! workspaceConfigPath ) {
264272 return [ await this . _createCoreProject ( ) ]
265273 }
@@ -1045,7 +1053,9 @@ export class Vitest {
10451053 } )
10461054 this . logger . logUpdate . done ( ) // restore terminal cursor
10471055 } )
1048- } ) ( )
1056+ } ) ( ) . finally ( ( ) => {
1057+ this . closingPromise = undefined
1058+ } )
10491059 }
10501060 return this . closingPromise
10511061 }
0 commit comments