mirror of
https://github.com/getpaseo/paseo.git
synced 2026-11-06 08:24:46 +00:00
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.
This commit is contained in:
@@ -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 });
|
||||
}
|
||||
@@ -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 }));
|
||||
|
||||
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user