Record your screen, ship a demo. Free and open-source, GPU-accelerated, no watermarks, no subscriptions. Windows, macOS, Linux. Actively maintained.
TypeScript cross-platformelectronffmpegopen-sourceproduct-demorustscreen-capturescreen-recorderscreen-recordingscreen-studioscreencastspeech-to-texttypescriptvideo-editingvideo-editorwaylandwgpuwhisper
test(e2e): repointer la spec d'export sur le dialogue v4, et isoler le verrou d'instance
Etienne Lescotd9b1ed36199c
diff --git a/tests/e2e/gif-export.spec.ts b/tests/e2e/gif-export.spec.tsindex 18277ccb6..1ff2b74b5 100644--- a/tests/e2e/gif-export.spec.ts+++ b/tests/e2e/gif-export.spec.ts@@ -1,4 +1,4 @@-import { spawnSync } from "node:child_process";+import { once } from "node:events";import fs from "node:fs";import os from "node:os";import path from "node:path";@@ -10,10 +10,9 @@ const ROOT = path.join(__dirname, "../..");const MAIN_JS = path.join(ROOT, "dist-electron/main.js");const TEST_VIDEO = path.join(__dirname, "../fixtures/sample.webm");-async function exportFromLoadedVideo(format: "gif" | "mp4"): Promise<Buffer> {- const outputPath = path.join(os.tmpdir(), `test-${format}-export-${Date.now()}.${format}`);- let testVideoInRecordings = "";+type ElectronApplication = Awaited<ReturnType<typeof electron.launch>>;+async function launchApp(userDataDir: string, tmpDir: string) {const app = await electron.launch({args: [MAIN_JS,@@ -21,17 +20,62 @@ async function exportFromLoadedVideo(format: "gif" | "mp4"): Promise<Buffer> {"--no-sandbox",// Force software WebGL in headless CI to avoid GPU framebuffer errors."--enable-unsafe-swiftshader",+ // The selectors below are the English accessible names, so pin the locale.+ "--lang=en-US",+ `--user-data-dir=${userDataDir}`,],env: {...process.env,+ ELECTRON_USER_DATA_DIR: userDataDir,+ // `acquireStableInstanceLock` keys its lock directory off `os.tmpdir()` and+ // the *user id* — not off userData — so a dev instance running from any+ // worktree would otherwise make this launch quit instantly (exit code 0, no+ // window, no stderr). Giving the app its own temp dir gives it its own lock.+ TMPDIR: tmpDir,+ TMP: tmpDir,+ TEMP: tmpDir,// Set HEADLESS=false to show windows while debugging.HEADLESS: process.env["HEADLESS"] ?? "true",+ LANG: "en_US.UTF-8",+ LC_ALL: "en_US.UTF-8",+ LANGUAGE: "en_US",},});- const electronProcess = app.process();app.process().stdout?.on("data", (d) => process.stdout.write(`[electron] ${d}`));app.process().stderr?.on("data", (d) => process.stderr.write(`[electron] ${d}`));+ return app;+}++async function closeApp(app: ElectronApplication) {+ const childProcess = app.process();+ await Promise.race([app.close(), new Promise<void>((resolve) => setTimeout(resolve, 5_000))]);+ if (childProcess.exitCode === null && childProcess.signalCode === null) {+ if (!childProcess.killed) {+ childProcess.kill("SIGKILL");+ }+ await Promise.race([+ once(childProcess, "close"),+ new Promise<void>((resolve) => setTimeout(resolve, 5_000)),+ ]);+ }+}++/**+ * Drives the v4 editor's Export dialog end to end and returns the bytes it wrote.+ *+ * The native save dialog can't be driven from Playwright, so `pick-export-save-path`+ * is stubbed in the main process to return a temp path. Everything after that is the+ * real pipeline: the dialog hands that path straight to the native exporter+ * (`exportMultiNative` / `exportGifNative`), which writes the file itself — there is+ * no `write-export-to-path` round-trip through the renderer any more, so the test+ * reads the finished file off disk instead of intercepting a buffer.+ */+async function exportFromLoadedVideo(format: "gif" | "mp4"): Promise<Buffer> {+ const outputPath = path.join(os.tmpdir(), `test-${format}-export-${Date.now()}.${format}`);+ const userDataDir = fs.mkdtempSync(path.join(os.tmpdir(), "openscreen-e2e-export-"));+ const appTmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "openscreen-e2e-tmp-"));+ const app = await launchApp(userDataDir, appTmpDir);try {const hudWindow = await app.firstWindow({ timeout: 60_000 });@@ -39,33 +83,18 @@ async function exportFromLoadedVideo(format: "gif" | "mp4"): Promise<Buffer> {await app.evaluate(({ ipcMain }, targetPath: string) => {ipcMain.removeHandler("pick-export-save-path");- ipcMain.removeHandler("write-export-to-path");ipcMain.handle("pick-export-save-path", () => ({success: true,path: targetPath,canceled: false,}));- ipcMain.handle(- "write-export-to-path",- (_event: Electron.IpcMainInvokeEvent, buffer: ArrayBuffer, filePath: string) => {- if (filePath !== targetPath) {- return {- success: false,- error: `Unexpected export path: ${filePath}`,- };- }- (globalThis as Record<string, unknown>)["__testExportData"] =- Buffer.from(buffer).toString("base64");- return { success: true, path: filePath };- },- );}, outputPath);- const userDataDir = await app.evaluate(({ app: electronApp }) => {- return electronApp.getPath("userData");- });- const recordingsDir = path.join(userDataDir, "recordings");- testVideoInRecordings = path.join(recordingsDir, "test-sample.webm");+ const recordingsDir = path.join(+ await app.evaluate(({ app: electronApp }) => electronApp.getPath("userData")),+ "recordings",+ );+ const testVideoInRecordings = path.join(recordingsDir, "test-sample.webm");fs.mkdirSync(recordingsDir, { recursive: true });fs.copyFileSync(TEST_VIDEO, testVideoInRecordings);@@ -92,55 +121,46 @@ async function exportFromLoadedVideo(format: "gif" | "mp4"): Promise<Buffer> {// WebCodecs may not be registered in the renderer on first load.await editorWindow.reload();await editorWindow.waitForLoadState("domcontentloaded");- await expect(editorWindow.getByText("Loading video...")).not.toBeVisible({- timeout: 15_000,- });- await editorWindow.getByTestId("testId-export-panel-button").click();- await editorWindow.getByTestId(`testId-${format}-format-button`).click();- await editorWindow.getByTestId("testId-export-button").click();+ // Top bar: the Export control is disabled until the seeded recording has been+ // imported into the project, so waiting for it to be enabled doubles as the+ // "editor finished loading" gate. `exact` keeps it off the dialog's own+ // "Export MP4" / "Export GIF" button.+ const openExport = editorWindow.getByRole("button", { name: "Export", exact: true });+ await expect(openExport).toBeEnabled({ timeout: 30_000 });+ await openExport.click();- await expect- .poll(- () =>- app.evaluate(() => Boolean((globalThis as Record<string, unknown>)["__testExportData"])),- { timeout: 90_000 },- )- .toBe(true);+ const dialog = editorWindow.getByRole("dialog");+ await expect(dialog.getByRole("heading", { name: "Export" })).toBeVisible();- const base64 = await app.evaluate(- () => (globalThis as Record<string, unknown>)["__testExportData"] as string,- );- fs.writeFileSync(outputPath, Buffer.from(base64, "base64"));+ await dialog+ .getByRole("button", { name: format === "gif" ? "GIF" : "MP4", exact: true })+ .click();++ const startExport = dialog.getByRole("button", {+ name: format === "gif" ? "Export GIF" : "Export MP4",+ exact: true,+ });+ await expect(startExport).toBeEnabled();+ await startExport.click();++ // The dialog swaps the placeholder for a progress block while the native+ // exporter runs and finally reports the path it wrote to.+ await expect(dialog.getByText("Saved to")).toBeVisible({ timeout: 85_000 });+ await expect(dialog.getByText(outputPath)).toBeVisible();expect(fs.existsSync(outputPath), `${format.toUpperCase()} not found at ${outputPath}`).toBe(true,);- const stats = fs.statSync(outputPath);- expect(stats.size).toBeGreaterThan(1024);+ expect(fs.statSync(outputPath).size).toBeGreaterThan(1024);return fs.readFileSync(outputPath);} finally {- await app- .evaluate(({ app: electronApp }) => {- electronApp.exit(0);- })- .catch(() => {- // The process may already be gone after export completes.- });- if (electronProcess.pid) {- if (process.platform === "win32") {- spawnSync("taskkill", ["/PID", String(electronProcess.pid), "/T", "/F"], {- stdio: "ignore",- });- } else if (!electronProcess.killed) {- electronProcess.kill("SIGKILL");- }- }+ await closeApp(app);if (fs.existsSync(outputPath)) {fs.unlinkSync(outputPath);}- if (testVideoInRecordings && fs.existsSync(testVideoInRecordings)) {- fs.unlinkSync(testVideoInRecordings);+ for (const dir of [userDataDir, appTmpDir]) {+ fs.rmSync(dir, { recursive: true, force: true, maxRetries: 5, retryDelay: 100 });}}}