diff --git a/examples/rules.feature b/examples/rules.feature new file mode 100644 index 0000000..75d1ddd --- /dev/null +++ b/examples/rules.feature @@ -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 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 within a rule + Then I should output the name of the scenario + + Examples: + | example | + | 1 | + | 2 | \ No newline at end of file diff --git a/examples/rules.js b/examples/rules.js new file mode 100644 index 0000000..ee27302 --- /dev/null +++ b/examples/rules.js @@ -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); +}); diff --git a/package.json b/package.json index 2158845..1037c97 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/compiler.js b/src/compiler.js index 484f468..1086559 100644 --- a/src/compiler.js +++ b/src/compiler.js @@ -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 });