list.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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 constants = require('../runner').constants;
  11. var EVENT_RUN_BEGIN = constants.EVENT_RUN_BEGIN;
  12. var EVENT_RUN_END = constants.EVENT_RUN_END;
  13. var EVENT_TEST_BEGIN = constants.EVENT_TEST_BEGIN;
  14. var EVENT_TEST_FAIL = constants.EVENT_TEST_FAIL;
  15. var EVENT_TEST_PASS = constants.EVENT_TEST_PASS;
  16. var EVENT_TEST_PENDING = constants.EVENT_TEST_PENDING;
  17. var color = Base.color;
  18. var cursor = Base.cursor;
  19. /**
  20. * Expose `List`.
  21. */
  22. exports = module.exports = List;
  23. /**
  24. * Initialize a new `List` test reporter.
  25. *
  26. * @public
  27. * @class
  28. * @memberof Mocha.reporters
  29. * @extends Mocha.reporters.Base
  30. * @param {Runner} runner
  31. */
  32. function List(runner) {
  33. Base.call(this, runner);
  34. var self = this;
  35. var n = 0;
  36. runner.on(EVENT_RUN_BEGIN, function() {
  37. console.log();
  38. });
  39. runner.on(EVENT_TEST_BEGIN, function(test) {
  40. process.stdout.write(color('pass', ' ' + test.fullTitle() + ': '));
  41. });
  42. runner.on(EVENT_TEST_PENDING, function(test) {
  43. var fmt = color('checkmark', ' -') + color('pending', ' %s');
  44. console.log(fmt, test.fullTitle());
  45. });
  46. runner.on(EVENT_TEST_PASS, function(test) {
  47. var fmt =
  48. color('checkmark', ' ' + Base.symbols.ok) +
  49. color('pass', ' %s: ') +
  50. color(test.speed, '%dms');
  51. cursor.CR();
  52. console.log(fmt, test.fullTitle(), test.duration);
  53. });
  54. runner.on(EVENT_TEST_FAIL, function(test) {
  55. cursor.CR();
  56. console.log(color('fail', ' %d) %s'), ++n, test.fullTitle());
  57. });
  58. runner.once(EVENT_RUN_END, self.epilogue.bind(self));
  59. }
  60. /**
  61. * Inherit from `Base.prototype`.
  62. */
  63. inherits(List, Base);
  64. List.description = 'like "spec" reporter but flat';