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,13 @@
|
|||
// Standalone test for the Obsidian-style wikilink plugin.
|
||||
// Run with: node tests/run-wikilinks-test.mjs
|
||||
import esbuild from "esbuild";
|
||||
import MarkdownIt from "markdown-it";
|
||||
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-wikilinks-${process.pid}.mjs`);
|
||||
await esbuild.build({
|
||||
entryPoints: [path.resolve("src/renderer/wikilinks.ts")],
|
||||
bundle: true,
|
||||
platform: "node",
|
||||
format: "esm",
|
||||
outfile: out,
|
||||
write: true,
|
||||
logLevel: "silent",
|
||||
const { mod, cleanupBundle } = await bundleForTest({
|
||||
name: "folio-wikilinks",
|
||||
entryPoints: ["src/renderer/wikilinks.ts"],
|
||||
});
|
||||
|
||||
const mod = await import(url.pathToFileURL(out).href);
|
||||
const { wikilinkPlugin } = mod;
|
||||
|
||||
const chapters = [
|
||||
|
|
@ -101,7 +90,7 @@ ok(!html8.includes('class="wikilink"'), "nested brackets not parsed as wikilink"
|
|||
const html9 = md.render("empty [[] here");
|
||||
ok(!html9.includes('class="wikilink"'), "empty wikilink target not parsed");
|
||||
|
||||
fs.rmSync(out, { force: true });
|
||||
cleanupBundle();
|
||||
|
||||
console.log("\nWikilink tests: " + (failures === 0 ? "ALL PASSED" : failures + " FAILED"));
|
||||
process.exit(failures === 0 ? 0 : 1);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue