diff --git a/packages/allure-cucumberjs/src/CucumberJSAllureReporter.ts b/packages/allure-cucumberjs/src/CucumberJSAllureReporter.ts index 93bc9df04..76d9551a0 100644 --- a/packages/allure-cucumberjs/src/CucumberJSAllureReporter.ts +++ b/packages/allure-cucumberjs/src/CucumberJSAllureReporter.ts @@ -240,9 +240,19 @@ export class CucumberJSAllureFormatter extends Formatter { this.documentMap.set(data.uri, data); } - data.feature?.children?.forEach((fc) => { - if (fc.scenario) { - this.onScenario(fc.scenario); + data.feature?.children?.forEach((c) => { + if (c.rule) { + this.onRule(c.rule); + } else if (c.scenario) { + this.onScenario(c.scenario); + } + }); + } + + private onRule(data: messages.Rule): void { + data.children?.forEach((c) => { + if (c.scenario) { + this.onScenario(c.scenario); } }); } diff --git a/packages/allure-cucumberjs/test/specs/with_labels_test.ts b/packages/allure-cucumberjs/test/specs/with_labels_test.ts index ee8ec0b76..3183a26af 100644 --- a/packages/allure-cucumberjs/test/specs/with_labels_test.ts +++ b/packages/allure-cucumberjs/test/specs/with_labels_test.ts @@ -24,6 +24,27 @@ const dataSet: { [name: string]: ITestFormatterOptions } = { }, ], }, + withLabelsAndRules: { + supportCodeLibrary: buildSupportCodeLibrary(({ Given }) => { + Given("a step", () => {}); + }), + sources: [ + { + data: + "@severity:foo @feature:bar\n" + + "Feature: a\n" + + "\n" + + " Rule: r\n" + + "\n" + + " @severity:bar @feature:foo @foo\n" + + " Scenario: b\n" + + " Given a step\n" + + " When do something\n" + + " Then get something\n", + uri: "withIssueLink.feature", + }, + ], + }, }; describe("CucumberJSAllureReporter > examples", () => { @@ -57,4 +78,35 @@ describe("CucumberJSAllureReporter > examples", () => { expect(featureLabels).contains("foo"); expect(featureLabels).contains("bar"); }); + + it("should add labels when scenario is inside a rule", async () => { + const results = await runFeatures(dataSet.withLabelsAndRules, { + labels: [ + { + pattern: [/@feature:(.*)/], + name: "feature", + }, + { + pattern: [/@severity:(.*)/], + name: "severity", + }, + ], + }); + expect(results.tests).length(1); + + const { labels } = results.tests[0]; + const tags = labels.filter((label) => label.name === LabelName.TAG); + const severityLabels = labels + .filter((label) => label.name === LabelName.SEVERITY) + .map(({ value }) => value); + const featureLabels = labels + .filter((label) => label.name === LabelName.FEATURE) + .map(({ value }) => value); + + expect(tags).length(1); + expect(severityLabels).contains("foo"); + expect(severityLabels).contains("bar"); + expect(featureLabels).contains("foo"); + expect(featureLabels).contains("bar"); + }); }); diff --git a/packages/allure-cucumberjs/test/specs/with_links_test.ts b/packages/allure-cucumberjs/test/specs/with_links_test.ts index 62fa4a8c6..9c0d922dc 100644 --- a/packages/allure-cucumberjs/test/specs/with_links_test.ts +++ b/packages/allure-cucumberjs/test/specs/with_links_test.ts @@ -24,6 +24,27 @@ const dataSet: { [name: string]: ITestFormatterOptions } = { }, ], }, + withLinksAndRules: { + supportCodeLibrary: buildSupportCodeLibrary(({ Given }) => { + Given("a step", () => {}); + }), + sources: [ + { + data: + "@foo\n" + + "Feature: a\n" + + "\n" + + " Rule: r\n" + + "\n" + + " @issue=1 @tms=2\n" + + " Scenario: b\n" + + " Given a step\n" + + " When do something\n" + + " Then get something\n", + uri: "withIssueLink.feature", + }, + ], + }, }; describe("CucumberJSAllureReporter > examples", () => { @@ -55,4 +76,33 @@ describe("CucumberJSAllureReporter > examples", () => { const tags = results.tests[0].labels.filter((label) => label.name === LabelName.TAG); expect(tags).length(1); }); + + it("should add links when scenario is inside a rule", async () => { + const results = await runFeatures(dataSet.withLinksAndRules, { + links: [ + { + pattern: [/@issue=(.*)/], + urlTemplate: "https://example.org/issues/%s", + type: "issue", + }, + { + pattern: [/@tms=(.*)/], + urlTemplate: "https://example.org/tasks/%s", + type: "tms", + }, + ], + }); + expect(results.tests).length(1); + + const { links } = results.tests[0]; + + expect(links).length(2); + expect(links[0].type).eq("issue"); + expect(links[0].url).eq("https://example.org/issues/1"); + expect(links[1].type).eq("tms"); + expect(links[1].url).eq("https://example.org/tasks/2"); + + const tags = results.tests[0].labels.filter((label) => label.name === LabelName.TAG); + expect(tags).length(1); + }); });