fabro/apps/fabro-web/scripts/build.test.ts
Bryan Helmkamp 603a64810c
Some checks are pending
Rust / Format (push) Waiting to run
Rust / Clippy (push) Waiting to run
Rust / Generated Docs (push) Waiting to run
Rust / Test (Linux) (push) Waiting to run
Rust / Test (macOS) (push) Waiting to run
TypeScript / Typecheck (push) Waiting to run
TypeScript / Test (push) Waiting to run
TypeScript / Build (push) Waiting to run
fix(web): virtualize run file diffs consistently
Always route non-empty Files Changed views through Pierre's Virtualizer and worker pool, with full-height layout propagation and stable per-file cache keys. Copy Pierre worker assets during the web build so the static worker URL resolves in production.
2026-05-05 16:41:39 -04:00

71 lines
2 KiB
TypeScript

import { test, expect } from "bun:test";
import { existsSync } from "node:fs";
import { readdir } from "node:fs/promises";
import { basename, join } from "node:path";
const root = Bun.fileURLToPath(new URL("..", import.meta.url));
test("production build copies Pierre worker assets", async () => {
const process = Bun.spawn(["bun", "run", "scripts/build.ts"], {
cwd: root,
stdout: "pipe",
stderr: "pipe",
});
const code = await process.exited;
if (code !== 0) {
const stderr = await new Response(process.stderr).text();
const stdout = await new Response(process.stdout).text();
throw new Error(
`build failed with code ${code}\nstdout:\n${stdout}\nstderr:\n${stderr}`,
);
}
const workerDist = join(root, "dist", "assets", "pierre-diffs-worker");
expect(existsSync(join(workerDist, "worker-portable.js"))).toBe(true);
const upstreamWorkerDir = join(
root,
"node_modules",
"@pierre",
"diffs",
"dist",
"worker",
);
const wasmFiles = (await readdir(upstreamWorkerDir))
.filter((file) => /^wasm-.*\.js$/.test(file))
.map((file) => basename(file));
for (const wasmFile of wasmFiles) {
expect(existsSync(join(workerDist, wasmFile))).toBe(true);
}
});
test("watch mode keeps running until interrupted", async () => {
const process = Bun.spawn([
"bun",
"run",
"scripts/build.ts",
"--watch",
], {
cwd: root,
stdout: "pipe",
stderr: "pipe",
});
const result = await Promise.race([
process.exited.then((code) => ({ kind: "exited" as const, code })),
Bun.sleep(1000).then(() => ({ kind: "running" as const })),
]);
if (result.kind === "exited") {
const stderr = await new Response(process.stderr).text();
const stdout = await new Response(process.stdout).text();
throw new Error(
`watch process exited unexpectedly with code ${result.code}\nstdout:\n${stdout}\nstderr:\n${stderr}`,
);
}
process.kill("SIGINT");
expect([0, 130]).toContain(await process.exited);
});