From 49d0d57f759067438ae74e4d6800d76d0bd552f0 Mon Sep 17 00:00:00 2001 From: Ivo Pinheiro Date: Thu, 24 Jan 2019 23:30:33 +0000 Subject: [PATCH 1/2] Use reportOptions config as the second argument to report init Fix issue #153 --- lib/reporter/index.js | 4 ++-- lib/testee.js | 2 +- test/testee.test.js | 16 ++++++++++++++++ 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/lib/reporter/index.js b/lib/reporter/index.js index 9267541..db049a4 100644 --- a/lib/reporter/index.js +++ b/lib/reporter/index.js @@ -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]; @@ -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 = []; diff --git a/lib/testee.js b/lib/testee.js index c08c58f..383d3b2 100644 --- a/lib/testee.js +++ b/lib/testee.js @@ -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 diff --git a/test/testee.test.js b/test/testee.test.js index 8680a8e..fc2fbbc 100644 --- a/test/testee.test.js +++ b/test/testee.test.js @@ -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) { From 19122d0053af3f0e0b2d5b50120c75abb31b5847 Mon Sep 17 00:00:00 2001 From: Ivo Pinheiro Date: Thu, 24 Jan 2019 23:30:33 +0000 Subject: [PATCH 2/2] Use reportOptions config as the second argument to report init Fix issue #153 --- README.md | 1 + bin/testee | 14 +++++++++++++- lib/reporter/index.js | 4 ++-- lib/testee.js | 2 +- test/testee.test.js | 16 ++++++++++++++++ 5 files changed, 33 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 0dc4846..08acd26 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/bin/testee b/bin/testee index 14ea562..2199bf6 100755 --- a/bin/testee +++ b/bin/testee @@ -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)') @@ -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); diff --git a/lib/reporter/index.js b/lib/reporter/index.js index 9267541..db049a4 100644 --- a/lib/reporter/index.js +++ b/lib/reporter/index.js @@ -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]; @@ -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 = []; diff --git a/lib/testee.js b/lib/testee.js index c08c58f..383d3b2 100644 --- a/lib/testee.js +++ b/lib/testee.js @@ -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 diff --git a/test/testee.test.js b/test/testee.test.js index 8680a8e..fc2fbbc 100644 --- a/test/testee.test.js +++ b/test/testee.test.js @@ -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) {