@@ -83,6 +83,7 @@ export class Vitest {
83
83
public distPath = distDir
84
84
85
85
private _cachedSpecs = new Map < string , WorkspaceSpec [ ] > ( )
86
+ private _workspaceConfigPath ?: string
86
87
87
88
/** @deprecated use `_cachedSpecs` */
88
89
projectTestFiles = this . _cachedSpecs
@@ -110,6 +111,10 @@ export class Vitest {
110
111
this . _browserLastPort = defaultBrowserPort
111
112
this . pool ?. close ?.( )
112
113
this . pool = undefined
114
+ this . closingPromise = undefined
115
+ this . projects = [ ]
116
+ this . resolvedProjects = [ ]
117
+ this . _workspaceConfigPath = undefined
113
118
this . coverageProvider = undefined
114
119
this . runningPromise = undefined
115
120
this . _cachedSpecs . clear ( )
@@ -145,22 +150,22 @@ export class Vitest {
145
150
const serverRestart = server . restart
146
151
server . restart = async ( ...args ) => {
147
152
await Promise . all ( this . _onRestartListeners . map ( fn => fn ( ) ) )
153
+ this . report ( 'onServerRestart' )
154
+ await this . close ( )
148
155
await serverRestart ( ...args )
149
- // watcher is recreated on restart
150
- this . unregisterWatcher ( )
151
- this . registerWatcher ( )
152
156
}
153
157
154
158
// since we set `server.hmr: false`, Vite does not auto restart itself
155
159
server . watcher . on ( 'change' , async ( file ) => {
156
160
file = normalize ( file )
157
161
const isConfig = file === server . config . configFile
162
+ || this . resolvedProjects . some ( p => p . server . config . configFile === file )
163
+ || file === this . _workspaceConfigPath
158
164
if ( isConfig ) {
159
165
await Promise . all ( this . _onRestartListeners . map ( fn => fn ( 'config' ) ) )
166
+ this . report ( 'onServerRestart' , 'config' )
167
+ await this . close ( )
160
168
await serverRestart ( )
161
- // watcher is recreated on restart
162
- this . unregisterWatcher ( )
163
- this . registerWatcher ( )
164
169
}
165
170
} )
166
171
}
@@ -175,8 +180,6 @@ export class Vitest {
175
180
}
176
181
catch { }
177
182
178
- await Promise . all ( this . _onSetServer . map ( fn => fn ( ) ) )
179
-
180
183
const projects = await this . resolveWorkspace ( cliOptions )
181
184
this . resolvedProjects = projects
182
185
this . projects = projects
@@ -193,6 +196,8 @@ export class Vitest {
193
196
if ( this . config . testNamePattern ) {
194
197
this . configOverride . testNamePattern = this . config . testNamePattern
195
198
}
199
+
200
+ await Promise . all ( this . _onSetServer . map ( fn => fn ( ) ) )
196
201
}
197
202
198
203
public provide < T extends keyof ProvidedContext & string > ( key : T , value : ProvidedContext [ T ] ) {
@@ -235,7 +240,7 @@ export class Vitest {
235
240
|| this . projects [ 0 ]
236
241
}
237
242
238
- private async getWorkspaceConfigPath ( ) : Promise < string | null > {
243
+ private async getWorkspaceConfigPath ( ) : Promise < string | undefined > {
239
244
if ( this . config . workspace ) {
240
245
return this . config . workspace
241
246
}
@@ -251,7 +256,7 @@ export class Vitest {
251
256
} )
252
257
253
258
if ( ! workspaceConfigName ) {
254
- return null
259
+ return undefined
255
260
}
256
261
257
262
return join ( configDir , workspaceConfigName )
@@ -260,6 +265,8 @@ export class Vitest {
260
265
private async resolveWorkspace ( cliOptions : UserConfig ) {
261
266
const workspaceConfigPath = await this . getWorkspaceConfigPath ( )
262
267
268
+ this . _workspaceConfigPath = workspaceConfigPath
269
+
263
270
if ( ! workspaceConfigPath ) {
264
271
return [ await this . _createCoreProject ( ) ]
265
272
}
0 commit comments