I have about 600 tests made with Mocha and now I need to automatically run all of them and get all errors and success count to send this information to monitoring server.
I can make bash script, which runs tests and writes Mocha log to file, then parse this log file and get success count and fail logs (for example by grep), but this is too dirty solution.
I would prefer run tests programmatically and get from Mocha something like fail messages and success tests array to work around this, but I couldn't find any docs about this.
Update from future (2025):
You can simply generate the mocha report as JSON, which will include all the failed and successful ones (even the file name and titles of failing/successful cases - and not just their count).
mocha --reporter=json --reporter-option output=filesData.json testCases.js
You can then read this JSON output and do the needful (eg. exporting to monitoring server)