smartpdf/test/test.ts

59 lines
1.9 KiB
TypeScript
Raw Normal View History

2018-10-06 13:25:45 +00:00
import { expect, tap } from '@pushrocks/tapbundle';
2018-10-06 15:35:26 +00:00
import * as smartpdf from '../ts/index';
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();
expect(testSmartPdf).to.be.instanceof(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 () => {
await testSmartPdf.getPdfResultForHtmlString('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 () => {
await testSmartPdf.getPdfResultForHtmlString('hi');
});
2019-05-28 22:27:43 +00:00
tap.test('should create a pdf from website as A4', async () => {
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);
expect(pdfResult.buffer).to.be.instanceOf(Buffer);
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-01-05 22:55:37 +00:00
await writePDfToDisk('https://rendertron.lossless.one/render/https://lossless.com', '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();