landing.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /**
  2. * Module dependencies.
  3. */
  4. var Base = require('./base');
  5. var inherits = require('../utils').inherits;
  6. var cursor = Base.cursor;
  7. var color = Base.color;
  8. /**
  9. * Expose `Landing`.
  10. */
  11. exports = module.exports = Landing;
  12. /**
  13. * Airplane color.
  14. */
  15. Base.colors.plane = 0;
  16. /**
  17. * Airplane crash color.
  18. */
  19. Base.colors['plane crash'] = 31;
  20. /**
  21. * Runway color.
  22. */
  23. Base.colors.runway = 90;
  24. /**
  25. * Initialize a new `Landing` reporter.
  26. *
  27. * @api public
  28. * @param {Runner} runner
  29. */
  30. function Landing(runner) {
  31. Base.call(this, runner);
  32. var self = this;
  33. var width = Base.window.width * .75 | 0;
  34. var total = runner.total;
  35. var stream = process.stdout;
  36. var plane = color('plane', '✈');
  37. var crashed = -1;
  38. var n = 0;
  39. function runway() {
  40. var buf = Array(width).join('-');
  41. return ' ' + color('runway', buf);
  42. }
  43. runner.on('start', function() {
  44. stream.write('\n\n\n ');
  45. cursor.hide();
  46. });
  47. runner.on('test end', function(test) {
  48. // check if the plane crashed
  49. var col = crashed === -1 ? width * ++n / total | 0 : crashed;
  50. // show the crash
  51. if (test.state === 'failed') {
  52. plane = color('plane crash', '✈');
  53. crashed = col;
  54. }
  55. // render landing strip
  56. stream.write('\u001b[' + (width + 1) + 'D\u001b[2A');
  57. stream.write(runway());
  58. stream.write('\n ');
  59. stream.write(color('runway', Array(col).join('⋅')));
  60. stream.write(plane);
  61. stream.write(color('runway', Array(width - col).join('⋅') + '\n'));
  62. stream.write(runway());
  63. stream.write('\u001b[0m');
  64. });
  65. runner.on('end', function() {
  66. cursor.show();
  67. console.log();
  68. self.epilogue();
  69. });
  70. }
  71. /**
  72. * Inherit from `Base.prototype`.
  73. */
  74. inherits(Landing, Base);