Skip to content

Commit

Permalink
Correctly diagnose errors from required runner module (mochajs#3596)
Browse files Browse the repository at this point in the history
  • Loading branch information
aido179 committed Dec 4, 2018
1 parent b636faf commit b3dd8d3
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions lib/mocha.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,12 +186,14 @@ Mocha.prototype.reporter = function(reporter, reporterOptions) {
try {
_reporter = require(reporter);
} catch (err) {
if (err.message.indexOf('Cannot find module') !== -1) {
if (
err.message.indexOf("Cannot find module '" + reporter + "'") !== -1
) {
// Try to load reporters from a path (absolute or relative)
try {
_reporter = require(path.resolve(process.cwd(), reporter));
} catch (_err) {
err.message.indexOf('Cannot find module') !== -1
err.message.indexOf("Cannot find module '" + reporter + "'") !== -1
? console.warn('"' + reporter + '" reporter not found')
: console.warn(
'"' +
Expand All @@ -200,6 +202,10 @@ Mocha.prototype.reporter = function(reporter, reporterOptions) {
err.stack
);
}
} else if (err.message.indexOf("Cannot find module 'mocha'") !== -1) {
console.warn(
'Mocha could not be found from within the reporter package.'
);
} else {
console.warn(
'"' + reporter + '" reporter blew up with error:\n' + err.stack
Expand Down

0 comments on commit b3dd8d3

Please sign in to comment.