New tests/e2e/ suite covering: - Auth, navigation, player, tracks, playlists - Search, discover, social, marketplace, chat - Accessibility, API, workflows, edge cases - Routes coverage, forms validation, modals - Empty states, responsive, network errors - Error boundary, performance, visual regression - Cross-browser, profile, smoke, upload - Storybook, deep pages, visual bugs - Includes fixtures, helpers, global setup/teardown - Playwright config and coverage map Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
83 lines
3.5 KiB
TypeScript
83 lines
3.5 KiB
TypeScript
import { request } from '@playwright/test';
|
|
import { CONFIG } from './helpers';
|
|
|
|
/**
|
|
* Global Setup — Crée les comptes de test et vérifie la santé des services.
|
|
* S'exécute une seule fois avant toute la suite.
|
|
*
|
|
* NOTE: globalSetup exporte une fonction async, pas des appels à test().
|
|
*/
|
|
export default async function globalSetup() {
|
|
const ctx = await request.newContext({ baseURL: CONFIG.baseURL });
|
|
|
|
// ── Créer les comptes de test ──────────────────────────────────
|
|
const users = [CONFIG.users.listener, CONFIG.users.creator, CONFIG.users.admin];
|
|
|
|
for (const user of users) {
|
|
try {
|
|
const response = await ctx.post('/api/v1/auth/register', {
|
|
data: {
|
|
email: user.email,
|
|
password: user.password,
|
|
username: user.username,
|
|
password_confirmation: user.password,
|
|
},
|
|
});
|
|
|
|
if (response.ok()) {
|
|
console.log(` ✓ Compte créé: ${user.email}`);
|
|
} else if (response.status() === 409 || response.status() === 422) {
|
|
console.log(` ⊘ Compte existant: ${user.email}`);
|
|
} else {
|
|
const body = await response.text().catch(() => '');
|
|
console.warn(` ⚠ Échec création ${user.email}: ${response.status()} ${body.slice(0, 120)}`);
|
|
}
|
|
} catch (e) {
|
|
console.warn(` ⚠ API indisponible pour ${user.email}: ${e}`);
|
|
}
|
|
}
|
|
|
|
// ── Vérification santé des services ────────────────────────────
|
|
try {
|
|
const health = await ctx.get('/api/v1/health');
|
|
console.log(` Backend API: ${health.ok() ? '✓ OK' : '✗ DOWN'} (${health.status()})`);
|
|
} catch {
|
|
console.error(' ✗ Backend API inaccessible');
|
|
}
|
|
|
|
// ── Vérification que le rate limiting est désactivé ────────────
|
|
// Le backend doit être démarré avec APP_ENV=test ou DISABLE_RATE_LIMIT_FOR_TESTS=true
|
|
// Utiliser `make dev-e2e` pour démarrer correctement.
|
|
try {
|
|
// Envoyer 10 requêtes login rapides pour détecter le rate limiting
|
|
let got429 = false;
|
|
for (let i = 0; i < 10; i++) {
|
|
const r = await ctx.post('/api/v1/auth/login', {
|
|
data: { email: 'rate-limit-probe@test.invalid', password: 'x' },
|
|
});
|
|
if (r.status() === 429) { got429 = true; break; }
|
|
}
|
|
if (got429) {
|
|
console.error(
|
|
'\n ╔══════════════════════════════════════════════════════════════╗\n' +
|
|
' ║ ⚠ RATE LIMITING IS ACTIVE — E2E TESTS WILL BE FLAKY! ║\n' +
|
|
' ║ Restart the backend with: make dev-e2e ║\n' +
|
|
' ║ This sets APP_ENV=test & DISABLE_RATE_LIMIT_FOR_TESTS=true║\n' +
|
|
' ╚══════════════════════════════════════════════════════════════╝\n',
|
|
);
|
|
} else {
|
|
console.log(' Rate limiting: ✓ disabled (test mode)');
|
|
}
|
|
} catch {
|
|
// Non-blocking — if API is down, the test will fail elsewhere
|
|
}
|
|
|
|
try {
|
|
const health = await ctx.get(`${CONFIG.streamURL}/health`);
|
|
console.log(` Stream Server: ${health.ok() ? '✓ OK' : '✗ DOWN'} (${health.status()})`);
|
|
} catch {
|
|
console.error(' ✗ Stream Server inaccessible (non bloquant)');
|
|
}
|
|
|
|
await ctx.dispose();
|
|
}
|