dot.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. 'use strict';
  2. /**
  3. * @typedef {import('../runner.js')} Runner
  4. */
  5. /**
  6. * @module Dot
  7. */
  8. /**
  9. * Module dependencies.
  10. */
  11. var Base = require('./base');
  12. var inherits = require('../utils').inherits;
  13. var constants = require('../runner').constants;
  14. var EVENT_TEST_PASS = constants.EVENT_TEST_PASS;
  15. var EVENT_TEST_FAIL = constants.EVENT_TEST_FAIL;
  16. var EVENT_RUN_BEGIN = constants.EVENT_RUN_BEGIN;
  17. var EVENT_TEST_PENDING = constants.EVENT_TEST_PENDING;
  18. var EVENT_RUN_END = constants.EVENT_RUN_END;
  19. /**
  20. * Expose `Dot`.
  21. */
  22. exports = module.exports = Dot;
  23. /**
  24. * Constructs a new `Dot` reporter instance.
  25. *
  26. * @public
  27. * @class
  28. * @memberof Mocha.reporters
  29. * @extends Mocha.reporters.Base
  30. * @param {Runner} runner - Instance triggers reporter actions.
  31. * @param {Object} [options] - runner options
  32. */
  33. function Dot(runner, options) {
  34. Base.call(this, runner, options);
  35. var self = this;
  36. var width = (Base.window.width * 0.75) | 0;
  37. var n = -1;
  38. runner.on(EVENT_RUN_BEGIN, function () {
  39. process.stdout.write('\n');
  40. });
  41. runner.on(EVENT_TEST_PENDING, function () {
  42. if (++n % width === 0) {
  43. process.stdout.write('\n ');
  44. }
  45. process.stdout.write(Base.color('pending', Base.symbols.comma));
  46. });
  47. runner.on(EVENT_TEST_PASS, function (test) {
  48. if (++n % width === 0) {
  49. process.stdout.write('\n ');
  50. }
  51. if (test.speed === 'slow') {
  52. process.stdout.write(Base.color('bright yellow', Base.symbols.dot));
  53. } else {
  54. process.stdout.write(Base.color(test.speed, Base.symbols.dot));
  55. }
  56. });
  57. runner.on(EVENT_TEST_FAIL, function () {
  58. if (++n % width === 0) {
  59. process.stdout.write('\n ');
  60. }
  61. process.stdout.write(Base.color('fail', Base.symbols.bang));
  62. });
  63. runner.once(EVENT_RUN_END, function () {
  64. process.stdout.write('\n');
  65. self.epilogue();
  66. });
  67. }
  68. /**
  69. * Inherit from `Base.prototype`.
  70. */
  71. inherits(Dot, Base);
  72. Dot.description = 'dot matrix representation';