Skip to content

Commit e7f8a52

Browse files
committed
feat(reporters): Make optional 'options' parameter standard for all constructors
The options parameter is passed to abstract Base superctor.
1 parent 6535965 commit e7f8a52

File tree

15 files changed

+93
-78
lines changed

15 files changed

+93
-78
lines changed

lib/reporters/base.js

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,10 @@ if (process.platform === 'win32') {
9292
* as well as user-defined color
9393
* schemes.
9494
*
95+
* @private
9596
* @param {string} type
9697
* @param {string} str
9798
* @return {string}
98-
* @private
9999
*/
100100
var color = (exports.color = function(type, str) {
101101
if (!exports.useColors) {
@@ -168,7 +168,8 @@ function stringifyDiffObjs(err) {
168168
/**
169169
* Returns a diff between 2 strings with coloured ANSI output.
170170
*
171-
* The diff will be either inline or unified dependant on the value
171+
* @description
172+
* The diff will be either inline or unified dependent on the value
172173
* of `Base.inlineDiff`.
173174
*
174175
* @param {string} actual
@@ -182,14 +183,14 @@ var generateDiff = (exports.generateDiff = function(actual, expected) {
182183
});
183184

184185
/**
185-
* Output the given `failures` as a list.
186+
* Outputs the given `failures` as a list.
186187
*
187188
* @public
188189
* @memberof Mocha.reporters.Base
189190
* @variation 1
190-
* @param {Array} failures
191+
* @param {Object[]} failures - Each is Test instance with corresponding
192+
* Error property
191193
*/
192-
193194
exports.list = function(failures) {
194195
console.log();
195196
failures.forEach(function(test, i) {
@@ -257,25 +258,26 @@ exports.list = function(failures) {
257258
};
258259

259260
/**
260-
* Initialize a new `Base` reporter.
261+
* Constructs a new `Base` reporter instance.
261262
*
262-
* All other reporters generally
263-
* inherit from this reporter.
263+
* @description
264+
* All other reporters generally inherit from this reporter.
264265
*
265-
* @memberof Mocha.reporters
266266
* @public
267267
* @class
268-
* @param {Runner} runner
268+
* @memberof Mocha.reporters
269+
* @param {Runner} runner - Instance triggers reporter actions.
270+
* @param {Object} [options] - runner options
269271
*/
270-
271-
function Base(runner) {
272+
function Base(runner, options) {
272273
var failures = (this.failures = []);
273274

274275
if (!runner) {
275276
throw new TypeError('Missing runner argument');
276277
}
277-
this.stats = runner.stats; // assigned so Reporters keep a closer reference
278+
this.options = options || {};
278279
this.runner = runner;
280+
this.stats = runner.stats; // assigned so Reporters keep a closer reference
279281

280282
runner.on(EVENT_TEST_PASS, function(test) {
281283
if (test.duration > test.slow()) {
@@ -297,11 +299,10 @@ function Base(runner) {
297299
}
298300

299301
/**
300-
* Output common epilogue used by many of
301-
* the bundled reporters.
302+
* Outputs common epilogue used by many of the bundled reporters.
302303
*
303-
* @memberof Mocha.reporters.Base
304304
* @public
305+
* @memberof Mocha.reporters.Base
305306
*/
306307
Base.prototype.epilogue = function() {
307308
var stats = this.stats;
@@ -338,7 +339,7 @@ Base.prototype.epilogue = function() {
338339
};
339340

340341
/**
341-
* Pad the given `str` to `len`.
342+
* Pads the given `str` to `len`.
342343
*
343344
* @private
344345
* @param {string} str
@@ -351,7 +352,7 @@ function pad(str, len) {
351352
}
352353

353354
/**
354-
* Returns an inline diff between 2 strings with coloured ANSI output.
355+
* Returns inline diff between 2 strings with coloured ANSI output.
355356
*
356357
* @private
357358
* @param {String} actual
@@ -388,7 +389,7 @@ function inlineDiff(actual, expected) {
388389
}
389390

390391
/**
391-
* Returns a unified diff between two strings with coloured ANSI output.
392+
* Returns unified diff between two strings with coloured ANSI output.
392393
*
393394
* @private
394395
* @param {String} actual
@@ -431,7 +432,7 @@ function unifiedDiff(actual, expected) {
431432
}
432433

433434
/**
434-
* Return a character diff for `err`.
435+
* Returns character diff for `err`.
435436
*
436437
* @private
437438
* @param {String} actual
@@ -454,7 +455,7 @@ function errorDiff(actual, expected) {
454455
}
455456

456457
/**
457-
* Color lines for `str`, using the color `name`.
458+
* Colors lines for `str`, using the color `name`.
458459
*
459460
* @private
460461
* @param {string} name
@@ -476,7 +477,7 @@ function colorLines(name, str) {
476477
var objToString = Object.prototype.toString;
477478

478479
/**
479-
* Check that a / b have the same type.
480+
* Checks that a / b have the same type.
480481
*
481482
* @private
482483
* @param {Object} a

lib/reporters/doc.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,17 @@ var EVENT_SUITE_END = constants.EVENT_SUITE_END;
2121
exports = module.exports = Doc;
2222

2323
/**
24-
* Initialize a new `Doc` reporter.
24+
* Constructs a new `Doc` reporter instance.
2525
*
26+
* @public
2627
* @class
2728
* @memberof Mocha.reporters
28-
* @extends {Base}
29-
* @public
30-
* @param {Runner} runner
29+
* @extends Mocha.reporters.Base
30+
* @param {Runner} runner - Instance triggers reporter actions.
31+
* @param {Object} [options] - runner options
3132
*/
32-
function Doc(runner) {
33-
Base.call(this, runner);
33+
function Doc(runner, options) {
34+
Base.call(this, runner, options);
3435

3536
var indents = 2;
3637

lib/reporters/dot.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,17 @@ var EVENT_RUN_END = constants.EVENT_RUN_END;
2222
exports = module.exports = Dot;
2323

2424
/**
25-
* Initialize a new `Dot` matrix test reporter.
25+
* Constructs a new `Dot` reporter instance.
2626
*
27+
* @public
2728
* @class
2829
* @memberof Mocha.reporters
2930
* @extends Mocha.reporters.Base
30-
* @public
31-
* @param {Runner} runner
31+
* @param {Runner} runner - Instance triggers reporter actions.
32+
* @param {Object} [options] - runner options
3233
*/
33-
function Dot(runner) {
34-
Base.call(this, runner);
34+
function Dot(runner, options) {
35+
Base.call(this, runner, options);
3536

3637
var self = this;
3738
var width = (Base.window.width * 0.75) | 0;

lib/reporters/html.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,17 @@ var statsTemplate =
4747
var playIcon = '‣';
4848

4949
/**
50-
* Initialize a new `HTML` reporter.
50+
* Constructs a new `HTML` reporter instance.
5151
*
5252
* @public
5353
* @class
5454
* @memberof Mocha.reporters
5555
* @extends Mocha.reporters.Base
56-
* @param {Runner} runner
56+
* @param {Runner} runner - Instance triggers reporter actions.
57+
* @param {Object} [options] - runner options
5758
*/
58-
function HTML(runner) {
59-
Base.call(this, runner);
59+
function HTML(runner, options) {
60+
Base.call(this, runner, options);
6061

6162
var self = this;
6263
var stats = this.stats;

lib/reporters/json-stream.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,13 @@ exports = module.exports = JSONStream;
2424
*
2525
* @public
2626
* @class
27-
* @extends Mocha.reporters.Base
2827
* @memberof Mocha.reporters
28+
* @extends Mocha.reporters.Base
2929
* @param {Runner} runner - Instance triggers reporter actions.
30+
* @param {Object} [options] - runner options
3031
*/
31-
function JSONStream(runner) {
32-
Base.call(this, runner);
32+
function JSONStream(runner, options) {
33+
Base.call(this, runner, options);
3334

3435
var self = this;
3536
var total = runner.total;

lib/reporters/json.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,17 @@ var EVENT_TEST_PENDING = constants.EVENT_TEST_PENDING;
2121
exports = module.exports = JSONReporter;
2222

2323
/**
24-
* Initialize a new `JSON` reporter.
24+
* Constructs a new `JSON` reporter instance.
2525
*
2626
* @public
2727
* @class JSON
2828
* @memberof Mocha.reporters
2929
* @extends Mocha.reporters.Base
30-
* @param {Runner} runner
30+
* @param {Runner} runner - Instance triggers reporter actions.
31+
* @param {Object} [options] - runner options
3132
*/
32-
function JSONReporter(runner) {
33-
Base.call(this, runner);
33+
function JSONReporter(runner, options) {
34+
Base.call(this, runner, options);
3435

3536
var self = this;
3637
var tests = [];

lib/reporters/landing.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,17 @@ Base.colors['plane crash'] = 31;
4242
Base.colors.runway = 90;
4343

4444
/**
45-
* Initialize a new `Landing` reporter.
45+
* Constructs a new `Landing` reporter instance.
4646
*
4747
* @public
4848
* @class
4949
* @memberof Mocha.reporters
5050
* @extends Mocha.reporters.Base
51-
* @param {Runner} runner
51+
* @param {Runner} runner - Instance triggers reporter actions.
52+
* @param {Object} [options] - runner options
5253
*/
53-
function Landing(runner) {
54-
Base.call(this, runner);
54+
function Landing(runner, options) {
55+
Base.call(this, runner, options);
5556

5657
var self = this;
5758
var width = (Base.window.width * 0.75) | 0;

lib/reporters/list.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,17 @@ var cursor = Base.cursor;
2525
exports = module.exports = List;
2626

2727
/**
28-
* Initialize a new `List` test reporter.
28+
* Constructs a new `List` reporter instance.
2929
*
3030
* @public
3131
* @class
3232
* @memberof Mocha.reporters
3333
* @extends Mocha.reporters.Base
34-
* @param {Runner} runner
34+
* @param {Runner} runner - Instance triggers reporter actions.
35+
* @param {Object} [options] - runner options
3536
*/
36-
function List(runner) {
37-
Base.call(this, runner);
37+
function List(runner, options) {
38+
Base.call(this, runner, options);
3839

3940
var self = this;
4041
var n = 0;

lib/reporters/markdown.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,17 @@ var SUITE_PREFIX = '$';
2727
exports = module.exports = Markdown;
2828

2929
/**
30-
* Initialize a new `Markdown` reporter.
30+
* Constructs a new `Markdown` reporter instance.
3131
*
3232
* @public
3333
* @class
3434
* @memberof Mocha.reporters
3535
* @extends Mocha.reporters.Base
36-
* @param {Runner} runner
36+
* @param {Runner} runner - Instance triggers reporter actions.
37+
* @param {Object} [options] - runner options
3738
*/
38-
function Markdown(runner) {
39-
Base.call(this, runner);
39+
function Markdown(runner, options) {
40+
Base.call(this, runner, options);
4041

4142
var level = 0;
4243
var buf = '';

lib/reporters/min.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,20 @@ var EVENT_RUN_BEGIN = constants.EVENT_RUN_BEGIN;
1919
exports = module.exports = Min;
2020

2121
/**
22-
* Initialize a new `Min` minimal test reporter (best used with --watch).
22+
* Constructs a new `Min` reporter instance.
23+
*
24+
* @description
25+
* This minimal test reporter is best used with '--watch'.
2326
*
2427
* @public
2528
* @class
2629
* @memberof Mocha.reporters
2730
* @extends Mocha.reporters.Base
28-
* @param {Runner} runner
31+
* @param {Runner} runner - Instance triggers reporter actions.
32+
* @param {Object} [options] - runner options
2933
*/
30-
function Min(runner) {
31-
Base.call(this, runner);
34+
function Min(runner, options) {
35+
Base.call(this, runner, options);
3236

3337
runner.on(EVENT_RUN_BEGIN, function() {
3438
// clear screen

0 commit comments

Comments
 (0)