dot.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. 'use strict';
  2. /**
  3. * @module Dot
  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_TEST_PASS = constants.EVENT_TEST_PASS;
  12. var EVENT_TEST_FAIL = constants.EVENT_TEST_FAIL;
  13. var EVENT_RUN_BEGIN = constants.EVENT_RUN_BEGIN;
  14. var EVENT_TEST_PENDING = constants.EVENT_TEST_PENDING;
  15. var EVENT_RUN_END = constants.EVENT_RUN_END;
  16. /**
  17. * Expose `Dot`.
  18. */
  19. exports = module.exports = Dot;
  20. /**
  21. * Initialize a new `Dot` matrix test reporter.
  22. *
  23. * @class
  24. * @memberof Mocha.reporters
  25. * @extends Mocha.reporters.Base
  26. * @public
  27. * @param {Runner} runner
  28. */
  29. function Dot(runner) {
  30. Base.call(this, runner);
  31. var self = this;
  32. var width = (Base.window.width * 0.75) | 0;
  33. var n = -1;
  34. runner.on(EVENT_RUN_BEGIN, function() {
  35. process.stdout.write('\n');
  36. });
  37. runner.on(EVENT_TEST_PENDING, function() {
  38. if (++n % width === 0) {
  39. process.stdout.write('\n ');
  40. }
  41. process.stdout.write(Base.color('pending', Base.symbols.comma));
  42. });
  43. runner.on(EVENT_TEST_PASS, function(test) {
  44. if (++n % width === 0) {
  45. process.stdout.write('\n ');
  46. }
  47. if (test.speed === 'slow') {
  48. process.stdout.write(Base.color('bright yellow', Base.symbols.dot));
  49. } else {
  50. process.stdout.write(Base.color(test.speed, Base.symbols.dot));
  51. }
  52. });
  53. runner.on(EVENT_TEST_FAIL, function() {
  54. if (++n % width === 0) {
  55. process.stdout.write('\n ');
  56. }
  57. process.stdout.write(Base.color('fail', Base.symbols.bang));
  58. });
  59. runner.once(EVENT_RUN_END, function() {
  60. console.log();
  61. self.epilogue();
  62. });
  63. }
  64. /**
  65. * Inherit from `Base.prototype`.
  66. */
  67. inherits(Dot, Base);
  68. Dot.description = 'dot matrix representation';