forked from mochajs/mocha
-
Notifications
You must be signed in to change notification settings - Fork 0
/
progress.spec.js
148 lines (131 loc) · 3.93 KB
/
progress.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
'use strict';
var reporters = require('../../').reporters;
var Progress = reporters.Progress;
var Base = reporters.Base;
describe('Progress reporter', function () {
var stdout;
var stdoutWrite;
var runner;
beforeEach(function () {
stdout = [];
runner = {};
stdoutWrite = process.stdout.write;
process.stdout.write = function (string) {
stdout.push(string);
};
});
describe('on start', function () {
it('should call cursor hide', function () {
var cachedCursor = Base.cursor;
var calledCursorHide = false;
Base.cursor.hide = function () {
calledCursorHide = true;
};
runner.on = function (event, callback) {
if (event === 'start') {
callback();
}
};
Progress.call({}, runner);
process.stdout.write = stdoutWrite;
expect(calledCursorHide).to.be(true);
Base.cursor = cachedCursor;
});
});
describe('on test end', function () {
describe('if line has not changed', function () {
it('should return and not write anything', function () {
var cachedCursor = Base.cursor;
var useColors = Base.useColors;
Base.useColors = false;
Base.cursor.CR = function () {};
var windowWidth = Base.window.width;
Base.window.width = -3;
var expectedTotal = 1;
var expectedOptions = {};
runner.total = expectedTotal;
runner.on = function (event, callback) {
if (event === 'test end') {
callback();
}
};
Progress.call({}, runner, expectedOptions);
process.stdout.write = stdoutWrite;
expect(stdout).to.eql([]);
Base.cursor = cachedCursor;
Base.useColors = useColors;
Base.window.width = windowWidth;
});
});
describe('if line has changed', function () {
it('should write expected progress of open and close options', function () {
var calledCursorCR = false;
var cachedCursor = Base.cursor;
var useColors = Base.useColors;
Base.useColors = false;
Base.cursor.CR = function () {
calledCursorCR = true;
};
var windowWidth = Base.window.width;
Base.window.width = 5;
var expectedTotal = 12;
var expectedOpen = 'OpEn';
var expectedClose = 'cLoSe';
var expectedIncomplete = 'iNcOmPlEtE';
var expectedOptions = {
open: expectedOpen,
complete: 'cOmPlEtE',
incomplete: expectedIncomplete,
close: expectedClose
};
var options = {
reporterOptions: expectedOptions
};
runner.total = expectedTotal;
runner.on = function (event, callback) {
if (event === 'test end') {
callback();
}
};
Progress.call({}, runner, options);
process.stdout.write = stdoutWrite;
var expectedArray = [
'\u001b[J',
' ' + expectedOpen,
'',
expectedIncomplete,
expectedClose
];
expect(calledCursorCR).to.be(true);
expect(stdout).to.eql(expectedArray);
Base.cursor = cachedCursor;
Base.useColors = useColors;
Base.window.width = windowWidth;
});
});
});
describe('on end', function () {
it('should call cursor show and epilogue', function () {
var cachedCursor = Base.cursor;
var calledCursorShow = false;
Base.cursor.show = function () {
calledCursorShow = true;
};
runner.on = function (event, callback) {
if (event === 'end') {
callback();
}
};
var calledEpilogue = false;
Progress.call({
epilogue: function () {
calledEpilogue = true;
}
}, runner);
process.stdout.write = stdoutWrite;
expect(calledEpilogue).to.be(true);
expect(calledCursorShow).to.be(true);
Base.cursor = cachedCursor;
});
});
});