mirror of
https://github.com/foliojs/pdfkit.git
synced 2025-12-08 20:15:54 +00:00
* Bump fontkit and linebreak deps * Bump fontkit to 2.0.0 * Bump * Drop old node versions * Bump testing dependencies * Update pdfjs * fix jest to compatibility with restructure, update fontkit, refresh snapshots * Update CHANGELOG.md --------- Co-authored-by: Libor M. <liborm85@gmail.com>
38 lines
848 B
JavaScript
38 lines
848 B
JavaScript
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 };
|