Files
fegger ff21ec921a Add test script and initial test suite
The test runner bundles TypeScript tests with esbuild and executes them using Node's built-in test runner. Tests cover
document downloader behavior, path utilities, rmapi bridge configuration, style refinement, and ZIP file handling. Mock
implementations for Obsidian plugin interfaces enable isolated unit testing.
2026-05-31 16:33:30 +02:00

47 lines
1.7 KiB
TypeScript

import test from "node:test";
import assert from "node:assert/strict";
import { mkdir, mkdtemp, writeFile } from "fs/promises";
import { tmpdir } from "os";
import { dirname, join } from "path";
import { getPageFiles, isNotebook, listRmContents } from "../src/utils/zip";
async function createExtractedDir(files: string[]): Promise<string> {
const dir = await mkdtemp(join(tmpdir(), "remarkable-zip-test-"));
for (const file of files) {
const filePath = join(dir, ...file.split("/"));
await mkdir(dirname(filePath), { recursive: true });
await writeFile(filePath, "");
}
return dir;
}
test("listRmContents recursively lists files without shelling out to find", async () => {
const dir = await createExtractedDir(["content.json", "pages/2.rm", "pages/nested/1.rm"]);
const contents = (await listRmContents(dir)).map((path) => path.replace(`${dir}/`, "")).sort();
assert.deepEqual(contents, ["content.json", "pages/2.rm", "pages/nested/1.rm"]);
});
test("getPageFiles returns sorted nested page files", async () => {
const dir = await createExtractedDir(["pages/2.rm", "pages/1.rm", "pages/ignored.zip"]);
const pages = (await getPageFiles(dir)).map((path) => path.replace(`${dir}/`, ""));
assert.deepEqual(pages, ["pages/1.rm", "pages/2.rm"]);
});
test("isNotebook treats annotated PDFs as non-notebooks", async () => {
const dir = await createExtractedDir(["pages/1.rm", "content.pdf"]);
assert.equal(await isNotebook(dir), false);
});
test("isNotebook accepts extracted notebooks with rm pages and no PDF", async () => {
const dir = await createExtractedDir(["pages/1.rm", "content.json"]);
assert.equal(await isNotebook(dir), true);
});