fix(ci): Corriger les tests E2E en CI
Plusieurs problèmes empêchaient les tests E2E de passer en CI : 1. Healthcheck : L'endpoint /api nécessite une authentification et retournait 401, causant l'échec du healthcheck. Remplacé par /api/docs qui est public. 2. Mailer : L'activation de compte déclenche l'envoi d'un email via mailpit, qui n'est pas disponible en CI. Ajout d'une variable d'environnement MAILER_DSN=null://null pour désactiver l'envoi. 3. Token partagé : Chaque navigateur (chromium, firefox, webkit) consommait le même token, causant des échecs pour les suivants. Maintenant chaque navigateur crée son propre token dans beforeAll avec un email unique (e2e-{browser}@example.com). 4. Nettoyage : Suppression de test-utils.ts et global-setup simplifié car la création de token est maintenant dans le fichier de test.
This commit is contained in:
@@ -1,52 +1,12 @@
|
||||
import { execSync } from 'child_process';
|
||||
import { writeFileSync } from 'fs';
|
||||
import { join, dirname } from 'path';
|
||||
import { fileURLToPath } from 'url';
|
||||
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = dirname(__filename);
|
||||
|
||||
/**
|
||||
* Global setup for E2E tests.
|
||||
* Seeds a test activation token before tests run.
|
||||
*
|
||||
* Note: Token creation is now handled per-browser in the test files
|
||||
* using beforeAll hooks. This ensures each browser project gets its
|
||||
* own unique token that won't be consumed by other browsers.
|
||||
*/
|
||||
async function globalSetup() {
|
||||
console.warn('🌱 Seeding test activation token...');
|
||||
|
||||
try {
|
||||
// Call the backend command to create a test token
|
||||
// Project root is 2 levels up from frontend/e2e/
|
||||
const projectRoot = join(__dirname, '../..');
|
||||
const composeFile = join(projectRoot, 'compose.yaml');
|
||||
|
||||
const result = execSync(
|
||||
`docker compose -f "${composeFile}" exec -T php php bin/console app:dev:create-test-activation-token --email=e2e-test@example.com 2>&1`,
|
||||
{
|
||||
encoding: 'utf-8'
|
||||
}
|
||||
);
|
||||
|
||||
// Extract the token from the output
|
||||
// Output format: "Token f9174245-9766-4ef1-b6e9-a6795aa2da04"
|
||||
const tokenMatch = result.match(/Token\s+([a-f0-9-]{36})/i);
|
||||
if (!tokenMatch) {
|
||||
console.error('❌ Could not extract token from output:', result);
|
||||
throw new Error('Failed to extract token from command output');
|
||||
}
|
||||
|
||||
const token = tokenMatch[1];
|
||||
console.warn(`✅ Test token created: ${token}`);
|
||||
|
||||
// Write the token to a file for tests to use
|
||||
const tokenFile = join(__dirname, '.test-token');
|
||||
writeFileSync(tokenFile, token);
|
||||
|
||||
console.warn('✅ Token saved to .test-token file');
|
||||
} catch (error) {
|
||||
console.error('❌ Failed to seed test token:', error);
|
||||
// Don't throw - tests can still run with skipped token-dependent tests
|
||||
console.warn('⚠️ Tests requiring valid tokens will be skipped');
|
||||
}
|
||||
console.warn('🎭 E2E Global setup - tokens are created per browser project');
|
||||
}
|
||||
|
||||
export default globalSetup;
|
||||
|
||||
Reference in New Issue
Block a user