json-stream.js 1.0 KB

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