dd-timer/tests/e2e/electron-app.ts
POL Mickaël 3e485fd09b chore: normalise fins de ligne CRLF → LF dans tout le repo
Applique .gitattributes sur tous les fichiers existants.
Élimine les différences fantômes entre WSL et Windows.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-06 08:55:10 +02:00

61 lines
1.9 KiB
TypeScript
Executable File

/**
* 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<ElectronFixtures>({
// 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';