Skip to content

Commit 9e4d637

Browse files
committed
Stop extending setupProxy. Add Playwright routing instead.
1 parent 115dea3 commit 9e4d637

File tree

3 files changed

+32
-35
lines changed

3 files changed

+32
-35
lines changed

packages/npm-packages/ruby-wasm-wasi/test-e2e/integrations/data-eval-async.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ if (!process.env.RUBY_NPM_PACKAGE_ROOT) {
1313
} else {
1414
test.beforeEach(async ({ context, page }) => {
1515
setupDebugLog(context);
16-
setupProxy(context, null);
16+
setupProxy(context);
1717
setupUncaughtExceptionRejection(page);
1818
});
1919

packages/npm-packages/ruby-wasm-wasi/test-e2e/integrations/js-require-remote.spec.ts

+27-18
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,35 @@
11
import fs from "fs";
22
import path from "path";
33
import { test, expect } from "@playwright/test";
4-
import { setupDebugLog, setupProxy, resolveBinding } from "../support";
4+
import {
5+
setupDebugLog,
6+
setupProxy,
7+
setupUncaughtExceptionRejection,
8+
expectUncaughtException,
9+
resolveBinding,
10+
} from "../support";
511

612
if (!process.env.RUBY_NPM_PACKAGE_ROOT) {
713
test.skip("skip", () => {});
814
} else {
9-
test.beforeEach(async ({ context }) => {
15+
test.beforeEach(async ({ context, page }) => {
1016
setupDebugLog(context);
11-
setupProxy(context, (route, relativePath, mockedPath) => {
12-
if (relativePath.match("fixtures")) {
13-
route.fulfill({
14-
path: path.join("./test-e2e/integrations", relativePath),
15-
});
16-
} else if (fs.existsSync(mockedPath)) {
17-
route.fulfill({
18-
path: mockedPath,
19-
});
20-
} else {
21-
route.fulfill({
22-
status: 404,
23-
});
24-
}
17+
setupProxy(context);
18+
19+
context.route(/fixtures/, (route) => {
20+
const filename = path.basename(route.request().url());
21+
route.fulfill({
22+
path: path.join("./test-e2e/integrations/fixtures", filename),
23+
});
24+
});
25+
26+
context.route(/not_found/, (route) => {
27+
route.fulfill({
28+
status: 404,
29+
});
2530
});
31+
32+
setupUncaughtExceptionRejection(page);
2633
});
2734

2835
test.describe("JS::RequireRemote#load", () => {
@@ -64,6 +71,8 @@ if (!process.env.RUBY_NPM_PACKAGE_ROOT) {
6471
test("JS::RequireRemote#load throws error when gem is not found", async ({
6572
page,
6673
}) => {
74+
expectUncaughtException(page);
75+
6776
// Opens the URL that will be used as the basis for determining the relative URL.
6877
await page.goto(
6978
"https://cdn.jsdelivr.net/npm/@ruby/head-wasm-wasi@latest/dist/",
@@ -73,12 +82,12 @@ if (!process.env.RUBY_NPM_PACKAGE_ROOT) {
7382
</script>
7483
<script type="text/ruby" data-eval="async">
7584
require 'js/require_remote'
76-
JS::RequireRemote.instance.load 'foo'
85+
JS::RequireRemote.instance.load 'not_found'
7786
</script>
7887
`);
7988

8089
const error = await page.waitForEvent("pageerror");
81-
expect(error.message).toMatch(/cannot load such url -- .+\/foo.rb/);
90+
expect(error.message).toMatch(/cannot load such url -- .+\/not_found.rb/);
8291
});
8392
});
8493
}

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

+4-16
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,7 @@ export const setupDebugLog = (context: BrowserContext) => {
1717
}
1818
};
1919

20-
type CustomRouter = (
21-
route: Route,
22-
relativePath: string,
23-
mockedPath: string,
24-
) => void;
25-
export const setupProxy = (
26-
context: BrowserContext,
27-
customRouter: CustomRouter | null,
28-
) => {
20+
export const setupProxy = (context: BrowserContext) => {
2921
const cdnPattern =
3022
/cdn.jsdelivr.net\/npm\/@ruby\/.+-wasm-wasi@.+\/dist\/(.+)/;
3123

@@ -39,13 +31,9 @@ export const setupProxy = (
3931
relativePath,
4032
);
4133

42-
if (customRouter) {
43-
customRouter(route, relativePath, mockedPath);
44-
} else {
45-
route.fulfill({
46-
path: mockedPath,
47-
});
48-
}
34+
route.fulfill({
35+
path: mockedPath,
36+
});
4937
});
5038
};
5139

0 commit comments

Comments
 (0)