Skip to content

Commit

Permalink
fix: save PDF in the same folder as HTML
Browse files Browse the repository at this point in the history
  • Loading branch information
PierreDemailly committed Jul 20, 2024
1 parent 5d74a18 commit f8bbda9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
13 changes: 9 additions & 4 deletions src/api/report.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
17 changes: 11 additions & 6 deletions src/reporting/pdf.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand All @@ -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();
Expand Down

0 comments on commit f8bbda9

Please sign in to comment.