| 1 | import * as NodeChildProcess from "node:child_process"; |
| 2 | import * as NodePath from "node:path"; |
| 3 | import * as NodeURL from "node:url"; |
| 4 | import { resolveElectronLaunchCommand } from "./electron-launcher.mjs"; |
| 5 | |
| 6 | const __dirname = NodePath.dirname(NodeURL.fileURLToPath(import.meta.url)); |
| 7 | const desktopDir = NodePath.resolve(__dirname, ".."); |
| 8 | const mainJs = NodePath.resolve(desktopDir, "dist-electron/boot.cjs"); |
| 9 | |
| 10 | console.log("\nLaunching Electron smoke test..."); |
| 11 | |
| 12 | const electronCommand = resolveElectronLaunchCommand([mainJs]); |
| 13 | const child = NodeChildProcess.spawn(electronCommand.electronPath, electronCommand.args, { |
| 14 | stdio: ["pipe", "pipe", "pipe"], |
| 15 | env: { |
| 16 | ...process.env, |
| 17 | VITE_DEV_SERVER_URL: "", |
| 18 | ELECTRON_ENABLE_LOGGING: "1", |
| 19 | }, |
| 20 | }); |
| 21 | |
| 22 | let output = ""; |
| 23 | child.stdout.on("data", (chunk) => { |
| 24 | output += chunk.toString(); |
| 25 | }); |
| 26 | child.stderr.on("data", (chunk) => { |
| 27 | output += chunk.toString(); |
| 28 | }); |
| 29 | |
| 30 | const timeout = setTimeout(() => { |
| 31 | child.kill(); |
| 32 | }, 8_000); |
| 33 | |
| 34 | child.on("exit", () => { |
| 35 | clearTimeout(timeout); |
| 36 | |
| 37 | const fatalPatterns = [ |
| 38 | "Cannot find module", |
| 39 | "MODULE_NOT_FOUND", |
| 40 | "Refused to execute", |
| 41 | "Uncaught Error", |
| 42 | "Uncaught TypeError", |
| 43 | "Uncaught ReferenceError", |
| 44 | ]; |
| 45 | const failures = fatalPatterns.filter((pattern) => output.includes(pattern)); |
| 46 | |
| 47 | if (failures.length > 0) { |
| 48 | console.error("\nDesktop smoke test failed:"); |
| 49 | for (const failure of failures) { |
| 50 | console.error(` - ${failure}`); |
| 51 | } |
| 52 | console.error("\nFull output:\n" + output); |
| 53 | process.exit(1); |
| 54 | } |
| 55 | |
| 56 | console.log("Desktop smoke test passed."); |
| 57 | process.exit(0); |
| 58 | }); |