Skip to content

Commit d422162

Browse files
committed
chore(playwright): add initial playwright support
1 parent 24b08f7 commit d422162

File tree

46 files changed

+194
-3
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+194
-3
lines changed

.github/workflows/playwright.yml

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: Playwright Tests
2+
3+
permissions:
4+
contents: read
5+
6+
on:
7+
push:
8+
branches: [main]
9+
pull_request:
10+
branches: [main]
11+
types: [opened, synchronize, reopened]
12+
13+
jobs:
14+
test:
15+
timeout-minutes: 10
16+
runs-on: ubuntu-latest
17+
steps:
18+
- uses: actions/checkout@v4
19+
- uses: actions/setup-node@v4
20+
with:
21+
node-version: lts/*
22+
- name: Install dependencies
23+
run: npm ci
24+
- name: Install Playwright Browsers
25+
run: npx playwright install --with-deps
26+
- name: Run Playwright tests
27+
run: npx playwright test
28+
- uses: actions/upload-artifact@v4
29+
if: ${{ !cancelled() }}
30+
with:
31+
name: playwright-report
32+
path: playwright-report/
33+
retention-days: 30

.gitignore

+7-1
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,10 @@ yarn-error.log*
3333
.turbo
3434

3535
.contentlayer
36-
.env
36+
.env
37+
38+
# Playwright
39+
/test-results/
40+
/playwright-report/
41+
/blob-report/
42+
/playwright/.cache/

package-lock.json

+64
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+5-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@
2626
"build": "next build",
2727
"start": "next start",
2828
"lint": "next lint",
29-
"lint:fix": "next lint --fix"
29+
"lint:fix": "next lint --fix",
30+
"test:open": "playwright test --ui-host=0.0.0.0",
31+
"test:run": "playwright test"
3032
},
3133
"dependencies": {
3234
"@arcjet/decorate": "^1.0.0-beta.5",
@@ -52,6 +54,7 @@
5254
"zod": "^3.24.2"
5355
},
5456
"devDependencies": {
57+
"@playwright/test": "^1.52.0",
5558
"@types/node": "^22",
5659
"@types/react": "^19",
5760
"@types/react-dom": "^19",
@@ -67,4 +70,4 @@
6770
"tailwindcss": "^3",
6871
"typescript": "^5"
6972
}
70-
}
73+
}

playwright.config.ts

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import { defineConfig, devices } from "@playwright/test";
2+
3+
/**
4+
* See https://playwright.dev/docs/test-configuration.
5+
*/
6+
export default defineConfig({
7+
testDir: "./tests",
8+
/* Run tests in files in parallel */
9+
fullyParallel: true,
10+
/* Fail the build on CI if you accidentally left test.only in the source code. */
11+
forbidOnly: !!process.env.CI,
12+
/* Retry on CI only */
13+
retries: process.env.CI ? 2 : 0,
14+
/* Opt out of parallel tests on CI. */
15+
workers: process.env.CI ? 1 : undefined,
16+
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
17+
reporter: [["html", { host: "0.0.0.0" }]],
18+
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
19+
use: {
20+
/* Base URL to use in actions like `await page.goto('/')`. */
21+
baseURL: "http://127.0.0.1:4000",
22+
23+
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
24+
trace: "on-first-retry",
25+
},
26+
27+
/* Configure projects for major browsers */
28+
projects: [
29+
{
30+
name: "chromium",
31+
use: { ...devices["Desktop Chrome"] },
32+
},
33+
34+
{
35+
name: "firefox",
36+
use: { ...devices["Desktop Firefox"] },
37+
},
38+
39+
{
40+
name: "webkit",
41+
use: { ...devices["Desktop Safari"] },
42+
},
43+
44+
/* Test against mobile viewports. */
45+
{
46+
name: "Mobile Chrome",
47+
use: { ...devices["Pixel 5"] },
48+
},
49+
{
50+
name: "Mobile Safari",
51+
use: { ...devices["iPhone 12"] },
52+
},
53+
],
54+
55+
/* Run your local dev server before starting the tests */
56+
webServer: {
57+
command: "npm run build && npm run start -- -p 4000",
58+
url: "http://127.0.0.1:4000",
59+
reuseExistingServer: !process.env.CI,
60+
env: {
61+
ARCJET_ENV: "development",
62+
AUTH_SECRET: "playwright",
63+
AUTH_TRUST_HOST: "http://127.0.0.1:4000",
64+
},
65+
},
66+
});

tests/screenshots.test.ts

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { test, expect } from "@playwright/test";
2+
3+
// @ts-ignore build manifest may or may not exist
4+
import appPathManifest from "../.next/app-path-routes-manifest.json";
5+
6+
const manifest = appPathManifest as Record<string, string>;
7+
8+
for (const [file, pathname] of Object.entries(manifest)) {
9+
// Skip over dynamic and api routes
10+
if (file.endsWith("/route") || file === "/_not-found/page") {
11+
continue;
12+
}
13+
14+
test(`"${pathname}" screenshot matches`, async ({ page }) => {
15+
const response = await page.goto(pathname);
16+
await expect(response?.status()).toEqual(200);
17+
await expect(page).toHaveScreenshot({ maxDiffPixelRatio: 0.01 });
18+
});
19+
}

0 commit comments

Comments
 (0)