Files
SkinbaseNova/tests/cpad/auth.setup.ts
2026-03-12 07:22:38 +01:00

29 lines
903 B
TypeScript

/**
* cPad Authentication Setup
*
* This file is matched by the `cpad-setup` Playwright project (see playwright.config.ts).
* It runs ONCE before all cpad tests, logs in as admin, and saves the browser
* storage state to tests/.auth/admin.json so subsequent tests skip the login step.
*
* Run only this setup step:
* npx playwright test --project=cpad-setup
*/
import { test as setup } from '@playwright/test';
import { loginAsAdmin, AUTH_FILE } from '../helpers/auth';
import fs from 'fs';
import path from 'path';
setup('authenticate as cPad admin', async ({ page }) => {
// Ensure the .auth directory exists
const authDir = path.dirname(AUTH_FILE);
if (!fs.existsSync(authDir)) {
fs.mkdirSync(authDir, { recursive: true });
}
await loginAsAdmin(page);
// Persist cookies + localStorage for the cpad project
await page.context().storageState({ path: AUTH_FILE });
});