Skip to content

Commit dc61a68

Browse files
committed
[INT-1] visual-snapshots: fix PdfConverter
1 parent c1880b1 commit dc61a68

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

Diff for: visual-js/visual-snapshots/src/app/pdf-converter.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@ export class PdfConverter {
77
public async *convertPagesToImages(
88
pdfFilePath: string
99
): AsyncGenerator<Buffer> {
10-
return await this._pdf(pdfFilePath, { scale: 1 });
10+
for await (const pdfPageImage of await this._pdf(pdfFilePath, {
11+
scale: 1,
12+
})) {
13+
yield pdfPageImage;
14+
}
1115
}
1216

1317
public createPdfFile(pdfFilePath: string): PdfFile {

Diff for: visual-js/visual-snapshots/test/app/pdf-converter.spec.ts

+16-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
import path from "path";
12
import { PdfConverter } from "../../src/app/pdf-converter.js";
3+
import { __dirname } from "../helpers.js";
24

35
describe("PdfConverter", () => {
46
test("convertPagesToImages", async () => {
5-
const pdf = jest.fn();
7+
const pdf = jest.fn().mockResolvedValue([]);
68

79
const pdfFilePath = "./fake-pdf-file-path.pdf";
810
const pdfConverter = new PdfConverter(pdf);
@@ -12,8 +14,20 @@ describe("PdfConverter", () => {
1214
expect(pdf).toHaveBeenCalledWith(pdfFilePath, { scale: 1 });
1315
});
1416

17+
test("convertPagesToImages", async () => {
18+
const pdfFilePath = path.join(__dirname(import.meta), "../files/test.pdf");
19+
const pdfConverter = new PdfConverter();
20+
21+
let pages = 0;
22+
for await (const _ of pdfConverter.convertPagesToImages(pdfFilePath)) {
23+
pages++;
24+
}
25+
26+
expect(pages).toEqual(3);
27+
});
28+
1529
test("createPdfFile", async () => {
16-
const pdf = jest.fn();
30+
const pdf = jest.fn().mockResolvedValue([]);
1731
const pdfConverter = new PdfConverter(pdf);
1832

1933
const pdfFilePath = "./fake-pdf-file-path.pdf";

Diff for: visual-js/visual-snapshots/test/files/test.pdf

51.7 KB
Binary file not shown.

0 commit comments

Comments
 (0)