-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
191 lines (153 loc) · 4.59 KB
/
index.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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
exports.default = createReporter
module.exports = createReporter
function createReporter () {
let fixtureStartTime = -1
const reporterCreatedTime = Date.now()
return {
noColors: false,
startTime: null,
afterErrorList: false,
testCount: 0,
skipped: 0,
currentFixtureName: null,
reportTaskStart (startTime, userAgents, testCount) {
this.startTime = startTime
this.testCount = testCount
this.setIndent(1)
.useWordWrap(true)
.write(this.chalk.bold('Running tests in:'))
.newline()
userAgents.forEach(ua => {
this
.write(`- ${this.chalk.blue(ua)}`)
.newline()
})
this.setIndent(1)
.write(this.chalk.grey(
`Startup time (${this.fmtTime(startTime - reporterCreatedTime)})`
))
.newline()
},
reportFixtureStart (name) {
if (this.afterErrorList) {
this.afterErrorList = false
} else {
this.newline()
}
if (this.currentFixtureName !== null) {
const duration = Date.now() - fixtureStartTime
this.setIndent(1)
.write(this.chalk.grey(
`${this.currentFixtureName} Duration (${this.fmtTime(duration)})`
))
.newline()
}
fixtureStartTime = Date.now()
this.currentFixtureName = name
this.setIndent(1)
.useWordWrap(true)
this.write(name)
.newline()
},
_renderErrors (errs) {
this.setIndent(3)
.newline()
errs.forEach((err, idx) => {
var prefix = this.chalk.red(`${idx + 1}) `)
this.newline()
.write(this.formatError(err, prefix))
.newline()
.newline()
})
},
reportTestStart (name, meta) {},
reportTestDone (name, testRunInfo) {
var hasErr = !!testRunInfo.errs.length
var symbol = null
var nameStyle = null
if (testRunInfo.skipped) {
this.skipped++
symbol = this.chalk.cyan('-')
nameStyle = this.chalk.cyan
} else if (hasErr) {
symbol = this.chalk.red.bold(this.symbols.err)
nameStyle = this.chalk.red.bold
} else {
symbol = this.chalk.green(this.symbols.ok)
nameStyle = this.chalk.grey
}
var title = `${symbol} ${nameStyle(name)}`
this.setIndent(1)
.useWordWrap(true)
if (testRunInfo.unstable) {
title += this.chalk.yellow(' (unstable)')
}
if (testRunInfo.screenshotPath) {
const screen = this.chalk.underline.grey(testRunInfo.screenshotPath)
title += ` (screenshots: ${screen})`
}
this.write(title)
this.write(' ' + this.chalk.grey('(' + this.fmtTime(testRunInfo.durationMs) + ')'))
if (hasErr) {
this._renderErrors(testRunInfo.errs)
}
this.afterErrorList = hasErr
this.newline()
},
_renderWarnings (warnings) {
this.newline()
.setIndent(1)
.write(this.chalk.bold.yellow(`Warnings (${warnings.length}):`))
.newline()
warnings.forEach(msg => {
this.setIndent(1)
.write(this.chalk.bold.yellow('--'))
.newline()
.setIndent(2)
.write(msg)
.newline()
})
},
reportTaskDone (endTime, passed, warnings) {
var durationMs = endTime - this.startTime
var durationStr = this.fmtTime(durationMs)
var footer = passed === this.testCount
? this.chalk.bold.green(`${this.testCount} passed`)
: this.chalk.bold.red(`${this.testCount - passed}/${this.testCount} failed`)
footer += this.chalk.grey(` (${durationStr})`)
if (!this.afterErrorList) {
this.newline()
}
if (this.currentFixtureName !== null) {
const duration = Date.now() - fixtureStartTime
this.setIndent(1)
.write(this.chalk.grey(
`${this.currentFixtureName} Duration (${this.fmtTime(duration)})`
))
.newline()
}
this.setIndent(1)
.useWordWrap(true)
this.newline()
.write(footer)
.newline()
if (this.skipped > 0) {
this.write(this.chalk.cyan(`${this.skipped} skipped`))
.newline()
}
if (warnings.length) {
this._renderWarnings(warnings)
}
this.write(this.chalk.grey(
`Total time (${this.fmtTime(Date.now() - reporterCreatedTime)})`
)).newline()
},
fmtTime (duration) {
if (duration < 10 * 1000) {
const seconds = duration / 1000
return seconds.toFixed(2) + 's'
}
return this.moment.duration(duration).format('h[h] mm[m] ss[s]')
}
}
}