2023-07-26 12:17:11 +00:00
|
|
|
import { expect, tap } from '@push.rocks/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/');
|
|
|
|
}
|
2022-06-15 20:14:55 +00:00
|
|
|
fs.writeFileSync(`.nogit/${fileName}`, pdfResult.buffer as Buffer);
|
2021-10-14 08:59:45 +00:00
|
|
|
};
|
2023-07-26 12:17:11 +00:00
|
|
|
await writePDfToDisk('https://lossless.com/', '1.pdf');
|
|
|
|
await writePDfToDisk('https://layer.io', '2.pdf');
|
2021-10-14 08:59:45 +00:00
|
|
|
});
|
|
|
|
|
2024-04-25 16:48:08 +00:00
|
|
|
tap.test('should merge pdfs', async () => {
|
2019-08-14 09:18:14 +00:00
|
|
|
const fs = await import('fs');
|
2022-06-15 20:14:55 +00:00
|
|
|
const pdf1 = await testSmartPdf.readFileToPdfObject('.nogit/1.pdf');
|
|
|
|
const pdf2 = await testSmartPdf.readFileToPdfObject('.nogit/2.pdf');
|
2022-10-26 21:04:59 +00:00
|
|
|
fs.writeFileSync(
|
|
|
|
`.nogit/combined.pdf`,
|
2024-04-25 16:48:08 +00:00
|
|
|
await testSmartPdf.mergePdfs([pdf1.buffer, pdf2.buffer])
|
2022-10-26 21:04:59 +00:00
|
|
|
);
|
|
|
|
});
|
2019-05-29 17:49:23 +00:00
|
|
|
|
2024-04-25 16:48:08 +00:00
|
|
|
tap.test('should create images from an pdf', async () => {
|
|
|
|
const pdfObject = await testSmartPdf.readFileToPdfObject('.nogit/combined.pdf');
|
|
|
|
const images = await testSmartPdf.convertPDFToJPGBytes(pdfObject.buffer);
|
|
|
|
console.log(images);
|
|
|
|
});
|
|
|
|
|
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();
|