import { test as setup } from '@playwright/test'; import * as fs from 'fs'; import * as path from 'path'; import { performOAuthLogin } from './helpers'; const authFile = 'tests/playwright/.auth/user.json'; setup('authenticate', async ({ page }) => { console.log('[Auth Setup] Starting OAuth authentication flow'); // Clear any existing auth state file to ensure fresh login if (fs.existsSync(authFile)) { fs.unlinkSync(authFile); console.log('[Auth Setup] Cleared existing auth state'); } // Perform OAuth login using reusable helper await performOAuthLogin(page); // Ensure the auth directory exists const authDir = path.dirname(authFile); if (!fs.existsSync(authDir)) { fs.mkdirSync(authDir, { recursive: true }); } // Save authenticated state await page.context().storageState({ path: authFile }); console.log(`[Auth Setup] Saved authentication state to ${authFile}`); });