Skip to content

Commit acbf323

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

File tree

4 files changed

+34
-38
lines changed

4 files changed

+34
-38
lines changed

packages/npm-packages/ruby-wasm-wasi/test-e2e/examples/examples.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ test.beforeEach(async ({ context, page }) => {
1414
setupDebugLog(context);
1515
setupUncaughtExceptionRejection(page);
1616
if (process.env.RUBY_NPM_PACKAGE_ROOT) {
17-
setupProxy(context, null);
17+
setupProxy(context);
1818
} else {
1919
console.info("Testing against CDN deployed files");
2020
const packagePath = path.join(__dirname, "..", "..", "package.json");

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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 27 additions & 18 deletions
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

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { BrowserContext, Page, Route, expect } from "@playwright/test";
1+
import { BrowserContext, Page, expect } from "@playwright/test";
22
import path from "path";
33

44
export const waitForRubyVM = async (page: Page) => {
@@ -17,18 +17,9 @@ 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\/(.+)/;
31-
3223
context.route(cdnPattern, (route) => {
3324
const request = route.request();
3425
console.log(">> [MOCK]", request.method(), request.url());
@@ -39,13 +30,9 @@ export const setupProxy = (
3930
relativePath,
4031
);
4132

42-
if (customRouter) {
43-
customRouter(route, relativePath, mockedPath);
44-
} else {
45-
route.fulfill({
46-
path: mockedPath,
47-
});
48-
}
33+
route.fulfill({
34+
path: mockedPath,
35+
});
4936
});
5037
};
5138

0 commit comments

Comments
 (0)