Skip to content
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ on:
types: [opened, synchronize, reopened]

jobs:
test:
example-nextjs:
timeout-minutes: 10
runs-on: ubuntu-latest
steps:
Expand All @@ -23,10 +23,33 @@ jobs:
- uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
with:
node-version: lts/*
- name: Build Docker image
run: docker build -t example-nextjs examples/nextjs
- name: Start container
run: |
docker run -d --name example-nextjs-app -p 3000:3000 \
-e ARCJET_ENV=development \
-e AUTH_SECRET=playwright \
-e AUTH_TRUST_HOST=http://127.0.0.1:3000 \
-e AUTH_GITHUB_ID=playwright \
-e AUTH_GITHUB_SECRET=playwright \
example-nextjs
- name: Install dependencies
run: npm ci
- name: Install Playwright Browsers
run: npx playwright install --with-deps
- name: Wait for server to be ready
run: |
for i in $(seq 1 30); do
if curl -s http://127.0.0.1:3000 > /dev/null 2>&1; then
echo "Server is ready!"
exit 0
fi
echo "Waiting for server... ($i/30)"
sleep 2
done
echo "Server did not start in time"
exit 1
- name: Run Playwright tests
run: npx playwright test
- uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
Expand Down
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -136,4 +136,10 @@ dist
.pnp.*

# Turborepo
.turbo
.turbo

# Playwright
/test-results/
/playwright-report/
/blob-report/
/playwright/.cache/
6 changes: 0 additions & 6 deletions examples/nextjs/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,3 @@ yarn-error.log*

.contentlayer
.env

# Playwright
/test-results/
/playwright-report/
/blob-report/
/playwright/.cache/
63 changes: 0 additions & 63 deletions examples/nextjs/package-lock.json

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

5 changes: 1 addition & 4 deletions examples/nextjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@
"build": "next build",
"start": "next start",
"lint": "next lint",
"lint:fix": "next lint --fix",
"test:open": "playwright test --ui-host=0.0.0.0",
"test:run": "playwright test"
"lint:fix": "next lint --fix"
},
"dependencies": {
"@arcjet/decorate": "1.3.0",
Expand All @@ -44,7 +42,6 @@
"zod": "4.3.6"
},
"devDependencies": {
"@playwright/test": "1.58.2",
"@types/node": "22.19.11",
"@types/react": "19.2.13",
"@types/react-dom": "19.2.3",
Expand Down
21 changes: 11 additions & 10 deletions examples/nextjs/tests/screenshots.test.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import { expect, test } from "@playwright/test";

// @ts-ignore build manifest may or may not exist
import appPathManifest from "../.next/app-path-routes-manifest.json";

const manifest = appPathManifest as Record<string, string>;

for (const [file, pathname] of Object.entries(manifest)) {
// Skip over dynamic and api routes
if (file.endsWith("/route") || file === "/_not-found/page") {
continue;
}
const paths = [
"/",
"/attack",
"/bots",
"/rate-limiting",
"/sensitive-info",
"/sensitive-info/submitted",
"/signup",
"/signup/submitted",
];

for (const pathname of paths) {
test(`"${pathname}" screenshot matches`, async ({ page }) => {
const response = await page.goto(pathname);
await expect(response?.status()).toEqual(200);
Expand Down
72 changes: 68 additions & 4 deletions package-lock.json

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

7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
{
"devDependencies": {
"@playwright/test": "1.58.2",
"@types/node": "24.10.1",
"npm-check-updates": "19.3.2",
"simple-git": "3.30.0",
"simple-git": "3.32.3",
"typescript": "5.9.3"
},
"name": "@arcjet-examples/root",
"packageManager": "npm@11.6.4",
"private": true,
"scripts": {
"prepare-to-publish": "node scripts/prepare-to-publish.ts",
"sort-staged-imports": "npx @biomejs/biome check --formatter-enabled=false --linter-enabled=false --staged --write"
"sort-staged-imports": "npx @biomejs/biome check --formatter-enabled=false --linter-enabled=false --staged --write",
"test:open": "playwright test --ui-host=0.0.0.0",
"test:run": "playwright test"
},
"type": "module",
"version": "0.0.0"
Expand Down
31 changes: 17 additions & 14 deletions examples/nextjs/playwright.config.ts → playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { defineConfig, devices } from "@playwright/test";
* See https://playwright.dev/docs/test-configuration.
*/
export default defineConfig({
testDir: "./tests",
testDir: "./examples/nextjs/tests",
/* Run tests in files in parallel */
fullyParallel: true,
/* Fail the build on CI if you accidentally left test.only in the source code. */
Expand All @@ -18,7 +18,7 @@ export default defineConfig({
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
use: {
/* Base URL to use in actions like `await page.goto('/')`. */
baseURL: "http://127.0.0.1:4000",
baseURL: "http://127.0.0.1:3000",

/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
trace: "on-first-retry",
Expand Down Expand Up @@ -53,16 +53,19 @@ export default defineConfig({
],

/* Run your local dev server before starting the tests */
webServer: {
command: "npm run build && npm run start -- -p 4000",
url: "http://127.0.0.1:4000",
reuseExistingServer: !process.env.CI,
env: {
ARCJET_ENV: "development",
AUTH_SECRET: "playwright",
AUTH_TRUST_HOST: "http://127.0.0.1:4000",
AUTH_GITHUB_ID: "playwright",
AUTH_GITHUB_SECRET: "playwright",
},
},
webServer: process.env.CI
? undefined
: {
command: "npm run build && npm run start -- -p 3000",
url: "http://127.0.0.1:3000",
reuseExistingServer: true,
cwd: "./examples/nextjs",
env: {
ARCJET_ENV: "development",
AUTH_SECRET: "playwright",
AUTH_TRUST_HOST: "http://127.0.0.1:3000",
AUTH_GITHUB_ID: "playwright",
AUTH_GITHUB_SECRET: "playwright",
},
},
});
Loading