mochawesome-report-generator
mochawesome-report-generator copied to clipboard
PDF Reports
It would be nice to be able to export the report into PDF. I am thinking of integrating this with a Slack bot which will run tests, and export the document via PDF and upload it to a channel. I am finding it a bit of a pain to convert the HTML into PDF (have to use like headless chrome to load the page, then print it in PDF).
Thanks for the suggestion. Exporting to PDF isn't currently on the roadmap but it's something I'll consider for future enhancements.
Thanks a bunch
Curious, update on adding export to PDF? Thank you.
TBH, I don't have much time these days to work on this project. Unless someone opens a PR for this feature it's unlikely to be added anytime soon.
So the way I got around the problem of needing to compile a single PDF is to host the HTML files using an HTTP file server (I used Go Echo v4 for this purpose, but you can probably also do this in a Node server). Basically, all css/js assets are identical for every single generated HTML file. So you only need to save 1 set of the following files on disk:
MaterialIcons-Regular.woff
MaterialIcons-Regular.woff2
app.css
app.js
roboto-light-webfont.woff
roboto-light-webfont.woff2
roboto-medium-webfont.woff
roboto-medium-webfont.woff2
roboto-regular-webfont.woff
roboto-regular-webfont.woff2
Save the above a directory called /assets/
, making sure to edit the import paths inside these files (i.e. src:url(roboto-medium-webfont.woff2) format("woff2"),url(roboto-medium-webfont.woff) format("woff");
becomes src:url(/assets/roboto-medium-webfont.woff2) format("woff2"),url(/assets/roboto-medium-webfont.woff) format("woff");
. Then make sure the assets
folder contents are accessible on the above server via the path /assets
.
After Mocha finishes running, and the HTML file is generated, just rename the file mochawesome.html
to index.html
, and nuke all other generated files. Then I create a new directory with the structure reports/yyyy-mm-dd_hh-mm-ss
and move index.html
into that directory. Then do string replacement on all src
and href
to use /assets/filename
inside of index.html
(i.e. <script src="/assets/app.js"></script>
).
Then you can just host the file directory reports/yyyy-mm-dd_hh-mm-ss
at /reports/yyyy-mm-dd_hh-mm-ss
on this server.
Not an ideal solution, but works well enough for my organization. This becomes even more secure if you use a basic auth middleware in that server to password protect the mocha awesome test results from prying eyes.
Unless someone opens a PR for this feature it's unlikely to be added anytime soon.
🤔
I am wondering if a PDF report be generated headlessly