2023-07-26 14:17:11 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								import { expect, tap } from '@push.rocks/tapbundle';
							 | 
						
					
						
							
								
									
										
										
										
											2022-03-24 14:32:49 +01: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 14:32:49 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  expect(testSmartPdf).toBeInstanceOf(smartpdf.SmartPdf);
							 | 
						
					
						
							
								
									
										
										
										
											2018-10-06 17:35:26 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								});
							 | 
						
					
						
							
								
									
										
										
										
											2018-10-06 13:25:45 +00:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2019-05-29 14:14:02 +02: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 13:10:12 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  await testSmartPdf.getA4PdfResultForHtmlString('hi');
							 | 
						
					
						
							
								
									
										
										
										
											2018-10-06 13:25:45 +00:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								});
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2022-01-05 17:20:28 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								tap.test('should create a pdf from html string', async () => {
							 | 
						
					
						
							
								
									
										
										
										
											2022-01-06 13:10:12 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  await testSmartPdf.getA4PdfResultForHtmlString('hi');
							 | 
						
					
						
							
								
									
										
										
										
											2022-01-05 17:20:28 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								});
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2019-05-29 00:27:43 +02: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-29 00:27:43 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								tap.test('should create a pdf from website as single page PDF', async () => {
							 | 
						
					
						
							
								
									
										
										
										
											2019-11-16 00:50:11 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  await testSmartPdf.getFullWebsiteAsSinglePdf('https://www.wikipedia.org');
							 | 
						
					
						
							
								
									
										
										
										
											2019-05-29 00:27:43 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								});
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2019-05-29 19:49:23 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								tap.test('should create a valid PDFResult', async () => {
							 | 
						
					
						
							
								
									
										
										
										
											2021-10-14 10:59:45 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  const writePDfToDisk = async (urlArg: string, fileName: string) => {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    const pdfResult = await testSmartPdf.getFullWebsiteAsSinglePdf(urlArg);
							 | 
						
					
						
							
								
									
										
										
										
											2022-03-24 14:32:49 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    expect(pdfResult.buffer).toBeInstanceOf(Buffer);
							 | 
						
					
						
							
								
									
										
										
										
											2021-10-14 10:59:45 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    const fs = await import('fs');
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    if (!fs.existsSync('.nogit/')) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      fs.mkdirSync('.nogit/');
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    }
							 | 
						
					
						
							
								
									
										
										
										
											2022-06-15 22:14:55 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    fs.writeFileSync(`.nogit/${fileName}`, pdfResult.buffer as Buffer);
							 | 
						
					
						
							
								
									
										
										
										
											2021-10-14 10:59:45 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  };
							 | 
						
					
						
							
								
									
										
										
										
											2023-07-26 14:17:11 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  await writePDfToDisk('https://lossless.com/', '1.pdf');
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  await writePDfToDisk('https://layer.io', '2.pdf');
							 | 
						
					
						
							
								
									
										
										
										
											2021-10-14 10:59:45 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								});
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								tap.test('should combine pdfs', async () => {
							 | 
						
					
						
							
								
									
										
										
										
											2019-08-14 11:18:14 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  const fs = await import('fs');
							 | 
						
					
						
							
								
									
										
										
										
											2022-06-15 22:14:55 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  const pdf1 = await testSmartPdf.readFileToPdfObject('.nogit/1.pdf');
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  const pdf2 = await testSmartPdf.readFileToPdfObject('.nogit/2.pdf');
							 | 
						
					
						
							
								
									
										
										
										
											2022-10-26 23:04:59 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  fs.writeFileSync(
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    `.nogit/combined.pdf`,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    (await testSmartPdf.mergePdfs([pdf1, pdf2])).buffer as Buffer
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  );
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								});
							 | 
						
					
						
							
								
									
										
										
										
											2019-05-29 19:49:23 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2018-10-06 17:35:26 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								tap.test('should be able to close properly', async () => {
							 | 
						
					
						
							
								
									
										
										
										
											2019-05-29 14:14:02 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  await testSmartPdf.stop();
							 | 
						
					
						
							
								
									
										
										
										
											2018-10-06 17:35:26 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								});
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								tap.start();
							 |