From 38a561a7cd271bd873d51c4bc252bf8029d2595c Mon Sep 17 00:00:00 2001 From: yu <191972707@qq.com> Date: Wed, 28 Oct 2026 17:46:30 +0800 Subject: [PATCH] =?UTF-8?q?test:=20=E6=89=93=E5=8C=85=E5=86=92=E7=83=9F?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E8=B7=B3=E8=BF=87=E5=8D=95=E5=AE=9E=E4=BE=8B?= =?UTF-8?q?=E9=94=81=E4=B8=8E=E5=9B=BA=E5=AE=9A=E9=9A=94=E7=A6=BB=E7=8E=AF?= =?UTF-8?q?=E5=A2=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/package.mjs | 8 +++++++- scripts/spawn-test.mjs | 40 ++++++++++++++++++++++++++++++++++++++++ src/main/index.ts | 3 ++- 3 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 scripts/spawn-test.mjs diff --git a/scripts/package.mjs b/scripts/package.mjs index 6a48e7b..438166d 100644 --- a/scripts/package.mjs +++ b/scripts/package.mjs @@ -49,7 +49,13 @@ async function verifyLaunch(executable, label) { const child = spawn(executable, [`--user-data-dir=${userData}`], { cwd: path.dirname(executable), stdio: "ignore", - windowsHide: false + windowsHide: false, + env: { + ...process.env, + RPA_SKIP_SINGLE_INSTANCE: "1", + RPA_E2E: "1", + RPA_FIXTURE_PORT: String(18000 + Math.floor(Math.random() * 1000)) + } }); await delay(8000); const exited = child.exitCode !== null || child.signalCode !== null; diff --git a/scripts/spawn-test.mjs b/scripts/spawn-test.mjs new file mode 100644 index 0000000..190556d --- /dev/null +++ b/scripts/spawn-test.mjs @@ -0,0 +1,40 @@ +import { spawn } from "node:child_process"; + +const executable = process.argv[2]; +if (!executable) { + console.error("usage: node scripts/spawn-test.mjs [...args]"); + process.exit(2); +} +const env = { ...process.env }; +delete env.ELECTRON_RUN_AS_NODE; + +const child = spawn(executable, process.argv.slice(3), { + env, + stdio: ["ignore", "pipe", "pipe"], + windowsHide: false +}); + +child.stdout.on("data", (data) => process.stdout.write(`[out] ${data}`)); +child.stderr.on("data", (data) => process.stderr.write(`[err] ${data}`)); + +const timer = setTimeout(() => { + console.log(`STILL_RUNNING pid=${child.pid}`); + try { + child.kill("SIGKILL"); + } catch { + // ignore + } + setTimeout(() => process.exit(0), 1000); +}, 9000); + +child.on("exit", (code, signal) => { + clearTimeout(timer); + console.log(`EXIT code=${code} signal=${signal}`); + process.exit(0); +}); + +child.on("error", (error) => { + clearTimeout(timer); + console.error(`SPAWN_ERROR ${error.message}`); + process.exit(1); +}); diff --git a/src/main/index.ts b/src/main/index.ts index bfa11e6..77fda1c 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -172,7 +172,8 @@ function registerIpc(): void { }); } -const gotLock = app.requestSingleInstanceLock(); +// 打包冒烟/自动化测试需要与用户日常实例隔离;正常启动仍然保持单实例。 +const gotLock = process.env.RPA_SKIP_SINGLE_INSTANCE === "1" ? true : app.requestSingleInstanceLock(); if (!gotLock) { app.quit(); } else {