mirror of
https://github.com/seejohnrun/haste-server.git
synced 2024-11-01 11:31:22 +00:00
70 lines
1.1 KiB
JavaScript
70 lines
1.1 KiB
JavaScript
|
|
||
|
/**
|
||
|
* Module dependencies.
|
||
|
*/
|
||
|
|
||
|
var Base = require('./base')
|
||
|
, cursor = Base.cursor
|
||
|
, color = Base.color;
|
||
|
|
||
|
/**
|
||
|
* Expose `JSON`.
|
||
|
*/
|
||
|
|
||
|
exports = module.exports = JSONReporter;
|
||
|
|
||
|
/**
|
||
|
* Initialize a new `JSON` reporter.
|
||
|
*
|
||
|
* @param {Runner} runner
|
||
|
* @api public
|
||
|
*/
|
||
|
|
||
|
function JSONReporter(runner) {
|
||
|
var self = this;
|
||
|
Base.call(this, runner);
|
||
|
|
||
|
var tests = []
|
||
|
, failures = []
|
||
|
, passes = [];
|
||
|
|
||
|
runner.on('test end', function(test){
|
||
|
tests.push(test);
|
||
|
});
|
||
|
|
||
|
runner.on('pass', function(test){
|
||
|
passes.push(test);
|
||
|
});
|
||
|
|
||
|
runner.on('fail', function(test){
|
||
|
failures.push(test);
|
||
|
});
|
||
|
|
||
|
runner.on('end', function(){
|
||
|
var obj = {
|
||
|
stats: self.stats
|
||
|
, tests: tests.map(clean)
|
||
|
, failures: failures.map(clean)
|
||
|
, passes: passes.map(clean)
|
||
|
};
|
||
|
|
||
|
process.stdout.write(JSON.stringify(obj));
|
||
|
});
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Return a plain-object representation of `test`
|
||
|
* free of cyclic properties etc.
|
||
|
*
|
||
|
* @param {Object} test
|
||
|
* @return {Object}
|
||
|
* @api private
|
||
|
*/
|
||
|
|
||
|
function clean(test) {
|
||
|
return {
|
||
|
title: test.title
|
||
|
, fullTitle: test.fullTitle()
|
||
|
, duration: test.duration
|
||
|
}
|
||
|
}
|