|
| 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 |
0 commit comments