refactor(tests): centralize test harness boilerplate into bundle.mjs helper
This commit is contained in:
parent
1729f7c236
commit
43a03272bf
9 changed files with 107 additions and 150 deletions
|
|
@ -1,24 +1,15 @@
|
|||
// Standalone test for the pure project/recents logic.
|
||||
// Builds src/main/project.ts with esbuild (no Electron needed) and asserts behavior.
|
||||
// Run with: node tests/run-project-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.join(os.tmpdir(), `folio-project-${process.pid}.mjs`);
|
||||
await esbuild.build({
|
||||
entryPoints: [path.resolve("src/main/project.ts")],
|
||||
bundle: true,
|
||||
platform: "node",
|
||||
format: "esm",
|
||||
outfile: out,
|
||||
write: true,
|
||||
logLevel: "silent",
|
||||
const { mod, cleanupBundle } = await bundleForTest({
|
||||
name: "folio-project",
|
||||
entryPoints: ["src/main/project.ts"],
|
||||
});
|
||||
|
||||
const mod = await import(url.pathToFileURL(out).href);
|
||||
const {
|
||||
APP_ID,
|
||||
META_FILE,
|
||||
|
|
@ -78,7 +69,7 @@ const id = makeChapterId("Chapter One");
|
|||
ok(id.startsWith("chapter-one-"), "chapter id slugified: " + id);
|
||||
ok(chapterFileName(id) === `${id}.md`, "filename is <id>.md");
|
||||
|
||||
fs.rmSync(out, { force: true });
|
||||
cleanupBundle();
|
||||
fs.rmSync(dir, { recursive: true, force: true });
|
||||
|
||||
console.log("\nProject tests: " + (failures === 0 ? "ALL PASSED" : failures + " FAILED"));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue