Skip to content

Commit c887799

Browse files
authored
fix: terminate all processes before teardown (#4)
1 parent d785676 commit c887799

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/fixtures/webcontainer.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
export 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.map((fn) => fn()));
52+
5053
this._instance.teardown();
5154
this._instancePromise = undefined;
5255
}
@@ -64,6 +67,16 @@ 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+
// @ts-ignore -- internal
73+
if (process._process != null) {
74+
process.kill();
75+
}
76+
77+
return process.exit;
78+
});
79+
6780
await process.exit;
6881

6982
return output.trim();

0 commit comments

Comments
 (0)