smartpdf/test/test.ts

45 lines
1.3 KiB
TypeScript
Raw Permalink 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.getPdfForHtmlString('hi');
});
2019-05-28 22:27:43 +00:00
tap.test('should create a pdf from website as A4', async () => {
2019-04-10 13:12:54 +00:00
await testSmartPdf.getPdfForWebsite('https://maintainedby.lossless.com');
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 () => {
await testSmartPdf.getFullWebsiteAsSinglePdf('https://maintainedby.lossless.com');
});
2019-05-29 17:49:23 +00:00
tap.test('should create a valid PDFResult', async () => {
2019-06-04 09:29:30 +00:00
const pdfResult = await testSmartPdf.getFullWebsiteAsSinglePdf(
'https://maintainedby.lossless.com'
);
2019-05-29 17:49:23 +00:00
expect(pdfResult.buffer).to.be.instanceOf(Buffer);
2019-08-14 09:18:14 +00:00
const fs = await import('fs');
if (!fs.existsSync('.nogit/')) {
fs.mkdirSync('.nogit/');
}
fs.writeFileSync('.nogit/sample.pdf', pdfResult.buffer);
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();