diff --git a/frontend/.gitignore b/frontend/.gitignore index 96a2ef4a..6a5f9f9d 100644 --- a/frontend/.gitignore +++ b/frontend/.gitignore @@ -1,4 +1,10 @@ test-results +# Playwright E2E: no versionar sesión, reportes ni estado compartido generado +e2e/.auth/user.json +e2e/.e2e-*.json +playwright-report/ +blob-report/ + node_modules # Output diff --git a/frontend/e2e/auth.setup.ts b/frontend/e2e/auth.setup.ts index 4fcbb08b..bbed9b43 100644 --- a/frontend/e2e/auth.setup.ts +++ b/frontend/e2e/auth.setup.ts @@ -1,4 +1,5 @@ import { test as setup } from '@playwright/test' +import { mkdirSync } from 'node:fs' import { fileURLToPath } from 'url' import path from 'path' @@ -11,5 +12,6 @@ setup('autenticacion', async ({ page }) => { await page.locator('input[id^="password"]').fill('demo123') await page.click('button[type="submit"]') await page.waitForURL(/dashboard/, { timeout: 60000 }) + mkdirSync(path.dirname(authFile), { recursive: true }) await page.context().storageState({ path: authFile }) }) \ No newline at end of file diff --git a/frontend/playwright.config.ts b/frontend/playwright.config.ts index cbe14e8f..c84ea18b 100644 --- a/frontend/playwright.config.ts +++ b/frontend/playwright.config.ts @@ -4,24 +4,33 @@ import path from 'path'; const __dirname = path.dirname(fileURLToPath(import.meta.url)); +const authStatePath = path.join(__dirname, 'e2e/.auth/user.json'); +/** GitHub/Gitea/GitLab suelen exportar CI=true; Jenkins no siempre, pero define JENKINS_URL. */ +const inCI = process.env.CI === 'true' || Boolean(process.env.JENKINS_URL); + export default defineConfig({ + // En CI, falla si queda un .only; en local no + forbidOnly: inCI, timeout: 60000, use: { baseURL: 'http://localhost:5173', - headless: false, - storageState: path.join(__dirname, 'e2e/.auth/user.json') + // Sin display en agentes de integración: obligatorio headless + headless: inCI ? true : false }, workers: 1, testDir: 'e2e', projects: [ { name: 'setup', - testMatch: '**/auth.setup.ts' + testMatch: '**/auth.setup.ts', + // Navegador limpio: user.json se genera aquí y no debe existir al primer run / en CI + use: { storageState: { cookies: [], origins: [] } } }, { name: 'tests', dependencies: ['setup'], - testIgnore: ['**/auth.setup.ts', '**/demo.test.ts'] + testIgnore: ['**/auth.setup.ts', '**/demo.test.ts'], + use: { storageState: authStatePath } } ] }); \ No newline at end of file