|
9 | 9 | var Base = require('./base');
|
10 | 10 |
|
11 | 11 | /**
|
12 |
| - * Expose `List`. |
| 12 | + * Expose `JSONStream`. |
13 | 13 | */
|
14 | 14 |
|
15 |
| -exports = module.exports = List; |
| 15 | +exports = module.exports = JSONStream; |
16 | 16 |
|
17 | 17 | /**
|
18 |
| - * Initialize a new `JSONStream` test reporter. |
| 18 | + * Constructs a new `JSONStream` reporter instance. |
19 | 19 | *
|
20 | 20 | * @public
|
21 |
| - * @name JSONStream |
22 |
| - * @class JSONStream |
23 |
| - * @memberof Mocha.reporters |
| 21 | + * @class |
24 | 22 | * @extends Mocha.reporters.Base
|
25 |
| - * @api public |
26 |
| - * @param {Runner} runner |
| 23 | + * @memberof Mocha.reporters |
| 24 | + * @param {Runner} runner - Instance triggers reporter actions. |
27 | 25 | */
|
28 |
| -function List(runner) { |
| 26 | +function JSONStream(runner) { |
29 | 27 | Base.call(this, runner);
|
30 | 28 |
|
31 | 29 | var self = this;
|
32 | 30 | var total = runner.total;
|
33 | 31 |
|
34 |
| - runner.on('start', function() { |
35 |
| - console.log(JSON.stringify(['start', {total: total}])); |
| 32 | + runner.once('start', function() { |
| 33 | + writeEvent(['start', {total: total}]); |
36 | 34 | });
|
37 | 35 |
|
38 | 36 | runner.on('pass', function(test) {
|
39 |
| - console.log(JSON.stringify(['pass', clean(test)])); |
| 37 | + writeEvent(['pass', clean(test)]); |
40 | 38 | });
|
41 | 39 |
|
42 | 40 | runner.on('fail', function(test, err) {
|
43 | 41 | test = clean(test);
|
44 | 42 | test.err = err.message;
|
45 | 43 | test.stack = err.stack || null;
|
46 |
| - console.log(JSON.stringify(['fail', test])); |
| 44 | + writeEvent(['fail', test]); |
47 | 45 | });
|
48 | 46 |
|
49 | 47 | runner.once('end', function() {
|
50 |
| - process.stdout.write(JSON.stringify(['end', self.stats])); |
| 48 | + writeEvent(['end', self.stats]); |
51 | 49 | });
|
52 | 50 | }
|
53 | 51 |
|
54 | 52 | /**
|
55 |
| - * Return a plain-object representation of `test` |
56 |
| - * free of cyclic properties etc. |
| 53 | + * Mocha event to be written to the output stream. |
| 54 | + * @typedef {Array} JSONStream~MochaEvent |
| 55 | + */ |
| 56 | + |
| 57 | +/** |
| 58 | + * Writes Mocha event to reporter output stream. |
| 59 | + * |
| 60 | + * @private |
| 61 | + * @param {JSONStream~MochaEvent} event - Mocha event to be output. |
| 62 | + */ |
| 63 | +function writeEvent(event) { |
| 64 | + process.stdout.write(JSON.stringify(event) + '\n'); |
| 65 | +} |
| 66 | + |
| 67 | +/** |
| 68 | + * Returns an object literal representation of `test` |
| 69 | + * free of cyclic properties, etc. |
57 | 70 | *
|
58 |
| - * @api private |
59 |
| - * @param {Object} test |
60 |
| - * @return {Object} |
| 71 | + * @private |
| 72 | + * @param {Test} test - Instance used as data source. |
| 73 | + * @return {Object} object containing pared-down test instance data |
61 | 74 | */
|
62 | 75 | function clean(test) {
|
63 | 76 | return {
|
|
0 commit comments