mirror of
https://github.com/foliojs/pdfkit.git
synced 2025-12-08 20:15:54 +00:00
* Fix further LineWrapper precision issues * add test of bounded text precision issue * add rowSpanning table example * add failure threshold * implement toContainText jest matcher * create a unit test for bounded text precision * remove round up rounding code path --------- Co-authored-by: Luiz Américo Pereira Câmara <blikblum@users.noreply.github.com>
43 lines
1.0 KiB
JavaScript
43 lines
1.0 KiB
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 = [];
|
|
|
|
(async () => {
|
|
await fn(doc);
|
|
})()
|
|
.then(() => {
|
|
doc.on('error', (err) => reject(err));
|
|
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(options);
|
|
}
|
|
resolve();
|
|
} catch (err) {
|
|
reject(err);
|
|
}
|
|
});
|
|
doc.end();
|
|
})
|
|
.catch((err) => reject(err));
|
|
});
|
|
}
|
|
|
|
export { runDocTest };
|