import { defineConfig } from '@playwright/test';
import { fileURLToPath } from 'node:url';
import path from 'node: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: 60_000,
    use: {
        baseURL: process.env.PLAYWRIGHT_TEST_BASE_URL || 'http://localhost:5173',
        headless: inCI ? true : false
    },
    workers: 1,
    testDir: 'e2e',
    projects: [
        {
            name: 'setup',
            testMatch: '**/auth.setup.ts',
            use: { storageState: { cookies: [], origins: [] } }
        },
        // Proyecto principal de E2E temporalmente desactivado mientras se ajusta el flujo
        // de Workspace / Fixed Assets. Rehabilitar cuando los E2E estén listos.
        // {
        //     name: 'tests',
        //     dependencies: ['setup'],
        //     testIgnore: ['**/auth.setup.ts', '**/demo.test.ts'],
        //     use: { storageState: authStatePath }
        // }
    ]
});
