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

@ -1,11 +1,10 @@
// Runner for the Tiptap editor test. Sets up a jsdom DOM, then dynamically
// imports the bundled editor module so Tiptap sees a browser-like environment.
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,
@ -24,19 +23,10 @@ g.DOMParser = window.DOMParser;
g.requestAnimationFrame = (cb) => setTimeout(cb, 0);
g.cancelAnimationFrame = (id) => clearTimeout(id);
const out = path.join(os.tmpdir(), `folio-editor-${process.pid}.mjs`);
const entry = path.resolve("tests/.folio-editor-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-editor",
entryPoints: ["tests/.folio-editor-test-entry.ts"],
});
const mod = await import(url.pathToFileURL(out).href);
const {
createTiptapEditor,
runCommand,
@ -235,7 +225,7 @@ ok(
"standalone Highlight button applies a default highlight to the selection"
);
fs.rmSync(out, { force: true });
cleanupBundle();
fs.rmSync(book, { recursive: true, force: true });
console.log(