Skip to content

Commit

Permalink
test: setup e2e
Browse files Browse the repository at this point in the history
  • Loading branch information
hi-ogawa committed Mar 29, 2024
1 parent e6cbf0f commit b0b497f
Show file tree
Hide file tree
Showing 11 changed files with 141 additions and 2 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: ci
"on":
- push
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 20
- run: corepack enable
- run: pnpm i
- run: pnpm lint-check
- run: pnpm tsc
- run: pnpm build
- run: npx playwright install chromium
- run: pnpm -C examples/react-ssr test-e2e
- run: pnpm -C examples/react-ssr build
- run: pnpm -C examples/react-ssr test-e2e-preview
- run: pnpm -C examples/react-server test-e2e
- run: pnpm -C examples/react-server build
- run: pnpm -C examples/react-server test-e2e-preview
9 changes: 9 additions & 0 deletions examples/react-server/e2e/basic.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { test, expect } from "@playwright/test";

test("basic", async ({ page }) => {
await page.goto("/");
await expect(page.locator("#root")).toContainText("hydrated: true");
await expect(page.locator("#root")).toContainText("Count: 0");
await page.getByRole("button", { name: "+" }).click();
await expect(page.locator("#root")).toContainText("Count: 1");
});
2 changes: 2 additions & 0 deletions examples/react-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
"dev": "vite",
"build": "vite build --all",
"preview": "vite preview",
"test-e2e": "playwright test",
"test-e2e-preview": "E2E_PREVIEW=1 playwright test",
"cf-build": "SERVER_ENTRY=/src/adapters/cloudflare-workers.ts pnpm build && bash misc/cloudflare-workers/build.sh",
"cf-preview": "cd misc/cloudflare-workers && wrangler dev",
"cf-release": "cd misc/cloudflare-workers && wrangler deploy"
Expand Down
28 changes: 28 additions & 0 deletions examples/react-server/playwright.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { defineConfig, devices } from "@playwright/test";

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

export default defineConfig({
testDir: "e2e",
use: {
trace: "on-first-retry",
},
projects: [
{
name: "chromium",
use: devices["Desktop Chrome"],
},
],
webServer: {
command,
port,
},
grepInvert: isPreview ? /@dev/ : /@build/,
forbidOnly: !!process.env["CI"],
retries: process.env["CI"] ? 2 : 0,
reporter: "list",
});
4 changes: 3 additions & 1 deletion examples/react-server/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
"include": [
"src",
"vite.config.ts",
"vite-plugin-environment-optimize-deps.ts"
"vite-plugin-environment-optimize-deps.ts",
"e2e",
"playwright.config.ts"
],
"compilerOptions": {
"noUncheckedIndexedAccess": false,
Expand Down
9 changes: 9 additions & 0 deletions examples/react-ssr/e2e/basic.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { test, expect } from "@playwright/test";

test("basic", async ({ page }) => {
await page.goto("/");
await expect(page.locator("#root")).toContainText("hydrated: true");
await expect(page.locator("#root")).toContainText("Count: 0");
await page.getByRole("button", { name: "+" }).click();
await expect(page.locator("#root")).toContainText("Count: 1");
});
2 changes: 2 additions & 0 deletions examples/react-ssr/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
"dev": "vite",
"build": "vite build --all",
"preview": "vite preview",
"test-e2e": "playwright test",
"test-e2e-preview": "E2E_PREVIEW=1 playwright test",
"vc-build": "SERVER_ENTRY=/src/adapters/vercel-edge.ts pnpm build && bash misc/vercel-edge/build.sh",
"vc-release": "vercel deploy --prebuilt misc/vercel-edge --prod"
},
Expand Down
28 changes: 28 additions & 0 deletions examples/react-ssr/playwright.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { defineConfig, devices } from "@playwright/test";

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

export default defineConfig({
testDir: "e2e",
use: {
trace: "on-first-retry",
},
projects: [
{
name: "chromium",
use: devices["Desktop Chrome"],
},
],
webServer: {
command,
port,
},
grepInvert: isPreview ? /@dev/ : /@build/,
forbidOnly: !!process.env["CI"],
retries: process.env["CI"] ? 2 : 0,
reporter: "list",
});
2 changes: 1 addition & 1 deletion examples/react-ssr/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"extends": "@tsconfig/strictest/tsconfig.json",
"include": ["src", "vite.config.ts"],
"include": ["src", "vite.config.ts", "e2e", "playwright.config.ts"],
"compilerOptions": {
"exactOptionalPropertyTypes": false,
"verbatimModuleSyntax": true,
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"devDependencies": {
"@hattip/adapter-node": "^0.0.44",
"@hiogawa/utils": "1.6.4-pre.1",
"@playwright/test": "^1.42.1",
"@tsconfig/strictest": "^2.0.4",
"@types/node": "^20.11.30",
"@vitejs/plugin-react": "^4.2.1",
Expand Down
35 changes: 35 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit b0b497f

Please sign in to comment.