-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
Copy pathsummary_formatter.ts
95 lines (90 loc) · 2.85 KB
/
summary_formatter.ts
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
import * as messages from '@cucumber/messages'
import { doesHaveValue } from '../value_checker'
import { durationBetweenTimestamps } from '../time'
import { formatIssue, formatSummary, isFailure, isWarning } from './helpers'
import { ITestCaseAttempt } from './helpers/event_data_collector'
import { formatUndefinedParameterTypes } from './helpers/issue_helpers'
import Formatter, { IFormatterOptions } from './'
interface ILogIssuesRequest {
issues: ITestCaseAttempt[]
title: string
}
export default class SummaryFormatter extends Formatter {
public static readonly documentation: string =
'Summary output of feature and scenarios'
constructor(options: IFormatterOptions) {
super(options)
let testRunStartedTimestamp: messages.Timestamp
options.eventBroadcaster.on('envelope', (envelope: messages.Envelope) => {
if (doesHaveValue(envelope.testRunStarted)) {
testRunStartedTimestamp = envelope.testRunStarted.timestamp
}
if (doesHaveValue(envelope.testRunFinished)) {
const testRunFinishedTimestamp = envelope.testRunFinished.timestamp
this.logSummary(
durationBetweenTimestamps(
testRunStartedTimestamp,
testRunFinishedTimestamp
)
)
}
})
}
logSummary(testRunDuration: messages.Duration): void {
const failures: ITestCaseAttempt[] = []
const warnings: ITestCaseAttempt[] = []
const testCaseAttempts = this.eventDataCollector.getTestCaseAttempts()
testCaseAttempts.forEach((testCaseAttempt) => {
if (
isFailure(
testCaseAttempt.worstTestStepResult,
testCaseAttempt.willBeRetried
)
) {
failures.push(testCaseAttempt)
} else if (
isWarning(
testCaseAttempt.worstTestStepResult,
testCaseAttempt.willBeRetried
)
) {
warnings.push(testCaseAttempt)
}
})
if (this.eventDataCollector.undefinedParameterTypes.length > 0) {
this.log(
formatUndefinedParameterTypes(
this.eventDataCollector.undefinedParameterTypes
)
)
}
if (failures.length > 0) {
this.logIssues({ issues: failures, title: 'Failures' })
}
if (warnings.length > 0) {
this.logIssues({ issues: warnings, title: 'Warnings' })
}
this.log(
formatSummary({
colorFns: this.colorFns,
testCaseAttempts,
testRunDuration,
})
)
}
logIssues({ issues, title }: ILogIssuesRequest): void {
this.log(`${title}:\n\n`)
issues.forEach((testCaseAttempt, index) => {
this.log(
formatIssue({
colorFns: this.colorFns,
number: index + 1,
snippetBuilder: this.snippetBuilder,
supportCodeLibrary: this.supportCodeLibrary,
testCaseAttempt,
printAttachments: this.printAttachments,
})
)
})
}
}