2018-10-06 13:25:45 +00:00
|
|
|
import { expect, tap } from '@pushrocks/tapbundle';
|
2022-03-24 13:32:49 +00:00
|
|
|
import * as smartpdf from '../ts/index.js';
|
2018-10-06 13:25:45 +00:00
|
|
|
|
|
|
|
let testSmartPdf: smartpdf.SmartPdf;
|
|
|
|
|
|
|
|
tap.test('should create a valid instance of smartpdf', async () => {
|
|
|
|
testSmartPdf = new smartpdf.SmartPdf();
|
2022-03-24 13:32:49 +00:00
|
|
|
expect(testSmartPdf).toBeInstanceOf(smartpdf.SmartPdf);
|
2018-10-06 15:35:26 +00:00
|
|
|
});
|
2018-10-06 13:25:45 +00:00
|
|
|
|
2019-05-29 12:14:02 +00:00
|
|
|
tap.test('should start the instance', async () => {
|
|
|
|
await testSmartPdf.start();
|
|
|
|
});
|
|
|
|
|
2018-10-06 13:25:45 +00:00
|
|
|
tap.test('should create a pdf from html string', async () => {
|
2022-01-06 12:10:12 +00:00
|
|
|
await testSmartPdf.getA4PdfResultForHtmlString('hi');
|
2018-10-06 13:25:45 +00:00
|
|
|
});
|
|
|
|
|
2022-01-05 16:20:28 +00:00
|
|
|
tap.test('should create a pdf from html string', async () => {
|
2022-01-06 12:10:12 +00:00
|
|
|
await testSmartPdf.getA4PdfResultForHtmlString('hi');
|
2022-01-05 16:20:28 +00:00
|
|
|
});
|
|
|
|
|
2019-05-28 22:27:43 +00:00
|
|
|
tap.test('should create a pdf from website as A4', async () => {
|
2019-11-19 15:53:14 +00:00
|
|
|
await testSmartPdf.getPdfResultForWebsite('https://www.wikipedia.org');
|
2018-10-06 13:25:45 +00:00
|
|
|
});
|
|
|
|
|
2019-05-28 22:27:43 +00:00
|
|
|
tap.test('should create a pdf from website as single page PDF', async () => {
|
2019-11-15 23:50:11 +00:00
|
|
|
await testSmartPdf.getFullWebsiteAsSinglePdf('https://www.wikipedia.org');
|
2019-05-28 22:27:43 +00:00
|
|
|
});
|
|
|
|
|
2019-05-29 17:49:23 +00:00
|
|
|
tap.test('should create a valid PDFResult', async () => {
|
2021-10-14 08:59:45 +00:00
|
|
|
const writePDfToDisk = async (urlArg: string, fileName: string) => {
|
|
|
|
const pdfResult = await testSmartPdf.getFullWebsiteAsSinglePdf(urlArg);
|
2022-03-24 13:32:49 +00:00
|
|
|
expect(pdfResult.buffer).toBeInstanceOf(Buffer);
|
2021-10-14 08:59:45 +00:00
|
|
|
const fs = await import('fs');
|
|
|
|
|
|
|
|
if (!fs.existsSync('.nogit/')) {
|
|
|
|
fs.mkdirSync('.nogit/');
|
|
|
|
}
|
|
|
|
fs.writeFileSync(`.nogit/${fileName}`, pdfResult.buffer);
|
|
|
|
};
|
|
|
|
await writePDfToDisk('https://maintainedby.lossless.com/', '1.pdf')
|
2022-03-24 13:32:49 +00:00
|
|
|
await writePDfToDisk('https://rendertron.lossless.one/render/https://fitnessloft.de/impressum/', '2.pdf')
|
2021-10-14 08:59:45 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
tap.test('should combine pdfs', async () => {
|
2019-08-14 09:18:14 +00:00
|
|
|
const fs = await import('fs');
|
2021-10-14 08:59:45 +00:00
|
|
|
const buffer1 = fs.readFileSync('.nogit/1.pdf');
|
|
|
|
const buffer2 = fs.readFileSync('.nogit/2.pdf');
|
|
|
|
fs.writeFileSync(`.nogit/combined.pdf`, await testSmartPdf.mergePdfBuffers([buffer1, buffer2]));
|
2019-08-14 09:18:14 +00:00
|
|
|
|
2021-10-14 08:59:45 +00:00
|
|
|
})
|
2019-05-29 17:49:23 +00:00
|
|
|
|
2018-10-06 15:35:26 +00:00
|
|
|
tap.test('should be able to close properly', async () => {
|
2019-05-29 12:14:02 +00:00
|
|
|
await testSmartPdf.stop();
|
2018-10-06 15:35:26 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
tap.start();
|