Skip to content

Commit 06a03b0

Browse files
test: fast fail on uncaught exception to produce better error message
It would be better to fail the test on uncaught exception compared to timeout.
1 parent b112e6c commit 06a03b0

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

packages/npm-packages/ruby-wasm-wasi/test-e2e/integrations/browser-script.spec.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import { test, expect, Page } from "@playwright/test";
22

3-
import { setupDebugLog, setupProxy, waitForRubyVM } from "../support";
3+
import { setupDebugLog, setupProxy, setupUncaughtExceptionRejection, expectUncaughtException } from "../support";
44

55
if (!process.env.RUBY_NPM_PACKAGE_ROOT) {
66
test.skip("skip", () => {});
77
} else {
8-
test.beforeEach(async ({ context }) => {
8+
test.beforeEach(async ({ context, page }) => {
99
setupDebugLog(context);
1010
setupProxy(context);
11+
setupUncaughtExceptionRejection(page);
1112
});
1213

1314
const resolveBinding = async (page: Page, name: string) => {
@@ -35,6 +36,8 @@ if (!process.env.RUBY_NPM_PACKAGE_ROOT) {
3536
});
3637

3738
test("JS::Object#await throws error on default attr", async ({ page }) => {
39+
expectUncaughtException(page);
40+
3841
await page.setContent(`
3942
<script src="https://cdn.jsdelivr.net/npm/@ruby/head-wasm-wasi@latest/dist/browser.script.iife.js"></script>
4043
<script type="text/ruby">
@@ -60,4 +63,6 @@ if (!process.env.RUBY_NPM_PACKAGE_ROOT) {
6063
expect(await resolve()).toBe("ok");
6164
});
6265
});
66+
test.describe('data-eval="async" crash', () => {
67+
});
6368
}

packages/npm-packages/ruby-wasm-wasi/test-e2e/support.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,17 @@ export const setupProxy = (context: BrowserContext) => {
2828
});
2929
});
3030
};
31+
32+
export const { setupUncaughtExceptionRejection, expectUncaughtException } = (() => {
33+
const rejectUncaughtException = (err: Error) => {
34+
expect(err).toEqual(undefined);
35+
}
36+
return {
37+
setupUncaughtExceptionRejection: (page: Page) => {
38+
page.on("pageerror", rejectUncaughtException);
39+
},
40+
expectUncaughtException: (page: Page) => {
41+
page.off("pageerror", rejectUncaughtException);
42+
},
43+
}
44+
})()

0 commit comments

Comments
 (0)