mirror of
https://github.com/snapotter-hq/SnapOtter.git
synced 2026-08-03 07:46:42 +02:00
56 lines
1.7 KiB
TypeScript
56 lines
1.7 KiB
TypeScript
import { readFileSync } from "node:fs";
|
|
import { mkdtemp, rm, writeFile } from "node:fs/promises";
|
|
import { tmpdir } from "node:os";
|
|
import { join } from "node:path";
|
|
import { buildPandocArgs, pandocAvailable, runPandoc } from "@snapotter/doc-engine";
|
|
import { afterAll, beforeAll, describe, expect, it } from "vitest";
|
|
|
|
describe("pandocAvailable", () => {
|
|
it("returns a boolean without throwing", () => {
|
|
expect(typeof pandocAvailable()).toBe("boolean");
|
|
});
|
|
});
|
|
|
|
describe("buildPandocArgs", () => {
|
|
it("runs conversions inside the pandoc sandbox", () => {
|
|
expect(buildPandocArgs("input.md", "out.docx")).toEqual([
|
|
"--sandbox",
|
|
"input.md",
|
|
"-o",
|
|
"out.docx",
|
|
]);
|
|
});
|
|
|
|
it("keeps extra args after the sandboxed input/output args", () => {
|
|
expect(buildPandocArgs("input.md", "out.html", { extraArgs: ["--standalone"] })).toEqual([
|
|
"--sandbox",
|
|
"input.md",
|
|
"-o",
|
|
"out.html",
|
|
"--standalone",
|
|
]);
|
|
});
|
|
});
|
|
|
|
describe.skipIf(!pandocAvailable())("runPandoc (requires pandoc)", () => {
|
|
let tmpDir: string;
|
|
|
|
beforeAll(async () => {
|
|
tmpDir = await mkdtemp(join(tmpdir(), "pandoc-test-"));
|
|
});
|
|
|
|
afterAll(async () => {
|
|
await rm(tmpDir, { recursive: true, force: true }).catch(() => {});
|
|
});
|
|
|
|
it("converts a trivial markdown file to html", async () => {
|
|
const mdPath = join(tmpDir, "test.md");
|
|
const htmlPath = join(tmpDir, "test.html");
|
|
await writeFile(mdPath, "# Hello\n\nWorld\n");
|
|
await runPandoc(mdPath, htmlPath, { extraArgs: ["--standalone"] });
|
|
const html = readFileSync(htmlPath, "utf8");
|
|
expect(html).toContain("Hello");
|
|
expect(html).toContain("<");
|
|
}, 30_000);
|
|
});
|