1 | 'use strict';
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 | var Base = require('./base');
|
8 | var inherits = require('../utils').inherits;
|
9 | var cursor = Base.cursor;
|
10 | var color = Base.color;
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 | exports = module.exports = Landing;
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 | Base.colors.plane = 0;
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 | Base.colors['plane crash'] = 31;
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 | Base.colors.runway = 90;
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 | function 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 |
|
65 | var col = crashed === -1 ? width * ++n / total | 0 : crashed;
|
66 |
|
67 |
|
68 | if (test.state === 'failed') {
|
69 | plane = color('plane crash', '✈');
|
70 | crashed = col;
|
71 | }
|
72 |
|
73 |
|
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 |
|
93 |
|
94 | inherits(Landing, Base);
|