Skip to content

Commit

Permalink
Merge pull request #1148 from trjohnst/1115_tapreporter-extensions
Browse files Browse the repository at this point in the history
Inheriting from internal reporters
  • Loading branch information
johanneswuerbach committed Jun 27, 2017
2 parents 10199a1 + f18402d commit 713a029
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
5 changes: 1 addition & 4 deletions docs/custom_reporter.md
Expand Up @@ -71,8 +71,5 @@ To use your custom reporter, set `reporter` in your `testem.js` config file:
"src/*.js",
"tests/*_tests.js"
]
"reporter": new MyReporter()
"reporter": MyReporter
};



4 changes: 4 additions & 0 deletions lib/utils/reporter.js
Expand Up @@ -14,6 +14,10 @@ function setupReporter(name, out, config, app) {
if (TestReporter) {
reporter = new TestReporter(false, out, config, app);
}
} else if (isa(name, Function)) {
// name is a constructor function, ignore new-cap and instantiate
// eslint-disable-next-line new-cap
reporter = new name(false, out, config, app);
} else {
reporter = name;
}
Expand Down
18 changes: 18 additions & 0 deletions tests/utils/reporter_tests.js
Expand Up @@ -11,6 +11,7 @@ var tmpNameAsync = Bluebird.promisify(tmp.tmpName);

var Reporter = require('../../lib/utils/reporter');
var FakeReporter = require('../support/fake_reporter');
var TapReporter = require('../../lib/reporters/tap_reporter');

var fsReadFileAsync = Bluebird.promisify(fs.readFile);
var fsUnlinkAsync = Bluebird.promisify(fs.unlink);
Expand Down Expand Up @@ -179,6 +180,23 @@ describe('Reporter', function() {
});
});

it('creates a reporter when custom reporter dependent on configs is provided', function() {
var CustomReporter = function() {
TapReporter.apply(this, arguments);
};
CustomReporter.prototype = Object.create(TapReporter.prototype);

var config = { get: sinon.stub() };
config.get.withArgs('reporter').returns(CustomReporter);
config.get.withArgs('tap_quiet_logs').returns(true);
var app = { config: config };
var reporter = new Reporter(app, stream);

expect(reporter).to.be.ok();
expect(reporter.reporters.length).to.equal(1);
expect(reporter.reporters[0].quietLogs).to.be.true();
});

it('writes xml to stream and file with xunit reporter and intermediate output is enabled', function() {
return tmpNameAsync().then(function(path) {
var stream = new PassThrough();
Expand Down

0 comments on commit 713a029

Please sign in to comment.