Skip to content

Commit

Permalink
Configuration: allow "getReporter" method to require node modules
Browse files Browse the repository at this point in the history
  • Loading branch information
markelog committed May 29, 2015
1 parent 3850b15 commit e76c2f0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 14 deletions.
9 changes: 9 additions & 0 deletions lib/cli-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,15 @@ exports.getReporter = function(reporter, colors) {
writer = null;
}

if (!writer) {
try {
writer = require(reporter);
writerPath = reporter;
} catch (e) {
writer = null;
}
}

return {
path: writerPath,
writer: writer
Expand Down
28 changes: 14 additions & 14 deletions test/specs/cli-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,20 +162,6 @@ describe('modules/cli-config', function() {
assert.equal(reporter.path, path.resolve('./lib/reporters/junit'));
});

it('should get junit reporter with part of the path', function() {
var reporter = configFile.getReporter('./junit.js');

assert.equal(typeof reporter.writer, 'function');
assert.equal(reporter.path, path.resolve('./lib/reporters/junit.js'));
});

it('should get junit reporter with part of the path without extension', function() {
var reporter = configFile.getReporter('./junit');

assert.equal(typeof reporter.writer, 'function');
assert.equal(reporter.path, path.resolve('./lib/reporters/junit'));
});

it('should get reporter with partial path', function() {
var reporter = configFile.getReporter('./test/data/reporter/test-reporter.js');

Expand All @@ -202,5 +188,19 @@ describe('modules/cli-config', function() {

configFile.__set__('supportsColor', old);
});

it('should fake reporter from node', function() {
var reporter = configFile.getReporter('path');

assert.equal(typeof reporter.writer, 'object');
assert.equal(reporter.path, 'path');
});

it('should fake reporter from node_modules', function() {
var reporter = configFile.getReporter('sinon');

assert.equal(typeof reporter.writer, 'object');
assert.equal(reporter.path, 'sinon');
});
});
});

0 comments on commit e76c2f0

Please sign in to comment.