Skip to content
This repository has been archived by the owner on Dec 4, 2023. It is now read-only.

Commit

Permalink
Make optional 'options' parameter standard for all reporter construct…
Browse files Browse the repository at this point in the history
…ors (mochajs#3766)
  • Loading branch information
plroebuck committed Feb 26, 2019
1 parent 64e4063 commit be22ad2
Show file tree
Hide file tree
Showing 15 changed files with 93 additions and 78 deletions.
45 changes: 23 additions & 22 deletions lib/reporters/base.js
Expand Up @@ -92,10 +92,10 @@ if (process.platform === 'win32') {
* as well as user-defined color
* schemes.
*
* @private
* @param {string} type
* @param {string} str
* @return {string}
* @private
*/
var color = (exports.color = function(type, str) {
if (!exports.useColors) {
Expand Down Expand Up @@ -168,7 +168,8 @@ function stringifyDiffObjs(err) {
/**
* Returns a diff between 2 strings with coloured ANSI output.
*
* The diff will be either inline or unified dependant on the value
* @description
* The diff will be either inline or unified dependent on the value
* of `Base.inlineDiff`.
*
* @param {string} actual
Expand All @@ -182,14 +183,14 @@ var generateDiff = (exports.generateDiff = function(actual, expected) {
});

/**
* Output the given `failures` as a list.
* Outputs the given `failures` as a list.
*
* @public
* @memberof Mocha.reporters.Base
* @variation 1
* @param {Array} failures
* @param {Object[]} failures - Each is Test instance with corresponding
* Error property
*/

exports.list = function(failures) {
console.log();
failures.forEach(function(test, i) {
Expand Down Expand Up @@ -257,25 +258,26 @@ exports.list = function(failures) {
};

/**
* Initialize a new `Base` reporter.
* Constructs a new `Base` reporter instance.
*
* All other reporters generally
* inherit from this reporter.
* @description
* All other reporters generally inherit from this reporter.
*
* @memberof Mocha.reporters
* @public
* @class
* @param {Runner} runner
* @memberof Mocha.reporters
* @param {Runner} runner - Instance triggers reporter actions.
* @param {Object} [options] - runner options
*/

function Base(runner) {
function Base(runner, options) {
var failures = (this.failures = []);

if (!runner) {
throw new TypeError('Missing runner argument');
}
this.stats = runner.stats; // assigned so Reporters keep a closer reference
this.options = options || {};
this.runner = runner;
this.stats = runner.stats; // assigned so Reporters keep a closer reference

runner.on(EVENT_TEST_PASS, function(test) {
if (test.duration > test.slow()) {
Expand All @@ -297,11 +299,10 @@ function Base(runner) {
}

/**
* Output common epilogue used by many of
* the bundled reporters.
* Outputs common epilogue used by many of the bundled reporters.
*
* @memberof Mocha.reporters.Base
* @public
* @memberof Mocha.reporters.Base
*/
Base.prototype.epilogue = function() {
var stats = this.stats;
Expand Down Expand Up @@ -338,7 +339,7 @@ Base.prototype.epilogue = function() {
};

/**
* Pad the given `str` to `len`.
* Pads the given `str` to `len`.
*
* @private
* @param {string} str
Expand All @@ -351,7 +352,7 @@ function pad(str, len) {
}

/**
* Returns an inline diff between 2 strings with coloured ANSI output.
* Returns inline diff between 2 strings with coloured ANSI output.
*
* @private
* @param {String} actual
Expand Down Expand Up @@ -388,7 +389,7 @@ function inlineDiff(actual, expected) {
}

/**
* Returns a unified diff between two strings with coloured ANSI output.
* Returns unified diff between two strings with coloured ANSI output.
*
* @private
* @param {String} actual
Expand Down Expand Up @@ -431,7 +432,7 @@ function unifiedDiff(actual, expected) {
}

/**
* Return a character diff for `err`.
* Returns character diff for `err`.
*
* @private
* @param {String} actual
Expand All @@ -454,7 +455,7 @@ function errorDiff(actual, expected) {
}

/**
* Color lines for `str`, using the color `name`.
* Colors lines for `str`, using the color `name`.
*
* @private
* @param {string} name
Expand All @@ -476,7 +477,7 @@ function colorLines(name, str) {
var objToString = Object.prototype.toString;

/**
* Check that a / b have the same type.
* Checks that a / b have the same type.
*
* @private
* @param {Object} a
Expand Down
13 changes: 7 additions & 6 deletions lib/reporters/doc.js
Expand Up @@ -21,16 +21,17 @@ var EVENT_SUITE_END = constants.EVENT_SUITE_END;
exports = module.exports = Doc;

/**
* Initialize a new `Doc` reporter.
* Constructs a new `Doc` reporter instance.
*
* @public
* @class
* @memberof Mocha.reporters
* @extends {Base}
* @public
* @param {Runner} runner
* @extends Mocha.reporters.Base
* @param {Runner} runner - Instance triggers reporter actions.
* @param {Object} [options] - runner options
*/
function Doc(runner) {
Base.call(this, runner);
function Doc(runner, options) {
Base.call(this, runner, options);

var indents = 2;

Expand Down
11 changes: 6 additions & 5 deletions lib/reporters/dot.js
Expand Up @@ -22,16 +22,17 @@ var EVENT_RUN_END = constants.EVENT_RUN_END;
exports = module.exports = Dot;

/**
* Initialize a new `Dot` matrix test reporter.
* Constructs a new `Dot` reporter instance.
*
* @public
* @class
* @memberof Mocha.reporters
* @extends Mocha.reporters.Base
* @public
* @param {Runner} runner
* @param {Runner} runner - Instance triggers reporter actions.
* @param {Object} [options] - runner options
*/
function Dot(runner) {
Base.call(this, runner);
function Dot(runner, options) {
Base.call(this, runner, options);

var self = this;
var width = (Base.window.width * 0.75) | 0;
Expand Down
9 changes: 5 additions & 4 deletions lib/reporters/html.js
Expand Up @@ -47,16 +47,17 @@ var statsTemplate =
var playIcon = '‣';

/**
* Initialize a new `HTML` reporter.
* Constructs a new `HTML` reporter instance.
*
* @public
* @class
* @memberof Mocha.reporters
* @extends Mocha.reporters.Base
* @param {Runner} runner
* @param {Runner} runner - Instance triggers reporter actions.
* @param {Object} [options] - runner options
*/
function HTML(runner) {
Base.call(this, runner);
function HTML(runner, options) {
Base.call(this, runner, options);

var self = this;
var stats = this.stats;
Expand Down
7 changes: 4 additions & 3 deletions lib/reporters/json-stream.js
Expand Up @@ -24,12 +24,13 @@ exports = module.exports = JSONStream;
*
* @public
* @class
* @extends Mocha.reporters.Base
* @memberof Mocha.reporters
* @extends Mocha.reporters.Base
* @param {Runner} runner - Instance triggers reporter actions.
* @param {Object} [options] - runner options
*/
function JSONStream(runner) {
Base.call(this, runner);
function JSONStream(runner, options) {
Base.call(this, runner, options);

var self = this;
var total = runner.total;
Expand Down
9 changes: 5 additions & 4 deletions lib/reporters/json.js
Expand Up @@ -21,16 +21,17 @@ var EVENT_TEST_PENDING = constants.EVENT_TEST_PENDING;
exports = module.exports = JSONReporter;

/**
* Initialize a new `JSON` reporter.
* Constructs a new `JSON` reporter instance.
*
* @public
* @class JSON
* @memberof Mocha.reporters
* @extends Mocha.reporters.Base
* @param {Runner} runner
* @param {Runner} runner - Instance triggers reporter actions.
* @param {Object} [options] - runner options
*/
function JSONReporter(runner) {
Base.call(this, runner);
function JSONReporter(runner, options) {
Base.call(this, runner, options);

var self = this;
var tests = [];
Expand Down
9 changes: 5 additions & 4 deletions lib/reporters/landing.js
Expand Up @@ -42,16 +42,17 @@ Base.colors['plane crash'] = 31;
Base.colors.runway = 90;

/**
* Initialize a new `Landing` reporter.
* Constructs a new `Landing` reporter instance.
*
* @public
* @class
* @memberof Mocha.reporters
* @extends Mocha.reporters.Base
* @param {Runner} runner
* @param {Runner} runner - Instance triggers reporter actions.
* @param {Object} [options] - runner options
*/
function Landing(runner) {
Base.call(this, runner);
function Landing(runner, options) {
Base.call(this, runner, options);

var self = this;
var width = (Base.window.width * 0.75) | 0;
Expand Down
9 changes: 5 additions & 4 deletions lib/reporters/list.js
Expand Up @@ -25,16 +25,17 @@ var cursor = Base.cursor;
exports = module.exports = List;

/**
* Initialize a new `List` test reporter.
* Constructs a new `List` reporter instance.
*
* @public
* @class
* @memberof Mocha.reporters
* @extends Mocha.reporters.Base
* @param {Runner} runner
* @param {Runner} runner - Instance triggers reporter actions.
* @param {Object} [options] - runner options
*/
function List(runner) {
Base.call(this, runner);
function List(runner, options) {
Base.call(this, runner, options);

var self = this;
var n = 0;
Expand Down
9 changes: 5 additions & 4 deletions lib/reporters/markdown.js
Expand Up @@ -27,16 +27,17 @@ var SUITE_PREFIX = '$';
exports = module.exports = Markdown;

/**
* Initialize a new `Markdown` reporter.
* Constructs a new `Markdown` reporter instance.
*
* @public
* @class
* @memberof Mocha.reporters
* @extends Mocha.reporters.Base
* @param {Runner} runner
* @param {Runner} runner - Instance triggers reporter actions.
* @param {Object} [options] - runner options
*/
function Markdown(runner) {
Base.call(this, runner);
function Markdown(runner, options) {
Base.call(this, runner, options);

var level = 0;
var buf = '';
Expand Down
12 changes: 8 additions & 4 deletions lib/reporters/min.js
Expand Up @@ -19,16 +19,20 @@ var EVENT_RUN_BEGIN = constants.EVENT_RUN_BEGIN;
exports = module.exports = Min;

/**
* Initialize a new `Min` minimal test reporter (best used with --watch).
* Constructs a new `Min` reporter instance.
*
* @description
* This minimal test reporter is best used with '--watch'.
*
* @public
* @class
* @memberof Mocha.reporters
* @extends Mocha.reporters.Base
* @param {Runner} runner
* @param {Runner} runner - Instance triggers reporter actions.
* @param {Object} [options] - runner options
*/
function Min(runner) {
Base.call(this, runner);
function Min(runner, options) {
Base.call(this, runner, options);

runner.on(EVENT_RUN_BEGIN, function() {
// clear screen
Expand Down
10 changes: 5 additions & 5 deletions lib/reporters/nyan.js
Expand Up @@ -22,17 +22,17 @@ var EVENT_TEST_FAIL = constants.EVENT_TEST_FAIL;
exports = module.exports = NyanCat;

/**
* Initialize a new `Dot` matrix test reporter.
* Constructs a new `Nyan` reporter instance.
*
* @param {Runner} runner
* @public
* @class Nyan
* @memberof Mocha.reporters
* @extends Mocha.reporters.Base
* @param {Runner} runner - Instance triggers reporter actions.
* @param {Object} [options] - runner options
*/

function NyanCat(runner) {
Base.call(this, runner);
function NyanCat(runner, options) {
Base.call(this, runner, options);

var self = this;
var width = (Base.window.width * 0.75) | 0;
Expand Down
8 changes: 4 additions & 4 deletions lib/reporters/progress.js
Expand Up @@ -28,17 +28,17 @@ exports = module.exports = Progress;
Base.colors.progress = 90;

/**
* Initialize a new `Progress` bar test reporter.
* Constructs a new `Progress` reporter instance.
*
* @public
* @class
* @memberof Mocha.reporters
* @extends Mocha.reporters.Base
* @param {Runner} runner
* @param {Object} options
* @param {Runner} runner - Instance triggers reporter actions.
* @param {Object} [options] - runner options
*/
function Progress(runner, options) {
Base.call(this, runner);
Base.call(this, runner, options);

var self = this;
var width = (Base.window.width * 0.5) | 0;
Expand Down

0 comments on commit be22ad2

Please sign in to comment.