Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(compiler): add support for the Gherkin Rule keyword #135

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions examples/rules.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
Feature: Rules

I want to be able to use the Gherkin Rule keyword in feature files

Rule: Scenarios within rules should be executed

Scenario: Scenario within a rule
Then I should output the name of the scenario

Rule: Examples within rules should be executed

Example: Example within a rule
Then I should output the name of the scenario

Rule: Scenario outlines within rules should execute all parameters

Scenario Outline: Scenario <example> of outline within a rule
Then I should output the name of the scenario

Examples:
| example |
| 1 |
| 2 |

Rule: Parameterized scenarios within rules should execute all parameters

Scenario: Parameterized scenario <example> within a rule
Then I should output the name of the scenario

Examples:
| example |
| 1 |
| 2 |
5 changes: 5 additions & 0 deletions examples/rules.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const { Then } = require('@cucumber/cucumber');

Then('I should output the name of the scenario', (t) => {
console.log('Executed scenario', t.testRun.test.name);
});
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"http-auth-example": "node main.js chrome ./examples/http-authentication-example.*",
"error-reporting-example": "node main.js chrome ./examples/error-reporting* ./examples/google.ts",
"hooks-example": "node main.js chrome ./examples/hooks*",
"rules-example": "node main.js chrome ./examples/rules.*",
"tags-1-example": "node main.js chrome ./examples/tags.* --tags @scenarioTag1",
"tags-not1-example": "node main.js chrome ./examples/tags.* --tags ~@scenarioTag1",
"tags-1or2-example": "node main.js chrome ./examples/tags.* --tags @scenarioTag1,@scenarioTag2",
Expand Down
10 changes: 9 additions & 1 deletion src/compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,15 @@ module.exports = class GherkinTestcafeCompiler {
const backgroundNode = gherkinDocument.feature.children.find((node) => node.background);

const scenarioNode = gherkinDocument.feature.children
.filter((node) => node.scenario)
.flatMap((node) => {
if (node.scenario) {
return [node];
} else if (node.rule) {
return node.rule.children.filter((childNode) => childNode.scenario);
} else {
return [];
}
})
.find((node) => node.scenario.id === scenario.astNodeIds[0]);

const setFailIndex = (test, index) => test.meta({ failIndex: index });
Expand Down