-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathhelpers.js
More file actions
37 lines (32 loc) · 848 Bytes
/
helpers.js
File metadata and controls
37 lines (32 loc) · 848 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import PDFDocument from '../../lib/document';
import { pdf2png } from './pdf2png.js';
function runDocTest(options, fn) {
if (typeof options === 'function') {
fn = options;
options = {};
}
if (!options.info) {
options.info = {};
}
return new Promise((resolve, reject) => {
const doc = new PDFDocument(options);
const buffers = [];
fn(doc);
doc.on('data', buffers.push.bind(buffers));
doc.on('end', async () => {
try {
const pdfData = Buffer.concat(buffers);
const { systemFonts = false } = options;
const images = await pdf2png(pdfData, { systemFonts });
for (let image of images) {
expect(image).toMatchImageSnapshot();
}
resolve();
} catch (err) {
reject(err)
}
});
doc.end();
});
}
export { runDocTest };