Skip to content

Commit

Permalink
fix: missing "Background" in Cucumber steps (#178)
Browse files Browse the repository at this point in the history
  • Loading branch information
mistic100 authored Jan 26, 2024
1 parent 8f4d5ae commit 51e3a81
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
4 changes: 2 additions & 2 deletions cucumberSupport.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ Before(({ pickle, gherkinDocument }) => {
feature: {
...gherkinDocument.feature,
// keep only the scenario corresponding to the current pickle
children: gherkinDocument.feature.children.filter(f => f.scenario?.id === pickle.astNodeIds[0]),
children: gherkinDocument.feature.children.filter(f => !f.scenario || f.scenario.id === pickle.astNodeIds[0]),
},
}));

// for scenario outlines, only keep the corresponding example
const scenario = gherkinDocumentWithSingleScenario.feature.children[0].scenario;
const scenario = gherkinDocumentWithSingleScenario.feature.children.filter(f => f.scenario)[0]?.scenario;
if (scenario.examples.length) {
const example = scenario.examples[0];
example.tableBody = example.tableBody.filter(row => row.id === pickle.astNodeIds[1]);
Expand Down
15 changes: 10 additions & 5 deletions cypress/e2e/cucumber.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ describe(`cucumber folder`, () => {
'pass',
`
Feature: Test 1
Background:
When I visit "site/index.html"
Scenario: pass
When I visit "site/index.html"
Then The list has 4 items
`
);
Expand All @@ -42,9 +43,10 @@ Feature: Test 1
'fail',
`
Feature: Test 1
Background:
When I visit "site/index.html"
Scenario: fail
When I visit "site/index.html"
Then The list has 5 items
`
);
Expand All @@ -55,9 +57,10 @@ Feature: Test 1
'pass with examples (example #1)',
`
Feature: Test 1
Background:
When I visit "site/index.html"
Scenario Outline: pass with examples
When I visit "site/index.html"
Then The list has more than <num> items
Examples:
Expand All @@ -72,9 +75,10 @@ Feature: Test 1
'pass with examples (example #2)',
`
Feature: Test 1
Background:
When I visit "site/index.html"
Scenario Outline: pass with examples
When I visit "site/index.html"
Then The list has more than <num> items
Examples:
Expand All @@ -89,9 +93,10 @@ Feature: Test 1
'pass with examples (example #3)',
`
Feature: Test 1
Background:
When I visit "site/index.html"
Scenario Outline: pass with examples
When I visit "site/index.html"
Then The list has more than <num> items
Examples:
Expand Down
5 changes: 2 additions & 3 deletions examples/cucumber/cypress/e2e/test1.feature
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
Feature: Test 1
Background:
When I visit "site/index.html"

Scenario: pass
When I visit "site/index.html"
Then The list has 4 items

Scenario: fail
When I visit "site/index.html"
Then The list has 5 items

Scenario Outline: pass with examples
When I visit "site/index.html"
Then The list has more than <num> items

Examples:
Expand Down

0 comments on commit 51e3a81

Please sign in to comment.