From f8bbda9889a1e7509040b866368ac230f8044aa4 Mon Sep 17 00:00:00 2001 From: PierreDemailly Date: Sat, 20 Jul 2024 15:48:19 +0200 Subject: [PATCH] fix: save PDF in the same folder as HTML --- src/api/report.js | 13 +++++++++---- src/reporting/pdf.js | 17 +++++++++++------ 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/src/api/report.js b/src/api/report.js index dfe644b..bf6b534 100644 --- a/src/api/report.js +++ b/src/api/report.js @@ -36,10 +36,15 @@ export async function report( finalReportLocation ); - return await PDF(reportHTMLPath, { - title: reportConfig.title, - saveOnDisk: savePDFOnDisk - }); + if (reportConfig.reporters.includes("pdf")) { + return await PDF(reportHTMLPath, { + title: reportConfig.title, + saveOnDisk: savePDFOnDisk, + reportOutputLocation: finalReportLocation + }); + } + + return reportHTMLPath; } finally { if (reportOutputLocation === null) { diff --git a/src/reporting/pdf.js b/src/reporting/pdf.js index 4c294b1..ef23522 100644 --- a/src/reporting/pdf.js +++ b/src/reporting/pdf.js @@ -13,7 +13,11 @@ export async function PDF( reportHTMLPath, options ) { - const { title, saveOnDisk = true } = options; + const { + title, + saveOnDisk = true, + reportOutputLocation = CONSTANTS.DIRS.REPORTS + } = options; const browser = await puppeteer.launch({ args: ["--no-sandbox", "--disable-setuid-sandbox"] @@ -27,16 +31,17 @@ export async function PDF( timeout: 20_000 }); + const reportPath = saveOnDisk ? path.join( + reportOutputLocation, + utils.cleanReportName(title, ".pdf") + ) : undefined; const pdfBuffer = await page.pdf({ - path: saveOnDisk ? path.join( - CONSTANTS.DIRS.REPORTS, - utils.cleanReportName(title, ".pdf") - ) : undefined, + path: reportPath, format: "A4", printBackground: true }); - return saveOnDisk ? path : pdfBuffer; + return saveOnDisk ? reportPath : pdfBuffer; } finally { await page.close();