Skip to content

Commit

Permalink
fix(cucumber): add support for rule keyword (via #751)
Browse files Browse the repository at this point in the history
  • Loading branch information
caiogevegir authored Aug 17, 2023
1 parent 9337694 commit a74ead7
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 3 deletions.
16 changes: 13 additions & 3 deletions packages/allure-cucumberjs/src/CucumberJSAllureReporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
});
}
Expand Down
52 changes: 52 additions & 0 deletions packages/allure-cucumberjs/test/specs/with_labels_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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", () => {
Expand Down Expand Up @@ -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");
});
});
50 changes: 50 additions & 0 deletions packages/allure-cucumberjs/test/specs/with_links_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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", () => {
Expand Down Expand Up @@ -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);
});
});

0 comments on commit a74ead7

Please sign in to comment.