Skip to content

Commit e5554f8

Browse files
committed
fix: test logging unhandled rejection from teardown
1 parent d785676 commit e5554f8

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

src/fixtures/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ export const test = base.extend<{
2424

2525
await use(webcontainer);
2626

27+
addEventListener("unhandledrejection", (event) => {
28+
console.log("unhandled rejection", {
29+
reason: event.reason,
30+
type: event.type,
31+
});
32+
});
2733
await webcontainer.teardown();
2834
},
2935
});

src/fixtures/webcontainer.ts

Lines changed: 5 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) => {
@@ -49,6 +50,8 @@ export class WebContainer {
4950
async teardown() {
5051
this._instance.teardown();
5152
this._instancePromise = undefined;
53+
54+
await Promise.all(this._onExit);
5255
}
5356

5457
async runCommand(command: string, args: string[] = []) {
@@ -64,6 +67,8 @@ export class WebContainer {
6467
}),
6568
);
6669

70+
this._onExit.push(process.exit);
71+
6772
await process.exit;
6873

6974
return output.trim();

0 commit comments

Comments
 (0)