vendor/node_modules/mocha/lib/reporters/json.js in stylus-source-0.42.2 vs vendor/node_modules/mocha/lib/reporters/json.js in stylus-source-0.49.3

- old
+ new

@@ -1,6 +1,5 @@ - /** * Module dependencies. */ var Base = require('./base') @@ -23,10 +22,11 @@ function JSONReporter(runner) { var self = this; Base.call(this, runner); var tests = [] + , pending = [] , failures = [] , passes = []; runner.on('test end', function(test){ tests.push(test); @@ -38,18 +38,25 @@ runner.on('fail', function(test){ failures.push(test); }); + runner.on('pending', function(test){ + pending.push(test); + }); + runner.on('end', function(){ var obj = { - stats: self.stats - , tests: tests.map(clean) - , failures: failures.map(clean) - , passes: passes.map(clean) + stats: self.stats, + tests: tests.map(clean), + pending: pending.map(clean), + failures: failures.map(clean), + passes: passes.map(clean) }; + runner.testResults = obj; + process.stdout.write(JSON.stringify(obj, null, 2)); }); } /** @@ -61,10 +68,25 @@ * @api private */ function clean(test) { return { - title: test.title - , fullTitle: test.fullTitle() - , duration: test.duration + title: test.title, + fullTitle: test.fullTitle(), + duration: test.duration, + err: errorJSON(test.err || {}) } -} \ No newline at end of file +} + +/** + * Transform `error` into a JSON object. + * @param {Error} err + * @return {Object} + */ + +function errorJSON(err) { + var res = {}; + Object.getOwnPropertyNames(err).forEach(function(key) { + res[key] = err[key]; + }, err); + return res; +}