Skip to content

Commit 1b38a5e

Browse files
committed
Run e2e with bundled codes
1 parent 7f7deb4 commit 1b38a5e

File tree

35 files changed

+4040
-198
lines changed

35 files changed

+4040
-198
lines changed

.github/workflows/check.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,4 @@ jobs:
2626
- run: npm run test
2727

2828
- run: npx playwright install chromium
29-
- run: npm run test-ct
29+
- run: npm run e2e

playwright/index.html renamed to e2e/index.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
<title>Testing Page</title>
77
</head>
88
<body>
9-
<div id="root"></div>
10-
<script type="module" src="./index.tsx"></script>
9+
<div id="rnrb-root"></div>
1110
</body>
1211
</html>

e2e/index.spec.tsx

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,44 @@
1-
import { test, expect } from "@playwright/experimental-ct-react";
1+
import { test, expect } from "@playwright/test";
2+
import { readdirSync } from "node:fs";
3+
import path from "node:path";
4+
import { bundle } from "../src/plugin/bundler";
5+
import { WEB_ROOT_ID } from "../src/constants";
26

3-
test.use({ viewport: { width: 500, height: 1000 } });
7+
test.beforeEach(async ({}, testInfo) => {
8+
// https://github.com/microsoft/playwright/issues/7575#issuecomment-1168800666
9+
testInfo.snapshotSuffix = "";
10+
});
11+
12+
test.describe("smoke webview code", () => {
13+
const fixturePath = path.join(process.cwd(), "fixtures");
14+
readdirSync(fixturePath).forEach((filename) => {
15+
if (filename.endsWith(".jsx") || filename.endsWith(".tsx")) {
16+
test(filename, async ({ page }) => {
17+
await page.goto("localhost:3000");
18+
19+
const code = await bundle(path.join(fixturePath, filename));
20+
21+
const rootHandle = await page.waitForFunction(
22+
(id) => document.getElementById(id)!,
23+
WEB_ROOT_ID
24+
);
25+
26+
await page.evaluate((code) => {
27+
const script = document.createElement("script");
28+
script.type = "text/javascript";
29+
script.onload = eval(code);
30+
31+
document.head.appendChild(script);
32+
}, code);
433

5-
test("should work", async ({ mount }) => {
6-
const component = await mount(<div>Learn React</div>);
7-
await expect(component).toContainText("Learn React");
34+
await page.waitForFunction((e) => e.innerHTML, rootHandle);
35+
await expect(
36+
await rootHandle.evaluate((e) => e.innerHTML)
37+
).toMatchSnapshot();
38+
await expect(
39+
await page.evaluate(() => document.head.innerHTML)
40+
).toMatchSnapshot();
41+
});
42+
}
43+
});
844
});
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<div style="background: red; width: 100vw; height: 100vh;">hoge</div>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
<meta charset="UTF-8">
3+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
4+
<title>Testing Page</title>
5+
<script type="text/javascript"></script>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<div style="background: red; width: 100vw; height: 100vh;">hoge</div>

0 commit comments

Comments
 (0)