landing.js 1.7 KB

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