Skip to content

Commit

Permalink
Take snapshot of bundled codes
Browse files Browse the repository at this point in the history
  • Loading branch information
inokawa committed May 6, 2024
1 parent 7f7deb4 commit 47f65a9
Show file tree
Hide file tree
Showing 34 changed files with 4,034 additions and 197 deletions.
3 changes: 1 addition & 2 deletions playwright/index.html → e2e/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
<title>Testing Page</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="./index.tsx"></script>
<div id="rnrb-root"></div>
</body>
</html>
41 changes: 36 additions & 5 deletions e2e/index.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,39 @@
import { test, expect } from "@playwright/experimental-ct-react";
import { test, expect } from "@playwright/test";
import { readdirSync } from "node:fs";
import path from "node:path";
import { bundle } from "../src/plugin/bundler";
import { WEB_ROOT_ID } from "../src/constants";

test.use({ viewport: { width: 500, height: 1000 } });
test.describe("smoke webview code", () => {
const fixturePath = path.join(process.cwd(), "fixtures");
readdirSync(fixturePath).forEach((filename) => {
if (filename.endsWith(".jsx") || filename.endsWith(".tsx")) {
test(filename, async ({ page }) => {
await page.goto("localhost:3000");

test("should work", async ({ mount }) => {
const component = await mount(<div>Learn React</div>);
await expect(component).toContainText("Learn React");
const code = await bundle(path.join(fixturePath, filename));

const rootHandle = await page.waitForFunction(
(id) => document.getElementById(id)!,
WEB_ROOT_ID
);

await page.evaluate((code) => {
const script = document.createElement("script");
script.type = "text/javascript";
script.onload = eval(code);

document.head.appendChild(script);
}, code);

await page.waitForFunction((e) => e.innerHTML, rootHandle);
await expect(
await rootHandle.evaluate((e) => e.innerHTML)
).toMatchSnapshot();
await expect(
await page.evaluate(() => document.head.innerHTML)
).toMatchSnapshot();
});
}
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<div style="background: red; width: 100vw; height: 100vh;">hoge</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Testing Page</title>
<script type="text/javascript"></script>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<div style="background: red; width: 100vw; height: 100vh;">hoge</div>
Loading

0 comments on commit 47f65a9

Please sign in to comment.