Skip to content
This repository has been archived by the owner on Dec 4, 2023. It is now read-only.

Commit

Permalink
Merge pull request mochajs#2659 from sul4bh/issue/2434
Browse files Browse the repository at this point in the history
Adds support for loading reporter from an absolute or relative path.
  • Loading branch information
Munter committed Jan 10, 2017
2 parents d7acdb8 + 04fd137 commit f11c090
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions lib/mocha.js
Expand Up @@ -152,9 +152,17 @@ Mocha.prototype.reporter = function (reporter, reporterOptions) {
try {
_reporter = require(reporter);
} catch (err) {
err.message.indexOf('Cannot find module') !== -1
? console.warn('"' + reporter + '" reporter not found')
: console.warn('"' + reporter + '" reporter blew up with error:\n' + err.stack);
if (err.message.indexOf('Cannot find module') !== -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 ? console.warn('"' + reporter + '" reporter not found')
: console.warn('"' + reporter + '" reporter blew up with error:\n' + err.stack);
}
} else {
console.warn('"' + reporter + '" reporter blew up with error:\n' + err.stack);
}
}
}
if (!_reporter && reporter === 'teamcity') {
Expand Down

0 comments on commit f11c090

Please sign in to comment.