-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
Copy pathsnippets_formatter.ts
38 lines (35 loc) · 1.25 KB
/
snippets_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
import * as messages from '@cucumber/messages'
import { doesHaveValue } from '../value_checker'
import { parseTestCaseAttempt } from './helpers'
import Formatter, { IFormatterOptions } from './'
import IEnvelope = messages.Envelope
export default class SnippetsFormatter extends Formatter {
public static readonly documentation: string =
"The Snippets Formatter doesn't output anything regarding the test run; it just prints snippets to implement any undefined steps"
constructor(options: IFormatterOptions) {
super(options)
options.eventBroadcaster.on('envelope', (envelope: IEnvelope) => {
if (doesHaveValue(envelope.testRunFinished)) {
this.logSnippets()
}
})
}
logSnippets(): void {
const snippets: string[] = []
this.eventDataCollector.getTestCaseAttempts().forEach((testCaseAttempt) => {
const parsed = parseTestCaseAttempt({
snippetBuilder: this.snippetBuilder,
supportCodeLibrary: this.supportCodeLibrary,
testCaseAttempt,
})
parsed.testSteps.forEach((testStep) => {
if (
testStep.result.status === messages.TestStepResultStatus.UNDEFINED
) {
snippets.push(testStep.snippet)
}
})
})
this.log(snippets.join('\n\n'))
}
}