|
| 1 | +/** |
| 2 | + * Fixture path helpers for E2E tests. |
| 3 | + * Automatically selects local or staging fixtures based on PLAYWRIGHT_BASE_URL or BASE_URL. |
| 4 | + * |
| 5 | + * The staging config sets PLAYWRIGHT_BASE_URL via the use.baseURL config. |
| 6 | + * We also check process.argv for --config=staging to detect staging runs. |
| 7 | + */ |
| 8 | + |
| 9 | +const isStaging = |
| 10 | + process.env.PLAYWRIGHT_BASE_URL?.includes('staging') ?? |
| 11 | + process.env.BASE_URL?.includes('staging') ?? |
| 12 | + process.argv.some((arg) => arg.includes('staging')) ?? |
| 13 | + false |
| 14 | + |
| 15 | +type AuthFixture = |
| 16 | + | 'member' |
| 17 | + | 'member-edit' |
| 18 | + | 'member-no-transaction' |
| 19 | + | 'author' |
| 20 | + | 'admin' |
| 21 | + | 'public' |
| 22 | + | 'nobody' |
| 23 | + |
| 24 | +type DataFixture = 'users' | 'transactions' |
| 25 | + |
| 26 | +/** |
| 27 | + * Get the auth fixture path for the current environment. |
| 28 | + * Falls back to 'member' for staging if the specific fixture doesn't exist. |
| 29 | + */ |
| 30 | +export function getAuthFixture(name: AuthFixture): string { |
| 31 | + if (isStaging) { |
| 32 | + const stagingFixtures = ['member', 'author', 'admin'] |
| 33 | + const fixtureName = stagingFixtures.includes(name) ? name : 'member' |
| 34 | + return `e2e/fixtures/auth/staging/${fixtureName}.staging.json` |
| 35 | + } |
| 36 | + return `e2e/fixtures/auth/${name}.local.json` |
| 37 | +} |
| 38 | + |
| 39 | +/** |
| 40 | + * Get the data fixture path for the current environment. |
| 41 | + */ |
| 42 | +export function getDataFixturePath(type: DataFixture, name: string): string { |
| 43 | + const suffix = isStaging ? 'staging' : 'local' |
| 44 | + return `../../e2e/fixtures/${type}/${name}.${suffix}.json` |
| 45 | +} |
| 46 | + |
| 47 | +/** |
| 48 | + * Check if running against staging environment. |
| 49 | + * Can be used as a boolean or as a callback for test.skip() |
| 50 | + */ |
| 51 | +export const isStagingEnv = (): boolean => isStaging |
| 52 | + |
| 53 | +/** |
| 54 | + * Auth fixture paths for direct use in test.use() |
| 55 | + */ |
| 56 | +export const authFixtures = { |
| 57 | + member: getAuthFixture('member'), |
| 58 | + memberEdit: getAuthFixture('member-edit'), |
| 59 | + memberNoTransaction: getAuthFixture('member-no-transaction'), |
| 60 | + author: getAuthFixture('author'), |
| 61 | + admin: getAuthFixture('admin'), |
| 62 | + public: isStaging |
| 63 | + ? 'e2e/fixtures/auth/public.json' |
| 64 | + : 'e2e/fixtures/auth/public.json', |
| 65 | + nobody: isStaging |
| 66 | + ? 'e2e/fixtures/auth/nobody.json' |
| 67 | + : 'e2e/fixtures/auth/nobody.json', |
| 68 | +} |
0 commit comments