refactor(tests): centralize test harness boilerplate into bundle.mjs helper

This commit is contained in:
avi 2026-08-24 21:15:06 -05:00
commit 43a03272bf
9 changed files with 107 additions and 150 deletions

View file

@ -2,12 +2,10 @@
// renderer assembly + Tiptap modules, and verifies that a book assembled from
// native chapters renders with correct chapter order, page-break anchors,
// reorder behavior, title injection, and Copy-All native fidelity.
import esbuild from "esbuild";
import fs from "fs";
import os from "os";
import path from "path";
import url from "url";
import { JSDOM } from "jsdom";
import { bundleForTest } from "./helpers/bundle.mjs";
const dom = new JSDOM("<!DOCTYPE html><html><body></body></html>", {
pretendToBeVisual: true,
@ -26,19 +24,10 @@ g.DOMParser = window.DOMParser;
g.requestAnimationFrame = (cb) => setTimeout(cb, 0);
g.cancelAnimationFrame = (id) => clearTimeout(id);
const out = path.join(os.tmpdir(), `folio-fullbook-${process.pid}.mjs`);
const entry = path.resolve("tests/.folio-fullbook-test-entry.ts");
await esbuild.build({
entryPoints: [entry],
bundle: true,
platform: "node",
format: "esm",
outfile: out,
write: true,
logLevel: "silent",
const { mod, cleanupBundle } = await bundleForTest({
name: "folio-fullbook",
entryPoints: ["tests/.folio-fullbook-test-entry.ts"],
});
const mod = await import(url.pathToFileURL(out).href);
const {
buildFullBookDoc,
nativeNodeText,
@ -190,6 +179,6 @@ ok(
"empty book assembles to empty doc"
);
fs.rmSync(out, { force: true });
cleanupBundle();
console.log("\nFull Book tests: " + (failures === 0 ? "ALL PASSED" : failures + " FAILED"));
process.exit(failures === 0 ? 0 : 1);