/** * Helper Playwright pour lancer l'application Electron. * * Lance l'app depuis dist-electron/main.js (il faut avoir buildé avec `vite build` avant). * Exporte une fixture `test` qui fournit `electronApp` et `page`. * * Chaque test démarre avec un userData vierge (nettoyé automatiquement). */ import { test as base, type ElectronApplication, type Page, _electron as electron } from '@playwright/test'; import path from 'path'; import fs from 'fs'; const USER_DATA_DIR = path.resolve(__dirname, '../../.e2e-userdata'); type ElectronFixtures = { electronApp: ElectronApplication; page: Page; }; export const test = base.extend({ // eslint-disable-next-line no-empty-pattern electronApp: async ({}, use) => { // Nettoyer le userData pour partir d'un état vierge à chaque test if (fs.existsSync(USER_DATA_DIR)) { fs.rmSync(USER_DATA_DIR, { recursive: true, force: true }); } fs.mkdirSync(USER_DATA_DIR, { recursive: true }); const mainPath = path.resolve(__dirname, '../../dist-electron/main.js'); const app = await electron.launch({ args: [mainPath], env: { ...process.env, ELECTRON_USER_DATA_DIR: USER_DATA_DIR, }, }); await use(app); await app.close(); }, page: async ({ electronApp }, use) => { const window = await electronApp.firstWindow(); await window.waitForLoadState('domcontentloaded'); await window.waitForSelector('.app-shell', { timeout: 15000 }); // L'app démarre sans enclos — en créer un pour les tests qui en ont besoin const addBtn = window.locator('#add-enclos-btn'); if (await addBtn.isVisible({ timeout: 5000 })) { await addBtn.click(); // Attendre que l'enclos apparaisse dans la sidebar await window.waitForSelector('.sb-item .sb-dot', { timeout: 5000 }); } await use(window); }, }); export { expect } from '@playwright/test';