list.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. 'use strict';
  2. /**
  3. * @module List
  4. */
  5. /**
  6. * Module dependencies.
  7. */
  8. var Base = require('./base');
  9. var inherits = require('../utils').inherits;
  10. var color = Base.color;
  11. var cursor = Base.cursor;
  12. /**
  13. * Expose `List`.
  14. */
  15. exports = module.exports = List;
  16. /**
  17. * Initialize a new `List` test reporter.
  18. *
  19. * @public
  20. * @class
  21. * @memberof Mocha.reporters
  22. * @extends Mocha.reporters.Base
  23. * @api public
  24. * @param {Runner} runner
  25. */
  26. function List(runner) {
  27. Base.call(this, runner);
  28. var self = this;
  29. var n = 0;
  30. runner.on('start', function() {
  31. console.log();
  32. });
  33. runner.on('test', function(test) {
  34. process.stdout.write(color('pass', ' ' + test.fullTitle() + ': '));
  35. });
  36. runner.on('pending', function(test) {
  37. var fmt = color('checkmark', ' -') + color('pending', ' %s');
  38. console.log(fmt, test.fullTitle());
  39. });
  40. runner.on('pass', function(test) {
  41. var fmt =
  42. color('checkmark', ' ' + Base.symbols.ok) +
  43. color('pass', ' %s: ') +
  44. color(test.speed, '%dms');
  45. cursor.CR();
  46. console.log(fmt, test.fullTitle(), test.duration);
  47. });
  48. runner.on('fail', function(test) {
  49. cursor.CR();
  50. console.log(color('fail', ' %d) %s'), ++n, test.fullTitle());
  51. });
  52. runner.once('end', self.epilogue.bind(self));
  53. }
  54. /**
  55. * Inherit from `Base.prototype`.
  56. */
  57. inherits(List, Base);