UNPKG

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