Skip to content

Commit 9167ea3

Browse files
committed
feat(e2e): add staging E2E testing infrastructure
- Create playwright.staging.config.ts with staging baseURL and increased timeouts - Add playwright-staging-setup.ts for auth fixture validation - Create e2e/fixtures/auth/staging/ directory structure - Add npm script test:e2e:staging - Document staging E2E workflow in docs/testing-principles.md - Update CLAUDE.md with staging test command - Add *.staging.json to .gitignore for auth fixtures
1 parent c969577 commit 9167ea3

7 files changed

Lines changed: 136 additions & 0 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ coverage
2020

2121
# Playwright
2222
*.local.*
23+
*.staging.json
2324
test-results
2425
playwright-report
2526

CLAUDE.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ npm run build # Production build
1616
# Testing
1717
npm test # Vitest unit tests
1818
npm run test:e2e:run # Playwright E2E tests
19+
npm run test:e2e:staging # E2E tests against staging (requires auth fixtures)
1920

2021
# Code Quality
2122
npm run lint # ESLint

docs/testing-principles.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,51 @@ test.use({
216216
})
217217
```
218218

219+
### Staging E2E Tests
220+
221+
Run E2E tests against the staging environment to validate deployments:
222+
223+
```bash
224+
# Run staging E2E tests
225+
npm run test:e2e:staging
226+
```
227+
228+
#### Setting Up Staging Authentication
229+
230+
Since staging uses real email delivery, auth fixtures must be created manually:
231+
232+
1. Login to https://staging.kelas.rumahberbagi.com in your browser
233+
2. Open DevTools > Application > Storage > Cookies
234+
3. Export cookies using a browser extension (e.g., "EditThisCookie")
235+
4. Save to `e2e/fixtures/auth/staging/<role>.staging.json` in this format:
236+
237+
```json
238+
{
239+
"cookies": [
240+
{
241+
"name": "__session",
242+
"value": "...",
243+
"domain": "staging.kelas.rumahberbagi.com",
244+
"path": "/",
245+
"expires": -1,
246+
"httpOnly": true,
247+
"secure": true,
248+
"sameSite": "Lax"
249+
}
250+
],
251+
"origins": []
252+
}
253+
```
254+
255+
Required auth fixtures:
256+
257+
- `member.staging.json` - Regular member
258+
- `author.staging.json` - Course author
259+
- `admin.staging.json` - Administrator
260+
261+
**Note:** Auth fixtures are gitignored and must be recreated when sessions
262+
expire.
263+
219264
### Best Practices
220265

221266
1. **Test user journeys** - Focus on complete user flows

e2e/fixtures/auth/staging/.gitkeep

Whitespace-only changes.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"test:e2e:dev": "cross-env RUNNING_E2E=true start-server-and-test dev http-get://localhost:3000/ test:e2e",
2929
"test:e2e:run": "cross-env RUNNING_E2E=true DATABASE_URL=file:./test.db start-server-and-test start:e2e http-get://localhost:3000/ test:e2e",
3030
"test:e2e:docker": "playwright test --config=playwright.docker.config.ts",
31+
"test:e2e:staging": "playwright test --config=playwright.staging.config.ts",
3132
"test:e2e:production": "cross-env BASE_URL=https://kelas.rumahberbagi.com playwright test --config=playwright.docker.config.ts",
3233
"type-check": "tsc --noEmit",
3334
"setup": "npm install && prisma migrate reset --force && npm run test:e2e:run",

playwright-staging-setup.ts

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import fs from 'node:fs'
2+
import path from 'node:path'
3+
4+
const STAGING_AUTH_DIR = 'e2e/fixtures/auth/staging'
5+
const REQUIRED_AUTH_FILES = [
6+
'member.staging.json',
7+
'author.staging.json',
8+
'admin.staging.json',
9+
]
10+
11+
/**
12+
* Global setup for staging E2E tests.
13+
*
14+
* Unlike local tests, staging authentication cannot be automated via magic link
15+
* because emails are sent to real addresses. Instead, this setup validates that
16+
* manually-exported auth fixtures exist.
17+
*
18+
* To create auth fixtures for staging:
19+
* 1. Login to https://staging.kelas.rumahberbagi.com in your browser
20+
* 2. Open DevTools > Application > Storage > Cookies
21+
* 3. Export the cookies using browser extension or manually copy them
22+
* 4. Save to e2e/fixtures/auth/staging/<role>.staging.json in Playwright's
23+
* storageState format:
24+
* {
25+
* "cookies": [{ "name": "...", "value": "...", "domain": "...", ... }],
26+
* "origins": []
27+
* }
28+
*/
29+
async function globalSetup() {
30+
if (!fs.existsSync(STAGING_AUTH_DIR)) {
31+
fs.mkdirSync(STAGING_AUTH_DIR, { recursive: true })
32+
console.log(`Created staging auth directory: ${STAGING_AUTH_DIR}`)
33+
}
34+
35+
const missingFiles: string[] = []
36+
37+
for (const file of REQUIRED_AUTH_FILES) {
38+
const filePath = path.join(STAGING_AUTH_DIR, file)
39+
if (!fs.existsSync(filePath)) {
40+
missingFiles.push(file)
41+
}
42+
}
43+
44+
if (missingFiles.length > 0) {
45+
console.warn('\n⚠️ Missing staging auth fixtures:')
46+
for (const file of missingFiles) {
47+
console.warn(` - ${STAGING_AUTH_DIR}/${file}`)
48+
}
49+
console.warn(
50+
'\nSee playwright-staging-setup.ts for instructions on creating these files.\n'
51+
)
52+
}
53+
54+
console.log('✓ Staging global setup complete')
55+
}
56+
57+
export default globalSetup

playwright.staging.config.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { PlaywrightTestConfig, devices } from '@playwright/test'
2+
import { Fixtures } from './e2e/base-test'
3+
4+
const config: PlaywrightTestConfig<Fixtures> = {
5+
forbidOnly: true,
6+
retries: 0,
7+
testDir: './e2e',
8+
globalSetup: require.resolve('./playwright-staging-setup'),
9+
globalTimeout: 15 * 60 * 1000,
10+
timeout: 60 * 1000,
11+
expect: {
12+
timeout: 10 * 1000,
13+
},
14+
use: {
15+
trace: 'on-first-retry',
16+
baseURL: 'https://staging.kelas.rumahberbagi.com',
17+
actionTimeout: 15 * 1000,
18+
navigationTimeout: 30 * 1000,
19+
},
20+
projects: [
21+
{
22+
name: 'chromium',
23+
use: { ...devices['Desktop Chrome'] },
24+
},
25+
{
26+
name: 'firefox',
27+
use: { ...devices['Desktop Firefox'] },
28+
},
29+
],
30+
}
31+
export default config

0 commit comments

Comments
 (0)