diff --git a/tests/__image_snapshots__/node-test-ts-buffer-can-load-a-document-from-a-buffer-1-snap.png b/tests/__image_snapshots__/node-test-ts-buffer-can-load-a-document-from-a-buffer-1-snap.png new file mode 100644 index 0000000..7a90aff Binary files /dev/null and b/tests/__image_snapshots__/node-test-ts-buffer-can-load-a-document-from-a-buffer-1-snap.png differ diff --git a/tests/__image_snapshots__/node-test-ts-data-url-can-load-a-document-from-a-data-url-1-snap.png b/tests/__image_snapshots__/node-test-ts-data-url-can-load-a-document-from-a-data-url-1-snap.png new file mode 100644 index 0000000..7a90aff Binary files /dev/null and b/tests/__image_snapshots__/node-test-ts-data-url-can-load-a-document-from-a-data-url-1-snap.png differ diff --git a/tests/__image_snapshots__/node-test-ts-readable-stream-can-load-a-document-from-a-readable-stream-1-snap.png b/tests/__image_snapshots__/node-test-ts-readable-stream-can-load-a-document-from-a-readable-stream-1-snap.png new file mode 100644 index 0000000..7a90aff Binary files /dev/null and b/tests/__image_snapshots__/node-test-ts-readable-stream-can-load-a-document-from-a-readable-stream-1-snap.png differ diff --git a/tests/node.test.ts b/tests/node.test.ts index 8d70d3c..fdfc22b 100644 --- a/tests/node.test.ts +++ b/tests/node.test.ts @@ -1,4 +1,5 @@ // @vitest-environment node +import { createReadStream, promises as fs } from "node:fs"; import { describe, expect, it } from "vitest"; import { pdf } from "../src"; @@ -9,3 +10,34 @@ describe("example.pdf in node", () => { } }); }); + +describe("data url", () => { + it("can load a document from a data URL", async () => { + const b64 = await fs.readFile("./tests/example.pdf", "base64"); + const dataUrl = `data:application/pdf;base64,${b64}`; + + for await (const page of await pdf(dataUrl)) { + expect(page).toMatchImageSnapshot(); + } + }); +}); + +describe("Buffer", () => { + it("can load a document from a buffer", async () => { + const buf = await fs.readFile("./tests/example.pdf"); + + for await (const page of await pdf(buf)) { + expect(page).toMatchImageSnapshot(); + } + }); +}); + +describe("ReadableStream", () => { + it("can load a document from a ReadableStream", async () => { + const readableStream = createReadStream("./tests/example.pdf"); + + for await (const page of await pdf(readableStream)) { + expect(page).toMatchImageSnapshot(); + } + }); +});