-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
progress.js
60 lines (44 loc) · 1.13 KB
/
progress.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
var BaseReporter = require('./base')
var ProgressReporter = function (formatError, reportSlow) {
BaseReporter.call(this, formatError, reportSlow)
this.writeCommonMsg = function (msg) {
this.write(this._remove() + msg + this._render())
}
this.specSuccess = function () {
this.write(this._refresh())
}
this.onBrowserComplete = function () {
this.write(this._refresh())
}
this.onRunStart = function () {
this._browsers = []
this._isRendered = false
}
this.onBrowserStart = function (browser) {
this._browsers.push(browser)
if (this._isRendered) {
this.write('\n')
}
this.write(this._refresh())
}
this._remove = function () {
if (!this._isRendered) {
return ''
}
var cmd = ''
this._browsers.forEach(function () {
cmd += '\x1B[1A' + '\x1B[2K'
})
this._isRendered = false
return cmd
}
this._render = function () {
this._isRendered = true
return this._browsers.map(this.renderBrowser).join('\n') + '\n'
}
this._refresh = function () {
return this._remove() + this._render()
}
}
// PUBLISH
module.exports = ProgressReporter