From 4d9c2900b3669b92be09c56646eeaf98a02dbecb Mon Sep 17 00:00:00 2001 From: Mohamed Boudra Date: Thu, 10 Sep 2026 10:07:11 +0200 Subject: [PATCH] test(desktop): clean browser profile after Electron exits Explicit Electron exit skips quit handlers, and removing the profile before shutdown lets Chromium recreate it. The launcher owns the temporary profile and removes it after the child exits. --- .../desktop/e2e/browser-throttling.e2e.cjs | 27 +++++++++++++++++++ .../e2e/browser-throttling.electron.cjs | 4 +-- packages/desktop/package.json | 2 +- 3 files changed, 30 insertions(+), 3 deletions(-) create mode 100644 packages/desktop/e2e/browser-throttling.e2e.cjs diff --git a/packages/desktop/e2e/browser-throttling.e2e.cjs b/packages/desktop/e2e/browser-throttling.e2e.cjs new file mode 100644 index 0000000000..c04d33ff99 --- /dev/null +++ b/packages/desktop/e2e/browser-throttling.e2e.cjs @@ -0,0 +1,27 @@ +const fs = require("node:fs"); +const os = require("node:os"); +const path = require("node:path"); +const { spawnSync } = require("node:child_process"); +const electron = require("electron"); + +// Chromium can recreate profile files during shutdown. The parent owns cleanup +// after Electron exits, including failed assertions and capture timeouts. +const profile = fs.mkdtempSync(path.join(os.tmpdir(), "paseo-browser-throttling-profile-")); +try { + const result = spawnSync( + electron, + [ + "--no-sandbox", + path.join(__dirname, "browser-throttling.electron.cjs"), + ...process.argv.slice(2), + ], + { + stdio: "inherit", + env: { ...process.env, PASEO_BROWSER_THROTTLING_PROFILE_DIR: profile }, + }, + ); + if (result.error) throw result.error; + process.exitCode = result.status ?? 1; +} finally { + fs.rmSync(profile, { recursive: true, force: true }); +} diff --git a/packages/desktop/e2e/browser-throttling.electron.cjs b/packages/desktop/e2e/browser-throttling.electron.cjs index 3e6fe79a8b..bc71e68a7a 100644 --- a/packages/desktop/e2e/browser-throttling.electron.cjs +++ b/packages/desktop/e2e/browser-throttling.electron.cjs @@ -13,7 +13,8 @@ const output = process.env.PASEO_BROWSER_THROTTLING_ARTIFACT_DIR || fs.mkdtempSync(path.join(os.tmpdir(), "paseo-browser-throttling-")); fs.mkdirSync(output, { recursive: true }); -const profile = fs.mkdtempSync(path.join(os.tmpdir(), "paseo-browser-throttling-profile-")); +const profile = process.env.PASEO_BROWSER_THROTTLING_PROFILE_DIR; +assert.ok(profile, "Run through test:e2e:browser-throttling so the launcher owns profile cleanup"); app.setPath("userData", profile); if (process.platform === "darwin") app.setActivationPolicy("accessory"); const measurements = []; @@ -157,4 +158,3 @@ app console.error(error); app.exit(1); }); -app.on("quit", () => fs.rmSync(profile, { recursive: true, force: true })); diff --git a/packages/desktop/package.json b/packages/desktop/package.json index 1174c74457..64cd20bf50 100644 --- a/packages/desktop/package.json +++ b/packages/desktop/package.json @@ -22,7 +22,7 @@ "dev:win": "powershell ./scripts/dev.ps1", "test:e2e:renderer": "cross-env E2E_DESKTOP_RUNTIME=1 playwright test --config=playwright.config.ts --project=desktop", "test:e2e:browser-tabs": "npm run build:main && node ./e2e/browser-tabs.e2e.mjs", - "test:e2e:browser-throttling": "npm run build:main && electron --no-sandbox e2e/browser-throttling.electron.cjs", + "test:e2e:browser-throttling": "npm run build:main && node e2e/browser-throttling.e2e.cjs", "verify:electron-cdp": "node ./scripts/verify-electron-cdp.mjs", "test": "vitest run --exclude \"e2e/**\"", "typecheck": "tsgo --noEmit -p tsconfig.json"