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

@ -3,25 +3,14 @@
// renderer module and verifies that chapter breaks become print sections and
// that every rich-text feature survives the native -> HTML conversion.
// Run with: node tests/run-print-test.mjs
import esbuild from "esbuild";
import fs from "fs";
import os from "os";
import path from "path";
import url from "url";
import { bundleForTest } from "./helpers/bundle.mjs";
const out = path.resolve(`tests/.tmp-folio-print-${process.pid}.mjs`);
await esbuild.build({
entryPoints: [path.resolve("src/renderer/print-format.ts")],
bundle: true,
platform: "node",
format: "esm",
const { mod, cleanupBundle } = await bundleForTest({
name: "folio-print",
entryPoints: ["src/renderer/print-format.ts"],
external: ["electron"],
outfile: out,
write: true,
logLevel: "silent",
});
const mod = await import(url.pathToFileURL(out).href);
const renderPrintChaptersNative = mod.renderPrintChaptersNative;
let failures = 0;
@ -136,7 +125,7 @@ check("renders external link", /<a href="https:\/\/example.com">Site<\/a>/.test(
check("renders wikilink as internal anchor", /<a href="folio:chapter\/Two" class="wikilink internal">Go<\/a>/.test(html));
check("no raw wikilink brackets", !html.includes("[[Two"));
fs.rmSync(out, { force: true });
cleanupBundle();
if (failures > 0) {
console.error(`\n${failures} check(s) failed.`);