Skip to content

Commit

Permalink
fix improper warnings for invalid reporters
Browse files Browse the repository at this point in the history
also: reorganize, add, and refactor a bunch of problematic unit tests for `lib/mocha.js`.  better isolation except where we can't really do that (calling `require`)

there's still missing tests in here, but this is an improvement.
  • Loading branch information
boneskull committed May 8, 2020
1 parent c0137eb commit 1ba7cc6
Show file tree
Hide file tree
Showing 3 changed files with 616 additions and 325 deletions.
16 changes: 8 additions & 8 deletions lib/mocha.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,24 +202,24 @@ Mocha.prototype.reporter = function(reporter, reporterOptions) {
_reporter = require(reporter);
} catch (err) {
if (
err.code !== 'MODULE_NOT_FOUND' ||
err.message.indexOf('Cannot find module') !== -1
err.code === 'MODULE_NOT_FOUND' ||
err.message.indexOf('Cannot find module') >= 0
) {
// Try to load reporters from a path (absolute or relative)
try {
_reporter = require(path.resolve(process.cwd(), reporter));
_reporter = require(path.resolve(reporter));
} catch (_err) {
_err.code !== 'MODULE_NOT_FOUND' ||
_err.message.indexOf('Cannot find module') !== -1
? console.warn(sQuote(reporter) + ' reporter not found')
: console.warn(
_err.code === 'MODULE_NOT_FOUND' ||
_err.message.indexOf('Cannot find module') >= 0
? utils.warn(sQuote(reporter) + ' reporter not found')
: utils.warn(
sQuote(reporter) +
' reporter blew up with error:\n' +
err.stack
);
}
} else {
console.warn(
utils.warn(
sQuote(reporter) + ' reporter blew up with error:\n' + err.stack
);
}
Expand Down
1 change: 1 addition & 0 deletions test/unit/fixtures/wonky-reporter.fixture.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
throw new Error('bad weirdness in this one');
Loading

0 comments on commit 1ba7cc6

Please sign in to comment.