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

@ -4,27 +4,18 @@
// JSON, then inspects the produced ZIP contents to check that the manuscript,
// its chapter order, and its formatting survive the native -> DOCX path.
// Run with: node tests/run-office-export-test.mjs
import esbuild from "esbuild";
import fs from "fs";
import os from "os";
import path from "path";
import url from "url";
import JSZip from "jszip";
import { bundleForTest } from "./helpers/bundle.mjs";
const out = path.resolve(`tests/.tmp-folio-office-${process.pid}.mjs`);
await esbuild.build({
entryPoints: [path.resolve("src/main/office-export.ts")],
bundle: true,
platform: "node",
format: "esm",
const { mod, cleanupBundle } = await bundleForTest({
name: "folio-office",
entryPoints: ["src/main/office-export.ts"],
external: ["electron"],
outfile: out,
write: true,
logLevel: "silent",
});
const mod = await import(url.pathToFileURL(out).href);
let failures = 0;
const check = (name, ok) => {
console.log(`${ok ? "PASS" : "FAIL"} ${name}`);
@ -271,7 +262,7 @@ for (const [f, bytes] of origFiles) {
check("folio.json unchanged", fs.readFileSync(path.join(bookDir, "folio.json")).equals(origManifest));
fs.rmSync(bookDir, { recursive: true, force: true });
fs.rmSync(out, { force: true });
cleanupBundle();
if (odtSkipped) {
console.log("NOTE ODT verification requires LibreOffice; it was skipped.");