mocha-jenkins-reporter
mocha-jenkins-reporter copied to clipboard
mocha-jenkins-reporter changes how console.log works
We have a test which checks a linting command. To avoid output to be printed to the console during the test case, we use sinon.stub
(https://github.com/ipfs/aegir/blob/d57dd3f59fc752a44aa462c767565977dc18f047/test/lint.spec.js#L8-L13).
However, this doesn't work very nicely with mocha-jenkins-reporter as it also overloads the console.log function, to save the logging output. But after the test finishes, and mocha-jenkins-reporter is supposed to write the results, it fails due to console.log not having added the log rows during this test run. Implementation of this is here: https://github.com/juhovh/mocha-jenkins-reporter/blob/d2da9ad26a0592083eb7969e06fc26831bab8d57/lib/jenkins.js#L323-L326
Instead, it would be better for mocha-jenkins-reporter to listen to process.stdout
so nothing have to be overloaded but still be able to capture debugging output.
this same thing causes a test fail if console.log is stubbed and console.log.restore()
is called later on. To fix this I assigned spy to a variable then use restore() on it