@@ -149,27 +149,32 @@ export class TestRunner {
149
149
. then ( ( result ) => {
150
150
if ( mode === 'nonblocking' ) {
151
151
this . #onClose?.( result . exitCode )
152
- this . #watcher?. close ( )
153
- this . #assetsServer?. stop ( )
152
+ this . close ( )
154
153
}
155
154
} )
156
155
. catch ( ( error ) => {
157
- /**
158
- * Since the tests runner set the `process.exitCode = 1`, execa will
159
- * throw an exception. However, we should ignore it and keep the
160
- * watcher on.
161
- */
162
156
if ( mode === 'nonblocking' ) {
163
157
this . #onError?.( error )
164
- this . #watcher?. close ( )
165
- this . #assetsServer?. stop ( )
158
+ this . close ( )
166
159
}
167
160
} )
168
161
. finally ( ( ) => {
169
162
this . #isBusy = false
170
163
} )
171
164
}
172
165
166
+ /**
167
+ * Restarts the HTTP server
168
+ */
169
+ #rerunTests( port : string , filtersArgs : string [ ] ) {
170
+ if ( this . #testScript) {
171
+ this . #testScript. removeAllListeners ( )
172
+ this . #testScript. kill ( 'SIGKILL' )
173
+ }
174
+
175
+ this . #runTests( port , filtersArgs , 'blocking' )
176
+ }
177
+
173
178
/**
174
179
* Starts the assets server
175
180
*/
@@ -190,7 +195,7 @@ export class TestRunner {
190
195
if ( isDotEnvFile ( relativePath ) || this . #isMetaFile( relativePath ) ) {
191
196
this . #clearScreen( )
192
197
this . #logger. log ( `${ this . #colors. green ( action ) } ${ relativePath } ` )
193
- this . #runTests ( port , filters , 'blocking' )
198
+ this . #rerunTests ( port , filters )
194
199
}
195
200
}
196
201
@@ -210,18 +215,17 @@ export class TestRunner {
210
215
* then only run that file
211
216
*/
212
217
if ( this . #isTestFile( relativePath ) ) {
213
- this . #runTests (
218
+ this . #rerunTests (
214
219
port ,
215
220
this . #convertFiltersToArgs( {
216
221
...this . #options. filters ,
217
222
files : [ relativePath ] ,
218
- } ) ,
219
- 'blocking'
223
+ } )
220
224
)
221
225
return
222
226
}
223
227
224
- this . #runTests ( port , filters , 'blocking' )
228
+ this . #rerunTests ( port , filters )
225
229
}
226
230
227
231
/**
@@ -251,6 +255,18 @@ export class TestRunner {
251
255
return this
252
256
}
253
257
258
+ /**
259
+ * Close watchers and running child processes
260
+ */
261
+ async close ( ) {
262
+ await this . #watcher?. close ( )
263
+ this . #assetsServer?. stop ( )
264
+ if ( this . #testScript) {
265
+ this . #testScript. removeAllListeners ( )
266
+ this . #testScript. kill ( 'SIGKILL' )
267
+ }
268
+ }
269
+
254
270
/**
255
271
* Runs tests
256
272
*/
0 commit comments