Skip to content

extendReporterWithFullErrors is incompatible with mocha-junit-reporter #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
bericp1 opened this issue Sep 21, 2021 · 1 comment
Open

Comments

@bericp1
Copy link

bericp1 commented Sep 21, 2021

Hey all! Firstly, thanks for the helpful util!

One note though is that in its current form, extendReporterWithFullErrors is incompatible with the popular mocha-junit-reporter. Since extendReporterWithFullErrors calls superReporter.call(this, runner, options); before calling withFullErrors, the JUnit reporter attaches its fail handler first which serializes the error to a string for the later-generated XML before addFullErrorIfMeaningful is ever called to modify error.stack.

I fixed this by adding the fail handler before calling the JUnit constructor:

junitWithFullErrors.js:

const { inherits } = require('util');
const addFullErrorIfMeaningful = require('mocha-error-reporters/lib/addFullErrorIfMeaningful');
const JUnitReporter = require('mocha-junit-reporter');

function JUnitReporterWithFullErrors(runner, options) {
  // `mocha-error-reporters` has a `extendReporterWithFullErrors` util but we manually pull in
  // `addFullErrorIfMeaningful` and extend the JUnit reporter in order to ensure that our
  // `.on('fail', ...)` is called before JUnit's `.on('fail', ...` so that the full error data is
  // appended to `error.stack` before JUnit serializes it to XML.
  runner.on('fail', (test, error) => addFullErrorIfMeaningful(error));
  JUnitReporter.call(this, runner, options);
}
inherits(JUnitReporterWithFullErrors, JUnitReporter);

module.exports = JUnitReporterWithFullErrors;
@steph-lebl
Copy link
Contributor

steph-lebl commented Sep 23, 2021 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants