Skip to content

Commit

Permalink
add more tests in the node environment
Browse files Browse the repository at this point in the history
  • Loading branch information
k-yle committed Jun 8, 2024
1 parent 67435a8 commit 98ce302
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 0 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
32 changes: 32 additions & 0 deletions tests/node.test.ts
Original file line number Diff line number Diff line change
@@ -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";

Expand All @@ -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();
}
});
});

0 comments on commit 98ce302

Please sign in to comment.