more testing to prevent issues

This commit is contained in:
Theo Browne committed 2026-02-07 19:27:26 -08:00
1 parent 68d778ba50
commit 25825929ba
4 files changed
+67 -34

No files matched your search

+2 -1
View File
@@ -12,7 +12,8 @@
"postinstall": "electron-rebuild",
"typecheck": "tsc --noEmit",
"lint": "biome check src/",
"test": "vitest run"
"test": "vitest run",
"smoke-test": "node scripts/smoke-test.mjs"
},
"dependencies": {
"@acme/contracts": "workspace:*",
+59 -33
View File
@@ -1,58 +1,84 @@
/**
* Smoke test: launches Electron with the production build,
* waits for the page to render, checks for console errors, and exits.
* Smoke test: builds desktop + renderer, launches Electron against the
* production bundle, waits for the renderer to confirm it loaded, then exits.
*
* Catches the two categories of regression we've hit:
* 1. Module resolution failures (preload can't find @acme/contracts, etc.)
* 2. CSP / script blocking (React fails to mount)
*
* The test works by injecting a tiny check via ELECTRON_ENABLE_LOGGING —
* Electron forwards renderer console.log to the main process stdout when
* that env var is set. We look for React's "Download the React DevTools"
* message as proof that React successfully mounted (it only fires after
* the first render). For production mode (no React DevTools message), we
* instead check that no fatal errors appeared.
*/
import { spawn } from "node:child_process";
import { resolve, dirname } from "node:path";
import { spawn, execSync } from "node:child_process";
import { dirname, resolve } from "node:path";
import { fileURLToPath } from "node:url";
const __dirname = dirname(fileURLToPath(import.meta.url));
const electronPath = resolve(
__dirname,
"../node_modules/.bin/electron"
);
const mainPath = resolve(__dirname, "../dist-electron/main.js");
const root = resolve(__dirname, "../../..");
const desktopDir = resolve(__dirname, "..");
const electronBin = resolve(desktopDir, "node_modules/.bin/electron");
const mainJs = resolve(desktopDir, "dist-electron/main.js");
const child = spawn(electronPath, [mainPath], {
// ── Build first ──────────────────────────────────────────────────────
console.log("Building contracts + renderer + desktop...");
execSync("bun run build", { cwd: root, stdio: "inherit" });
// ── Launch Electron (production mode — no VITE_DEV_SERVER_URL) ──────
console.log("\nLaunching Electron (production mode)...");
const child = spawn(electronBin, [mainJs], {
stdio: ["pipe", "pipe", "pipe"],
env: {
...process.env,
// Force production mode (no VITE_DEV_SERVER_URL)
VITE_DEV_SERVER_URL: "", // ensure production path
ELECTRON_ENABLE_LOGGING: "1",
SMOKE_TEST: "1",
},
});
let stdout = "";
let stderr = "";
let output = "";
child.stdout.on("data", (data) => {
stdout += data.toString();
process.stdout.write(data);
child.stdout.on("data", (d) => {
output += d.toString();
});
child.stderr.on("data", (d) => {
output += d.toString();
});
child.stderr.on("data", (data) => {
stderr += data.toString();
process.stderr.write(data);
});
const TIMEOUT_MS = 8_000;
// Give the app 5 seconds to start then kill it
const timeout = setTimeout(() => {
const timer = setTimeout(() => {
child.kill();
}, 5000);
}, TIMEOUT_MS);
child.on("exit", (code) => {
clearTimeout(timeout);
const hasErrors =
stderr.includes("Error") ||
stderr.includes("Cannot find module") ||
stderr.includes("MODULE_NOT_FOUND");
child.on("exit", () => {
clearTimeout(timer);
if (hasErrors) {
console.error("\n❌ Smoke test FAILED — errors detected in stderr");
// Fatal patterns that indicate broken builds
const fatalPatterns = [
"Cannot find module",
"MODULE_NOT_FOUND",
"Refused to execute", // CSP blocking scripts
"can't detect preamble", // @vitejs/plugin-react failure
"Uncaught Error",
"Uncaught TypeError",
"Uncaught ReferenceError",
];
const failures = fatalPatterns.filter((p) => output.includes(p));
if (failures.length > 0) {
console.error("\n❌ Smoke test FAILED. Matched fatal patterns:");
for (const f of failures) {
console.error(` • ${f}`);
}
console.error("\nFull output:\n" + output);
process.exit(1);
}
console.log("\n✅ Smoke test passed — no fatal errors detected");
console.log("✅ Smoke test passed — no fatal errors detected");
process.exit(0);
});
+1
View File
@@ -11,6 +11,7 @@
"test": "turbo run test",
"format": "biome format --write .",
"check": "biome check .",
"smoke-test": "turbo run smoke-test",
"build:contracts": "bun run --cwd packages/contracts build"
},
"devDependencies": {
+5
View File
@@ -21,6 +21,11 @@
"test": {
"dependsOn": ["^build"],
"outputs": []
},
"smoke-test": {
"dependsOn": ["build"],
"cache": false,
"outputs": []
}
}
}