dot.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. 'use strict';
  2. /**
  3. * Module dependencies.
  4. */
  5. var Base = require('./base');
  6. var inherits = require('../utils').inherits;
  7. var color = Base.color;
  8. /**
  9. * Expose `Dot`.
  10. */
  11. exports = module.exports = Dot;
  12. /**
  13. * Initialize a new `Dot` matrix test reporter.
  14. *
  15. * @api public
  16. * @param {Runner} runner
  17. */
  18. function Dot (runner) {
  19. Base.call(this, runner);
  20. var self = this;
  21. var width = Base.window.width * 0.75 | 0;
  22. var n = -1;
  23. runner.on('start', function () {
  24. process.stdout.write('\n');
  25. });
  26. runner.on('pending', function () {
  27. if (++n % width === 0) {
  28. process.stdout.write('\n ');
  29. }
  30. process.stdout.write(color('pending', Base.symbols.comma));
  31. });
  32. runner.on('pass', function (test) {
  33. if (++n % width === 0) {
  34. process.stdout.write('\n ');
  35. }
  36. if (test.speed === 'slow') {
  37. process.stdout.write(color('bright yellow', Base.symbols.dot));
  38. } else {
  39. process.stdout.write(color(test.speed, Base.symbols.dot));
  40. }
  41. });
  42. runner.on('fail', function () {
  43. if (++n % width === 0) {
  44. process.stdout.write('\n ');
  45. }
  46. process.stdout.write(color('fail', Base.symbols.bang));
  47. });
  48. runner.on('end', function () {
  49. console.log();
  50. self.epilogue();
  51. });
  52. }
  53. /**
  54. * Inherit from `Base.prototype`.
  55. */
  56. inherits(Dot, Base);