Skip to content

Commit

Permalink
add ability to link test results with issues and tms (via #224)
Browse files Browse the repository at this point in the history
  • Loading branch information
damonpam authored Mar 1, 2021
1 parent 2debbad commit d520456
Show file tree
Hide file tree
Showing 6 changed files with 259 additions and 105 deletions.
37 changes: 28 additions & 9 deletions packages/allure-cucumberjs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,40 @@ export default class Reporter extends CucumberJSAllureFormatter {
constructor(options) {
super(
options,
new AllureRuntime({ resultsDir: "./out/allure-results" }),
new AllureRuntime({ resultsDir: "./allure-results" }),
{
labels: {
issue: [/@bug_(.*)/],
epic: [/@feature:(.*)/]
epic: [/@feature:(.*)/],
severity: [/@severity:(.*)/]
},
links: {
issue: {
pattern: [/@issue=(.*)/],
urlTemplate: "http://localhost:8080/issue/%s"
},
tms: {
pattern: [/@tms=(.*)/],
urlTemplate: "http://localhost:8080/tms/%s"
}
}
}
);
}
}
```
This class MUST:
* Be a default export
* Extend `CucumberJSAllureFormatter`
* Take 1 argument in constructor and pass it to `super()` as first argument
* Second `super()` argument is `AllureRuntime` instance
* Third is a config, currently allows to map tags to Allure labels
This class **MUST**:
* Be a default export.
* Extend `CucumberJSAllureFormatter`.
* First `super()` argument is the first argument in the `constructor`.
* Second `super()` argument is an `AllureRuntime` instance.
* Third argument is a config object which allows:
* Map tags to Allure labels.
* Add links to external sites like JIRA, XRAY, etc. `%s` will be auto-replaced by the issue id. Example:
```gherkin
@issue=TEST-1
Scenario: Example for scenario issue link check
Then the issue link should be "http://localhost:8080/issue/TEST-1"
```

Then pass with reporter as a Cucumber formatter:
```
Expand Down Expand Up @@ -68,3 +85,5 @@ Ilya Korobitsyn <[email protected]>
#### Contributors

* Claudia Hardman <[email protected]>
* Max Di Maria <[email protected]>
* Daniel Montesinos <[email protected]>
50 changes: 50 additions & 0 deletions packages/allure-cucumberjs/features/links.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
Feature: Links

Background:
Given a allure formatter file with config:
"""
{
links: {
issue: {
pattern: [/@issue=(.*)/],
urlTemplate: "http://localhost:8080/issue/%s"
},
tms: {
pattern: [/@tms=(.*)/],
urlTemplate: "http://localhost:8080/tms/%s"
}
}
}
"""

Scenario: Reporting scenario issue link
Given a feature:
"""
Feature: Feature issue links
@issue=TEST
Scenario: Example for scenario issue link check
When do passing step
Then do passing step
"""
When I run cucumber-js with allure
Then it passes
Then it has result for "Example for scenario issue link check"

When I choose result for "Example for scenario issue link check"
Then it has link with url "http://localhost:8080/issue/TEST" with name "TEST" and with type "issue"

Scenario: Reporting scenario tms link
Given a feature:
"""
Feature: Feature issue links
@tms=TEST
Scenario: Example for scenario tms link check
When do passing step
Then do passing step
"""
When I run cucumber-js with allure
Then it passes
Then it has result for "Example for scenario tms link check"

When I choose result for "Example for scenario tms link check"
Then it has link with url "http://localhost:8080/tms/TEST" with name "TEST" and with type "tms"
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { StepResult, TestResult } from "allure-js-commons";
import chai, { expect } from "chai";
import { Then, When } from "cucumber";
import { expect } from "chai";
import chai from "chai";
import { TestResult } from "allure-js-commons";
import { ChaiPartial } from "../support/chai-partial";
import { StepResult } from "allure-js-commons";

chai.use(ChaiPartial);

Expand Down Expand Up @@ -35,3 +33,8 @@ Then(/^it has label "(.*)" with value "(.*)"$/, function(name: string, value: st
Then(/^it has description "(.*)"$/, function(description: string) {
expect(this.ctx).partial({ description });
});

Then(/^it has link with url "(.*)" with name "(.*)" and with type "(.*)"$/,
function(url: string, name: string, type: string) {
expect(this.ctx).partial({ links: [{ url, name, type }] });
});
8 changes: 8 additions & 0 deletions packages/allure-cucumberjs/src/CucumberAllureInterface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,14 @@ export class CucumberAllureInterface extends Allure {
addLabel(name: string, value: string): void {
this.currentTest.addLabel(name, value);
}

addIssueLink(url: string, name: string) {
this.currentTest.addIssueLink(url, name);
}

addTmsLink(url: string, name: string) {
this.currentTest.addTmsLink(url, name);
}
}

export class WrappedStep {
Expand Down
Loading

0 comments on commit d520456

Please sign in to comment.