Playwright E2E
Check that your form works in a real browser, with and without JavaScript. This recipe uses Playwright 1.56.0 and Chromium.
Start the fixture and wait for readiness
ts
import { defineConfig } from "@playwright/test";
import { fileURLToPath } from "node:url";
export default defineConfig({
testDir: "./e2e",
fullyParallel: false,
workers: 1,
use: { baseURL: "http://127.0.0.1:3107" },
webServer: {
command: "node --import tsx docs/samples/island/start.ts",
cwd: fileURLToPath(new URL("../..", import.meta.url)),
url: "http://127.0.0.1:3107",
reuseExistingServer: false,
},
});This bounded fixture uses port 3107 and refuses to reuse an unrelated server. The HTTP unit tests use ephemeral ports; Playwright's fixture has a configured origin so the browser can navigate predictably.
Exercise both experiences
ts
import { test, expect } from "@playwright/test";
test("Svelte counter enhances the native form", async ({ page }) => {
await page.goto("/");
await expect(page.locator("#note-counter")).toContainText("0 / 200 characters");
await page.getByLabel("Note", { exact: true }).fill("Hello island");
await expect(page.locator("#note-counter")).toContainText("12 / 200 characters");
await page.getByRole("button", { name: "Save note" }).click();
await expect(page.locator("main > ul")).toContainText("Hello island");
});
test("native submission and retained errors work with JavaScript disabled", async ({
browser,
baseURL,
}) => {
const context = await browser.newContext({ javaScriptEnabled: false, baseURL });
try {
const page = await context.newPage();
await page.goto("/");
await page.getByLabel("Note", { exact: true }).fill(" ");
const invalid = page.waitForResponse(
(response) => response.url().endsWith("/notes") && response.request().method() === "POST",
);
await page.getByRole("button", { name: "Save note" }).click();
expect((await invalid).status()).toBe(422);
await expect(page.getByRole("alert")).toContainText("Write between 1 and 200 characters");
await expect(page.getByLabel("Note", { exact: true })).toHaveValue(" ");
await page.getByLabel("Note", { exact: true }).fill("No JavaScript needed");
await page.getByRole("button", { name: "Save note" }).click();
await expect(page.locator("main > ul")).toContainText("No JavaScript needed");
} finally {
await context.close();
}
});Label/role locators exercise the accessible control markup. The no-JS test checks the actual 422 response and retained value, not just the presence of a button.
sh
npm run build:packages
npm run docs:check
npx playwright install chromium
npm run docs:e2eOn Linux CI, install browser system libraries with npx playwright install --with-deps chromium; .github/workflows/docs.yml does this before running the same tests.
Test hosted sign-in separately with a configured provider.