forked from cucumber/cucumber-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
snippets_formatter.js
54 lines (51 loc) · 1.59 KB
/
snippets_formatter.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
import Formatter from './'
import Status from '../status'
import { KeywordType, getStepKeywordType } from './helpers'
export default class SnippetsFormatter extends Formatter {
constructor(options) {
super(options)
options.eventBroadcaster.on(
'test-step-finished',
::this.logUndefinedTestStepSnippet
)
}
logUndefinedTestStepSnippet({ testCase: { sourceLocation }, index, result }) {
if (result.status === Status.UNDEFINED) {
const {
gherkinDocument,
testCase,
} = this.eventDataCollector.getTestCaseData(sourceLocation)
const {
pickleStep,
gherkinKeyword,
} = this.eventDataCollector.getTestStepData({ testCase, index })
const previousKeywordType = this.getPreviousKeywordType({
gherkinDocument,
testCase,
index,
})
const keywordType = getStepKeywordType({
keyword: gherkinKeyword,
language: gherkinDocument.feature.language,
previousKeywordType,
})
const snippet = this.snippetBuilder.build({ keywordType, pickleStep })
this.log(`${snippet}\n\n`)
}
}
getPreviousKeywordType({ gherkinDocument, testCase, index }) {
let previousKeywordType = KeywordType.PRECONDITION
for (let i = 0; i < index; i += 1) {
const { gherkinKeyword } = this.eventDataCollector.getTestStepData({
testCase,
index: i,
})
previousKeywordType = getStepKeywordType({
keyword: gherkinKeyword,
language: gherkinDocument.feature.language,
previousKeywordType,
})
}
return previousKeywordType
}
}