Skip to content

Commit

Permalink
format: add support for gherkin rule/example syntax (#1273)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
davidjgoss committed Mar 18, 2020
1 parent 0bbb4b9 commit bf23ac9
Show file tree
Hide file tree
Showing 19 changed files with 1,139 additions and 26 deletions.
9 changes: 9 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# EditorConfig is awesome: https://EditorConfig.org

# top-most EditorConfig file
root = true

# 4 space indentation
[*]
indent_style = space
indent_size = 2
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ Please see [CONTRIBUTING.md](https://github.com/cucumber/cucumber/blob/master/CO

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

#### New Features

* Add support for Gherkin's [Rule/Example syntax](https://cucumber.io/docs/gherkin/reference/#rule)

#### Breaking changes

* Drop support for Node.js 8
Expand Down
32 changes: 32 additions & 0 deletions features/background.feature
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,35 @@ Feature: Background
| IDENTIFIER |
| Given a background step |
| When another scenario step |

Scenario: Two examples within a rule with a background, plus a feature-level background
Given a file named "features/background.feature" with:
"""
Feature: a feature
Background:
Given a feature-level background step
Rule: a rule
Background:
Given a rule-level background step
Example: first example
When an example step
Example: second example
When an example step
When another example step
"""
When I run cucumber-js
Then it fails
And the scenario "first example" has the steps:
| IDENTIFIER |
| Given a feature-level background step |
| Given a rule-level background step |
| When an example step |
And the scenario "second example" has the steps:
| IDENTIFIER |
| Given a feature-level background step |
| Given a rule-level background step |
| When an example step |
| When another example step |
37 changes: 37 additions & 0 deletions features/fixtures/formatters/passed-rule.json.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
module.exports = [
{
description: '',
elements: [
{
description: '',
id: 'a-feature;a-rule;an-example',
keyword: 'Example',
line: 3,
name: 'an example',
steps: [
{
arguments: [],
keyword: 'Given ',
line: 4,
match: {
location: 'features/step_definitions/steps.js:3',
},
name: 'a step',
result: {
duration: 0,
status: 'passed',
},
},
],
tags: [],
type: 'scenario',
},
],
id: 'a-feature',
keyword: 'Feature',
line: 1,
name: 'a feature',
tags: [],
uri: 'features/a.feature',
},
]
143 changes: 143 additions & 0 deletions features/fixtures/formatters/passed-rule.message.json.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
module.exports = [
{
source: {
uri: 'features/a.feature',
data:
'Feature: a feature\n Rule: a rule\n Example: an example\n Given a step',
media: {
encoding: 'UTF8',
contentType: 'text/x.cucumber.gherkin+plain',
},
},
},
{
gherkinDocument: {
uri: 'features/a.feature',
feature: {
location: {
line: 1,
column: 1,
},
language: 'en',
keyword: 'Feature',
name: 'a feature',
children: [
{
rule: {
location: {
line: 2,
column: 3,
},
keyword: 'Rule',
name: 'a rule',
children: [
{
scenario: {
location: {
line: 3,
column: 5,
},
keyword: 'Example',
name: 'an example',
steps: [
{
location: {
line: 4,
column: 7,
},
keyword: 'Given ',
text: 'a step',
id: '1',
},
],
id: '2',
},
},
],
},
},
],
},
},
},
{
pickle: {
id: '4',
uri: 'features/a.feature',
name: 'an example',
language: 'en',
steps: [
{
text: 'a step',
id: '3',
astNodeIds: ['1'],
},
],
astNodeIds: ['2'],
},
},
{
pickleAccepted: {
pickleId: '4',
},
},
{
testRunStarted: {},
},
{
testCase: {
id: '5',
pickleId: '4',
testSteps: [
{
id: '6',
pickleStepId: '3',
stepDefinitionIds: ['0'],
},
],
},
},
{
testCaseStarted: {
attempt: 0,
testCaseId: '5',
id: '7',
},
},
{
testStepStarted: {
testStepId: '6',
testCaseStartedId: '7',
},
},
{
testStepFinished: {
testResult: {
status: 'PASSED',
duration: {
seconds: '0',
nanos: 0,
},
},
testStepId: '6',
testCaseStartedId: '7',
},
},
{
testCaseFinished: {
testResult: {
status: 'PASSED',
duration: {
seconds: '0',
nanos: 0,
},
},
testCaseStartedId: '7',
},
},
{
testRunFinished: {
success: true,
},
},
]
File renamed without changes.
24 changes: 21 additions & 3 deletions features/formatters.feature
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Feature: Formatters
Then the "message" formatter output matches the fixture "formatters/rejected-pickle.message.json"
Then the "json" formatter output matches the fixture "formatters/rejected-pickle.json"

Scenario: passed
Scenario: passed from Scenario
Given a file named "features/a.feature" with:
"""
Feature: a feature
Expand All @@ -25,8 +25,26 @@ Feature: Formatters
Given(/^a step$/, function() {})
"""
When I run cucumber-js with all formatters
Then the "message" formatter output matches the fixture "formatters/passed.message.json"
Then the "json" formatter output matches the fixture "formatters/passed.json"
Then the "message" formatter output matches the fixture "formatters/passed-scenario.message.json"
Then the "json" formatter output matches the fixture "formatters/passed-scenario.json"

Scenario: passed from Rule
Given a file named "features/a.feature" with:
"""
Feature: a feature
Rule: a rule
Example: an example
Given a step
"""
Given a file named "features/step_definitions/steps.js" with:
"""
const {Given} = require('cucumber')
Given(/^a step$/, function() {})
"""
When I run cucumber-js with all formatters
Then the "message" formatter output matches the fixture "formatters/passed-rule.message.json"
Then the "json" formatter output matches the fixture "formatters/passed-rule.json"

Scenario: failed
Given a file named "features/a.feature" with:
Expand Down

0 comments on commit bf23ac9

Please sign in to comment.