mirror of
https://github.com/snapotter-hq/SnapOtter.git
synced 2026-08-03 07:46:42 +02:00
feat(tools): 2.0 phase 5 wave 4 - office, ebooks, data, archives (14 tools) (#224)
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
import { parseConvertTarget } from "@snapotter/doc-engine";
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
describe("parseConvertTarget", () => {
|
||||
it("returns a bare extension unchanged", () => {
|
||||
const result = parseConvertTarget("pdf");
|
||||
expect(result).toEqual({ ext: "pdf", convertTo: "pdf" });
|
||||
});
|
||||
|
||||
it("splits on the first colon for qualified filter targets", () => {
|
||||
const result = parseConvertTarget("docx:MS Word 2007 XML");
|
||||
expect(result).toEqual({ ext: "docx", convertTo: "docx:MS Word 2007 XML" });
|
||||
});
|
||||
|
||||
it("handles filter names with colons after the first", () => {
|
||||
const result = parseConvertTarget("csv:Text - txt - csv (StarCalc):44,34,76,1");
|
||||
expect(result).toEqual({
|
||||
ext: "csv",
|
||||
convertTo: "csv:Text - txt - csv (StarCalc):44,34,76,1",
|
||||
});
|
||||
});
|
||||
|
||||
it("handles single-character extensions", () => {
|
||||
const result = parseConvertTarget("a:SomeFilter");
|
||||
expect(result).toEqual({ ext: "a", convertTo: "a:SomeFilter" });
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,34 @@
|
||||
import { readFileSync } from "node:fs";
|
||||
import { mkdtemp, rm, writeFile } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import { 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.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);
|
||||
});
|
||||
Reference in New Issue
Block a user