Permalink
Browse files

Merge pull request #2659 from sul4bh/issue/2434

Adds support for loading reporter from an absolute or relative path.
  • Loading branch information...
2 parents 2f10625 + 265299d commit 8a3cab063cfe68fa2e9aea8feada23aaf1a4db6f @Munter Munter committed on GitHub Jan 10, 2017
Showing with 11 additions and 3 deletions.
  1. +11 −3 lib/mocha.js
View
@@ -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') {

0 comments on commit 8a3cab0

Please sign in to comment.