This could be “Hey, use mochawesome with Cypress and you’re good to go”. It used to be like that. But Cypress team decided to make some (acceptable) changes and now the tests are running in isolation. This is, by default, making Mochawesome generating only one test report, with the latest test script. So the (probably subject to change) solution is to do a bit of tweaking. Here are the steps, assuming your report folder is the default mochawesome-report location:
- Install the lovely libraries Mochawesome and mochawesome-merge
- Add Mochawesome config to
cypress.jsonfile (overwritting must be off, so now you will have a json report for each test script):
- First of all, cleanup the Mochawesome report folder. Delete it, even.
rm -fr mochawesome-report — you’re not using Windows, riiiight?
- Run the tests in headless mode — you’re doing that already, right?
npx cypress run
- Run reports merging (it will create a single json file from all tests reports)
npx mochawesome-merge — reportDir mochawesome-report > mochawesome-report/output.json
- Generate reports
npx marge output.json
Or you could just configure package.json project config with some relevant scripts:
"test": "npm start & cypress run",
"e2e": "cypress run",
"cy:run": "cypress run",
"cy:run:record": "cypress run --record",
"cy:open": "cypress open",
"cleanup": "rm -fr mochawesome-report",
"merge_reports": "mochawesome-merge --reportDir mochawesome-report > mochawesome-report/output.json",
"generate_mochawesome_report": "marge mochawesome-report/output.json",
"e2e_mochawesome": "npm run cleanup; cypress run; npm run merge_reports; npm run generate_mochawesome_report"
and then you use
npm run e2e_mochawesome