When a test fails due to an unexpected error, mocha-error-reporters appends the full error in JSON format to the test report.
1 passing (5ms)
1 failing
1) Test Example
Test with error:
Error: Pow!
at Context.it (test/testData/testExample.js:9:17)
Full Error:
{
"additionnalAttribute": "The key to understand this bug",
"name": "Error",
"message": "Pow!",
"stack": "Error: Pow!\n at Context.it (test/testData/testExample.js:9:17)"
}
Without mocha-error-reporters, the Full Error section would ne be present and it would be impossible to read additionnalAttribute
which may be the key to understand this bug. All additionnal attributes (ex: inner error) will be fully serialized; thanks to the npm package serialize-error.
In your project, run this npm command:
npm install mocha-error-reporters --save-dev
Call mocha with:
mocha --require mocha-error-reporters --reporter=specWithFullErrors
mocha-error-reporters provides 8 reporters:
- specWithFullErrors
- minWithFullErrors
- dotWithFullErrors
- listWithFullErrors
- nyanWithFullErrors
- xUnitWithFullErrors
- progressWithFullErrors
- landingWithFullErrors
Mocha allows you to define custom reporters.
The code snippet below shows how unexpected errors can be serialized in your custom reporters.
const { extendReporterWithFullErrors } = require('mocha-error-reporters');
const yourCustomReporter;
const yourCustomReporterWithFullErrors = extendReporterWithFullErrors(yourCustomReporter);
The source code of this project is distributed under the MIT License.
See CONTRIBUTING.md.
Participation in this poject is governed by the Code of Conduct.