1import * as NodeChildProcess from "node:child_process";
2import * as NodePath from "node:path";
3import * as NodeURL from "node:url";
4import { resolveElectronLaunchCommand } from "./electron-launcher.mjs";
5
6const __dirname = NodePath.dirname(NodeURL.fileURLToPath(import.meta.url));
7const desktopDir = NodePath.resolve(__dirname, "..");
8const mainJs = NodePath.resolve(desktopDir, "dist-electron/boot.cjs");
9
10console.log("\nLaunching Electron smoke test...");
11
12const electronCommand = resolveElectronLaunchCommand([mainJs]);
13const 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
22let output = "";
23child.stdout.on("data", (chunk) => {
24 output += chunk.toString();
25});
26child.stderr.on("data", (chunk) => {
27 output += chunk.toString();
28});
29
30const timeout = setTimeout(() => {
31 child.kill();
32}, 8_000);
33
34child.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});