32 lines
1.0 KiB
TypeScript
32 lines
1.0 KiB
TypeScript
import { PassThrough } from "node:stream";
|
|
import { describe, expect, it } from "vitest";
|
|
|
|
import { serializeExportTableToPdfStream } from "./index.js";
|
|
|
|
async function collect(stream: PassThrough): Promise<Buffer> {
|
|
const chunks: Buffer[] = [];
|
|
for await (const chunk of stream) {
|
|
chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
|
|
}
|
|
return Buffer.concat(chunks);
|
|
}
|
|
|
|
describe("serializeExportTableToPdfStream — title omitted", () => {
|
|
it("renders a valid PDF without a title heading", async () => {
|
|
const sink = new PassThrough();
|
|
const collected = collect(sink);
|
|
|
|
// No `title` option -> the title <Text> node is skipped (null branch).
|
|
const result = await serializeExportTableToPdfStream(sink, {
|
|
columns: [{ key: "id", label: "Identifier" }],
|
|
rows: [{ id: 1 }, { id: 2 }],
|
|
});
|
|
sink.end();
|
|
|
|
expect(result).toEqual({ rowCount: 2 });
|
|
const buffer = await collected;
|
|
expect(buffer.slice(0, 5).toString("utf8")).toBe("%PDF-");
|
|
expect(buffer.byteLength).toBeGreaterThan(100);
|
|
});
|
|
});
|