-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
summary_helpers.js
79 lines (74 loc) · 2.04 KB
/
summary_helpers.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
import _ from 'lodash'
import Duration from 'duration'
import Status from '../../status'
import {
addDurations,
durationToMilliseconds,
getZeroDuration,
} from '../../time'
const STATUS_REPORT_ORDER = [
Status.FAILED,
Status.AMBIGUOUS,
Status.UNDEFINED,
Status.PENDING,
Status.SKIPPED,
Status.PASSED,
]
export function formatSummary({ colorFns, testCaseAttempts }) {
const testCaseResults = []
const testStepResults = []
let totalDuration = getZeroDuration()
testCaseAttempts.forEach(({ testCase, result, stepResults }) => {
totalDuration = addDurations(totalDuration, result.duration)
if (!result.willBeRetried) {
testCaseResults.push(result)
_.each(testCase.testSteps, testStep => {
if (testStep.pickleStepId) {
testStepResults.push(stepResults[testStep.id])
}
})
}
})
const scenarioSummary = getCountSummary({
colorFns,
objects: testCaseResults,
type: 'scenario',
})
const stepSummary = getCountSummary({
colorFns,
objects: testStepResults,
type: 'step',
})
const durationSummary = getDurationSummary(totalDuration)
return [scenarioSummary, stepSummary, durationSummary].join('\n')
}
function getCountSummary({ colorFns, objects, type }) {
const counts = _.chain(objects)
.groupBy('status')
.mapValues('length')
.value()
const total = _.reduce(counts, (memo, value) => memo + value) || 0
let text = `${total} ${type}${total === 1 ? '' : 's'}`
if (total > 0) {
const details = []
STATUS_REPORT_ORDER.forEach(status => {
if (counts[status] > 0) {
details.push(
colorFns[status](`${counts[status]} ${Status[status].toLowerCase()}`)
)
}
})
text += ` (${details.join(', ')})`
}
return text
}
function getDurationSummary(durationMsg) {
const start = new Date(0)
const end = new Date(durationToMilliseconds(durationMsg))
const duration = new Duration(start, end)
return (
`${duration.minutes}m${duration.toString('%S')}.${duration.toString(
'%L'
)}s` + `\n`
)
}