source: Dev/trunk/node_modules/mocha/lib/reporters/json-stream.js

Last change on this file was 484, checked in by hendrikvanantwerpen, 11 years ago

Commit node_modules, to make checkouts and builds more deterministic.

File size: 1.0 KB
Line 
1
2/**
3 * Module dependencies.
4 */
5
6var Base = require('./base')
7  , color = Base.color;
8
9/**
10 * Expose `List`.
11 */
12
13exports = module.exports = List;
14
15/**
16 * Initialize a new `List` test reporter.
17 *
18 * @param {Runner} runner
19 * @api public
20 */
21
22function List(runner) {
23  Base.call(this, runner);
24
25  var self = this
26    , stats = this.stats
27    , total = runner.total;
28
29  runner.on('start', function(){
30    console.log(JSON.stringify(['start', { total: total }]));
31  });
32
33  runner.on('pass', function(test){
34    console.log(JSON.stringify(['pass', clean(test)]));
35  });
36
37  runner.on('fail', function(test, err){
38    console.log(JSON.stringify(['fail', clean(test)]));
39  });
40
41  runner.on('end', function(){
42    process.stdout.write(JSON.stringify(['end', self.stats]));
43  });
44}
45
46/**
47 * Return a plain-object representation of `test`
48 * free of cyclic properties etc.
49 *
50 * @param {Object} test
51 * @return {Object}
52 * @api private
53 */
54
55function clean(test) {
56  return {
57      title: test.title
58    , fullTitle: test.fullTitle()
59    , duration: test.duration
60  }
61}
Note: See TracBrowser for help on using the repository browser.