Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

smoke-test.mjs

57 lines1.4 KB

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