Skip to content

Commit bf23ac9

Browse files
authored
format: add support for gherkin rule/example syntax (#1273)
* add basic feature for gherkin rule/example support * use require instead of import * assert on formatter output for passing example * add formatters.feature scenario for rejected pickle from rule * add formatters.feature scenario for passed from rule * add editorconfig for indentation control * formatting * make `getGherkinStepMap` rule-aware * restructure tests a bit * refactor tests a bit more, add some to cover getGherkinScenarioMap * account for Rule in getGherkinScenarioMap * rework getGherkinScenarioLocationMap to handle Rule * add unit test for Rule/Example in json formatter * report keyword as Scenario or Example correctly from scenario map * include rule name in concatenated scenario id for json formatter * make sure we work with a background within a rule * readability * add background usage to rule feature, assert on failure output * add acceptance test for message and json format on failure from rule * add a bit of coverage for the progress bar formatter * more on progress far - numbers/time reporting at end * work rule usage into progress formatter spec * work rule usage into rerun formatter spec * work rule usage into summary formatter spec * add coverage for pickle filtering on name * changelog update * rework progress formatter spec to have a seperate case for rule/example * remove negative test for rule/example in json formatter * rework gherkin document parser spec to avoid replication of structure * fix some lint * fix line numbers in formatter unit tests * fix dodgy import * fix overqualified references to messages interfaces * remove unnecessary tags * for progress bar formatter, break out new test for rule/example, retain scenario one * split out new test for rule/example in rerun formatter spec * remove superfluous formatter tests * fix whitespace * restore original names where qualifiers no longer needed
1 parent 0bbb4b9 commit bf23ac9

19 files changed

+1139
-26
lines changed

.editorconfig

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# EditorConfig is awesome: https://EditorConfig.org
2+
3+
# top-most EditorConfig file
4+
root = true
5+
6+
# 4 space indentation
7+
[*]
8+
indent_style = space
9+
indent_size = 2

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ Please see [CONTRIBUTING.md](https://github.com/cucumber/cucumber/blob/master/CO
22

33
### [Unreleased](https://github.com/cucumber/cucumber-js/compare/v6.0.5...master) (In Git)
44

5+
#### New Features
6+
7+
* Add support for Gherkin's [Rule/Example syntax](https://cucumber.io/docs/gherkin/reference/#rule)
8+
59
#### Breaking changes
610

711
* Drop support for Node.js 8

features/background.feature

+32
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,35 @@ Feature: Background
4646
| IDENTIFIER |
4747
| Given a background step |
4848
| When another scenario step |
49+
50+
Scenario: Two examples within a rule with a background, plus a feature-level background
51+
Given a file named "features/background.feature" with:
52+
"""
53+
Feature: a feature
54+
Background:
55+
Given a feature-level background step
56+
57+
Rule: a rule
58+
Background:
59+
Given a rule-level background step
60+
61+
Example: first example
62+
When an example step
63+
64+
Example: second example
65+
When an example step
66+
When another example step
67+
"""
68+
When I run cucumber-js
69+
Then it fails
70+
And the scenario "first example" has the steps:
71+
| IDENTIFIER |
72+
| Given a feature-level background step |
73+
| Given a rule-level background step |
74+
| When an example step |
75+
And the scenario "second example" has the steps:
76+
| IDENTIFIER |
77+
| Given a feature-level background step |
78+
| Given a rule-level background step |
79+
| When an example step |
80+
| When another example step |
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
module.exports = [
2+
{
3+
description: '',
4+
elements: [
5+
{
6+
description: '',
7+
id: 'a-feature;a-rule;an-example',
8+
keyword: 'Example',
9+
line: 3,
10+
name: 'an example',
11+
steps: [
12+
{
13+
arguments: [],
14+
keyword: 'Given ',
15+
line: 4,
16+
match: {
17+
location: 'features/step_definitions/steps.js:3',
18+
},
19+
name: 'a step',
20+
result: {
21+
duration: 0,
22+
status: 'passed',
23+
},
24+
},
25+
],
26+
tags: [],
27+
type: 'scenario',
28+
},
29+
],
30+
id: 'a-feature',
31+
keyword: 'Feature',
32+
line: 1,
33+
name: 'a feature',
34+
tags: [],
35+
uri: 'features/a.feature',
36+
},
37+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
module.exports = [
2+
{
3+
source: {
4+
uri: 'features/a.feature',
5+
data:
6+
'Feature: a feature\n Rule: a rule\n Example: an example\n Given a step',
7+
media: {
8+
encoding: 'UTF8',
9+
contentType: 'text/x.cucumber.gherkin+plain',
10+
},
11+
},
12+
},
13+
{
14+
gherkinDocument: {
15+
uri: 'features/a.feature',
16+
feature: {
17+
location: {
18+
line: 1,
19+
column: 1,
20+
},
21+
language: 'en',
22+
keyword: 'Feature',
23+
name: 'a feature',
24+
children: [
25+
{
26+
rule: {
27+
location: {
28+
line: 2,
29+
column: 3,
30+
},
31+
keyword: 'Rule',
32+
name: 'a rule',
33+
children: [
34+
{
35+
scenario: {
36+
location: {
37+
line: 3,
38+
column: 5,
39+
},
40+
keyword: 'Example',
41+
name: 'an example',
42+
steps: [
43+
{
44+
location: {
45+
line: 4,
46+
column: 7,
47+
},
48+
keyword: 'Given ',
49+
text: 'a step',
50+
id: '1',
51+
},
52+
],
53+
id: '2',
54+
},
55+
},
56+
],
57+
},
58+
},
59+
],
60+
},
61+
},
62+
},
63+
{
64+
pickle: {
65+
id: '4',
66+
uri: 'features/a.feature',
67+
name: 'an example',
68+
language: 'en',
69+
steps: [
70+
{
71+
text: 'a step',
72+
id: '3',
73+
astNodeIds: ['1'],
74+
},
75+
],
76+
astNodeIds: ['2'],
77+
},
78+
},
79+
{
80+
pickleAccepted: {
81+
pickleId: '4',
82+
},
83+
},
84+
{
85+
testRunStarted: {},
86+
},
87+
{
88+
testCase: {
89+
id: '5',
90+
pickleId: '4',
91+
testSteps: [
92+
{
93+
id: '6',
94+
pickleStepId: '3',
95+
stepDefinitionIds: ['0'],
96+
},
97+
],
98+
},
99+
},
100+
{
101+
testCaseStarted: {
102+
attempt: 0,
103+
testCaseId: '5',
104+
id: '7',
105+
},
106+
},
107+
{
108+
testStepStarted: {
109+
testStepId: '6',
110+
testCaseStartedId: '7',
111+
},
112+
},
113+
{
114+
testStepFinished: {
115+
testResult: {
116+
status: 'PASSED',
117+
duration: {
118+
seconds: '0',
119+
nanos: 0,
120+
},
121+
},
122+
testStepId: '6',
123+
testCaseStartedId: '7',
124+
},
125+
},
126+
{
127+
testCaseFinished: {
128+
testResult: {
129+
status: 'PASSED',
130+
duration: {
131+
seconds: '0',
132+
nanos: 0,
133+
},
134+
},
135+
testCaseStartedId: '7',
136+
},
137+
},
138+
{
139+
testRunFinished: {
140+
success: true,
141+
},
142+
},
143+
]

features/formatters.feature

+21-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Feature: Formatters
1111
Then the "message" formatter output matches the fixture "formatters/rejected-pickle.message.json"
1212
Then the "json" formatter output matches the fixture "formatters/rejected-pickle.json"
1313

14-
Scenario: passed
14+
Scenario: passed from Scenario
1515
Given a file named "features/a.feature" with:
1616
"""
1717
Feature: a feature
@@ -25,8 +25,26 @@ Feature: Formatters
2525
Given(/^a step$/, function() {})
2626
"""
2727
When I run cucumber-js with all formatters
28-
Then the "message" formatter output matches the fixture "formatters/passed.message.json"
29-
Then the "json" formatter output matches the fixture "formatters/passed.json"
28+
Then the "message" formatter output matches the fixture "formatters/passed-scenario.message.json"
29+
Then the "json" formatter output matches the fixture "formatters/passed-scenario.json"
30+
31+
Scenario: passed from Rule
32+
Given a file named "features/a.feature" with:
33+
"""
34+
Feature: a feature
35+
Rule: a rule
36+
Example: an example
37+
Given a step
38+
"""
39+
Given a file named "features/step_definitions/steps.js" with:
40+
"""
41+
const {Given} = require('cucumber')
42+
43+
Given(/^a step$/, function() {})
44+
"""
45+
When I run cucumber-js with all formatters
46+
Then the "message" formatter output matches the fixture "formatters/passed-rule.message.json"
47+
Then the "json" formatter output matches the fixture "formatters/passed-rule.json"
3048

3149
Scenario: failed
3250
Given a file named "features/a.feature" with:

0 commit comments

Comments
 (0)