-
-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathgetGherkinDiagnostics.test.ts
206 lines (196 loc) · 5.61 KB
/
getGherkinDiagnostics.test.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
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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
import { CucumberExpression, ParameterTypeRegistry } from '@cucumber/cucumber-expressions'
import assert from 'assert'
import { Diagnostic, DiagnosticSeverity } from 'vscode-languageserver-types'
import { getGherkinDiagnostics } from '../../src/service/getGherkinDiagnostics.js'
describe('getGherkinDiagnostics', () => {
it('returns no diagnostics for valid document', () => {
const diagnostics = getGherkinDiagnostics(`Feature: Hello`, [])
assert.deepStrictEqual(diagnostics, [])
})
it('returns error diagnostic for unexpected end of file', () => {
const diagnostics = getGherkinDiagnostics(
`Feature: Hello
@tag
`,
[]
)
assert.deepStrictEqual(diagnostics, [
{
message: '(3:0): unexpected end of file, expected: #TagLine, #RuleLine, #Comment, #Empty',
range: {
start: {
line: 2,
character: 0,
},
end: {
line: 2,
character: 0,
},
},
severity: DiagnosticSeverity.Error,
source: 'Cucumber',
},
])
})
it('returns error diagnostic for missing table separator', () => {
const expression = new CucumberExpression('a table:', new ParameterTypeRegistry())
const diagnostics = getGherkinDiagnostics(
`Feature: Hello
Scenario: Hi
Given a table:
| a |
| b
`,
[expression]
)
const expectedDiagnostics: Diagnostic[] = [
{
message: '(5:7): inconsistent cell count within the table',
range: {
start: {
line: 4,
character: 6,
},
end: {
line: 4,
character: 9,
},
},
severity: DiagnosticSeverity.Error,
source: 'Cucumber',
},
]
assert.deepStrictEqual(diagnostics, expectedDiagnostics)
})
it('returns warning diagnostic for undefined Given->And step', () => {
const diagnostics = getGherkinDiagnostics(
`Feature: Hello
Scenario: Hi
Given a defined step
And an undefined step
`,
[new CucumberExpression('a defined step', new ParameterTypeRegistry())]
)
const expectedDiagnostics: Diagnostic[] = [
{
code: 'cucumber.undefined-step',
codeDescription: {
href: 'https://cucumber.io/docs/cucumber/step-definitions/',
},
data: {
snippetKeyword: 'Given ',
stepText: 'an undefined step',
},
message: 'Undefined step: an undefined step',
range: {
start: {
line: 3,
character: 8,
},
end: {
line: 3,
character: 25,
},
},
severity: DiagnosticSeverity.Warning,
source: 'Cucumber',
},
]
assert.deepStrictEqual(diagnostics, expectedDiagnostics)
})
it('returns warning diagnostic for undefined When->And->But step', () => {
const diagnostics = getGherkinDiagnostics(
`Feature: Hello
Scenario: Hi
Given a defined step
When a defined step
And a defined step
But an undefined step
`,
[new CucumberExpression('a defined step', new ParameterTypeRegistry())]
)
const expectedDiagnostics: Diagnostic[] = [
{
code: 'cucumber.undefined-step',
codeDescription: {
href: 'https://cucumber.io/docs/cucumber/step-definitions/',
},
data: {
snippetKeyword: 'When ',
stepText: 'an undefined step',
},
message: 'Undefined step: an undefined step',
range: {
start: {
line: 5,
character: 8,
},
end: {
line: 5,
character: 25,
},
},
severity: DiagnosticSeverity.Warning,
source: 'Cucumber',
},
]
assert.deepStrictEqual(diagnostics, expectedDiagnostics)
})
it('returns diagnostic for undefined step with unreferenced parameter in Scenario Outline', () => {
const noExamples = `Feature:
Scenario Outline:
Given a <parameter>`
const noTableHeader = `Feature:
Scenario Outline:
Given a <parameter>
Examples:`
const noTableBody = `Feature:
Scenario Outline:
Given a <parameter>
Examples:
| parameter |`
for (const document of [noExamples, noTableHeader, noTableBody]) {
const diagnostics = getGherkinDiagnostics(document, [])
const expectedDiagnostics: Diagnostic[] = [
{
code: 'cucumber.undefined-step',
codeDescription: {
href: 'https://cucumber.io/docs/cucumber/step-definitions/',
},
data: {
snippetKeyword: 'Given ',
stepText: 'a <parameter>',
},
message: 'Undefined step: a <parameter>',
range: {
end: {
character: 27,
line: 2,
},
start: {
character: 14,
line: 2,
},
},
severity: 2,
source: 'Cucumber',
},
]
assert.deepStrictEqual(diagnostics, expectedDiagnostics)
}
})
it('returns no diagnostics with valid parameter match in Scenario Outline', () => {
const diagnostics = getGherkinDiagnostics(
`Feature:
Scenario Outline:
Given a <state> <entity>
Examples:
| parameter | state | entity | other |
| unused | defined | step | unused |
`,
[new CucumberExpression('a defined step', new ParameterTypeRegistry())]
)
const expectedDiagnostics: Diagnostic[] = []
assert.deepStrictEqual(diagnostics, expectedDiagnostics)
})
})