| 
									
										
										
										
											2018-10-06 13:25:45 +00:00
										 |  |  | import { expect, tap } from '@pushrocks/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/'); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     fs.writeFileSync(`.nogit/${fileName}`, pdfResult.buffer); | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  |   await writePDfToDisk('https://maintainedby.lossless.com/', '1.pdf') | 
					
						
							| 
									
										
										
										
											2022-03-24 14:32:49 +01:00
										 |  |  |   await writePDfToDisk('https://rendertron.lossless.one/render/https://fitnessloft.de/impressum/', '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'); | 
					
						
							| 
									
										
										
										
											2021-10-14 10:59:45 +02: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 11:18:14 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-14 10:59:45 +02:00
										 |  |  | }) | 
					
						
							| 
									
										
										
										
											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(); |