dot.js 1.3 KB

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