Skip to content

Commit

Permalink
Use reportOptions config as the second argument to report init
Browse files Browse the repository at this point in the history
Fix issue bitovi#153
  • Loading branch information
ivospinheiro committed Jan 25, 2019
1 parent 614a3b2 commit 19122d0
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ On the command line, you have the following options available:
* `-R`, `--root [path|URL]`: The server root path or URL the files are relative to
* `-p`, `--port` `[port]`: The port to run the server on (default: `3621`)
* `-r`, `--reporter` `[name]`: The name of the reporter to use (default: `Dot`)
* `--reporter-options` `[options]`: The reporter specific options (separated by a comma)
* `-c`, `--config` `[file]`: Use this JSON or JS configuration file (can be overridden by command line options)
* `--timeout` `[seconds]`: The per test timeout (in seconds)
* `--delay` `[ms]`: When running multiple tests, the time to wait for the browser to shut down before starting it with a new page.
Expand Down
14 changes: 13 additions & 1 deletion bin/testee
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ program.version(pkg.version)
.option('-p, --port [port]', 'The server port')
.option('-R, --root [path]', 'The server root path the files are relative to')
.option('-r, --reporter [name]', 'The name of the reporter to use')
.option('--reporter-options [options]', 'The reporter specific options (separated by a comma)')
.option('-c --config [filename]', 'Use a JSON or JS configuration file')
.option('--coverage', 'Track code coverage and write to console (if not running as server)')
.option('--timeout [seconds]', 'The per test timeout (in seconds)')
Expand All @@ -32,7 +33,18 @@ var browsers = _.isArray(config.browsers) ? config.browsers :

// passing `--coverage` will not instrument node_modules by default
config.coverage = config.coverage !== true ? config.coverage :
{ ignore: [ "node_modules" ] };
{ ignore: [ "node_modules" ] };

if (program.reporterOptions) {
config.reporterOptions = {};

var reporterOptionsArrStr = program.reporterOptions.split(",");

reporterOptionsArrStr.forEach(function (option) {
var options = option.split("=");
config.reporterOptions[options[0]] = options[1];
});
}

if(config.server) {
testee.server(config);
Expand Down
4 changes: 2 additions & 2 deletions lib/reporter/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ var testProperties = ['async', 'sync', 'timedOut', 'pending', 'file', 'duration'

// The reporter listens to service events and reports it to the command line using
// any of the Mocha reporters.
function Reporter(MochaReporter, coverage, root) {
function Reporter(MochaReporter, coverage, root, reporterOptions) {
if(typeof MochaReporter === 'string') {
if(mocha.reporters[MochaReporter]) {
MochaReporter = mocha.reporters[MochaReporter];
Expand All @@ -35,7 +35,7 @@ function Reporter(MochaReporter, coverage, root) {
// The actual (suite and test) objects we can feed to the Mocha runner
this._mochaObjects = {};
// The instantiated Mocha reporter
this.reporter = new MochaReporter(runner);
this.reporter = new MochaReporter(runner, {reporterOptions: reporterOptions});
// This is where we store errors so that we can report them all
// at once at the end
this.errors = [];
Expand Down
2 changes: 1 addition & 1 deletion lib/testee.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ _.extend(Testee.prototype, {

var self = this;
// We need to initialize the reporter first (in case of errors)
var reporter = new Reporter(this.options.reporter, this.options.coverage, this.options.root);
var reporter = new Reporter(this.options.reporter, this.options.coverage, this.options.root, this.options.reporterOptions);
// A deferred that runs the initialization flow
var flow = this.startServer()
// Sets up the reporter and binds Feathers service events to it
Expand Down
16 changes: 16 additions & 0 deletions test/testee.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,22 @@ describe('Testee', function () {
});
});

it('reporterOptions should be passed to reporter init', function (done) {
var reporterOptions = {
"junit_report_name": "Tests"
};

var _reporterOptions;
var _reporter = function(runner, options) {
_reporterOptions = options.reporterOptions;
};

testee.test(['examples/qunit/index.html'], browsers, Object.assign({}, config, {reporter: _reporter, reporterOptions: reporterOptions})).catch(function () {
assert.equal(reporterOptions, _reporterOptions);
done();
});
});

describe('QUnit example', function () {
it('socketio provider', function (done) {
testee.test(['examples/qunit/index.html'], browsers, config).catch(function (error) {
Expand Down

0 comments on commit 19122d0

Please sign in to comment.