File tree Expand file tree Collapse file tree 2 files changed +19
-0
lines changed
Expand file tree Collapse file tree 2 files changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -24,6 +24,15 @@ export const test = base.extend<{
2424
2525 await use ( webcontainer ) ;
2626
27+ addEventListener ( "unhandledrejection" , ( event ) => {
28+ // TODO: Remove, debugging
29+ console . log ( "unhandled rejection" , {
30+ reason : event . reason ,
31+ error : event . reason instanceof Error ,
32+ message : event . reason instanceof Error ? event . reason . message : "nope" ,
33+ type : event . type ,
34+ } ) ;
35+ } ) ;
2736 await webcontainer . teardown ( ) ;
2837 } ,
2938} ) ;
Original file line number Diff line number Diff line change 77export class WebContainer {
88 private _instancePromise ?: WebContainerApi ;
99 private _isReady : Promise < void > ;
10+ private _onExit : ( ( ) => Promise < unknown > ) [ ] = [ ] ;
1011
1112 constructor ( ) {
1213 this . _isReady = WebContainerApi . boot ( { } ) . then ( ( instance ) => {
@@ -47,6 +48,8 @@ export class WebContainer {
4748 }
4849
4950 async teardown ( ) {
51+ await Promise . all ( this . _onExit ) ;
52+
5053 this . _instance . teardown ( ) ;
5154 this . _instancePromise = undefined ;
5255 }
@@ -64,6 +67,13 @@ export class WebContainer {
6467 } ) ,
6568 ) ;
6669
70+ // make sure any long-living processes are terminated before teardown, e.g. "npm run dev" commands
71+ this . _onExit . push ( ( ) => {
72+ process . kill ( ) ;
73+
74+ return process . exit ;
75+ } ) ;
76+
6777 await process . exit ;
6878
6979 return output . trim ( ) ;
You can’t perform that action at this time.
0 commit comments