Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: test worker update #122

Merged
merged 2 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions examples/web-worker/e2e/basic.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { expect, test } from "@playwright/test";
import { createEditor } from "./helper";

test("basic", async ({ page }) => {
await page.goto("/");
Expand All @@ -23,3 +24,11 @@ test("worker in worker", async ({ page }) => {
"Rendered in web worker in web worker",
);
});

test("reload worker change @dev", async ({ page }) => {
await page.goto("/");
await expect(page.getByTestId("worker-message")).toContainText("dep-ok");
using file = createEditor("./src/worker/dep.tsx");
file.edit((s) => s.replace(`"dep-ok"`, `"dep-edit-ok"`));
await expect(page.getByTestId("worker-message")).toContainText("dep-edit-ok");
});
15 changes: 15 additions & 0 deletions examples/web-worker/e2e/helper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import fs from "node:fs";

export function createEditor(filepath: string) {
let init = fs.readFileSync(filepath, "utf-8");
let data = init;
return {
edit(editFn: (data: string) => string) {
data = editFn(data);
fs.writeFileSync(filepath, data);
},
[Symbol.dispose]() {
fs.writeFileSync(filepath, init);
},
};
}
4 changes: 3 additions & 1 deletion examples/web-worker/playwright.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { defineConfig, devices } from "@playwright/test";

const port = Number(process.env["E2E_PORT"] || 6174);
const command = process.env["E2E_PREVIEW"]
const isPreview = Boolean(process.env["E2E_PREVIEW"]);
const command = isPreview
? `pnpm preview --port ${port} --strict-port`
: `pnpm dev --port ${port} --strict-port`;

Expand All @@ -20,6 +21,7 @@ export default defineConfig({
command,
port,
},
grepInvert: isPreview ? /@dev/ : /@build/,
forbidOnly: !!process.env["CI"],
retries: process.env["CI"] ? 2 : 0,
reporter: "list",
Expand Down