Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

Commit

Permalink
feat(Generator): support tags with wildcard (#66)
Browse files Browse the repository at this point in the history
  • Loading branch information
TobiTenno authored Apr 6, 2021
1 parent 5188eb2 commit ecbc504
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 23 deletions.
8 changes: 5 additions & 3 deletions .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Please fill out the below template as best you can.
--------------------------------------------------------
<!-- Please fill out the below template as best you can.
-------------------------------------------------------->

### Description of Issue
Describe the issue as best you can. Screenshots, logs, and stack traces can be very helpful!
<!-- Describe the issue as best you can. Screenshots, logs, and stack traces can be very helpful! -->

### System Configuration
#### Project Version
Expand All @@ -14,5 +14,7 @@ Describe the issue as best you can. Screenshots, logs, and stack traces can be v
1. Step 2

### Expected Outcomes
<!--
- Links can be styled as buttons
- Disabled links behave the same as disabled buttons
-->
7 changes: 5 additions & 2 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
### Summary
Summarize the contents of the code changes in your pull request. Tag any open issues you believe to be resolved by this pull request.
<!-- Summarize the contents of the code changes in your pull request. Tag any open issues you believe to be resolved by this pull request. -->

### Additional Details
<!--
If you have anything else that you think may be relevant to this issue, list it here. Additional information can help us better understand your changes and speed up the review process.
Please add your name to the [CONTRIBUTORS.md] file. Adding your name to the [CONTRIBUTORS.md] file signifies agreement to all rights and reservations provided by the [License].
Thanks for contributing to cucumber-forge-report-generator.
Thanks for contributing to cucumber-forge-report-generator.
[CONTRIBUTORS.md]: ../blob/main/CONTRIBUTORS.md
[License]: ../blob/main/LICENSE
-->
34 changes: 26 additions & 8 deletions features/generate_report.feature
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ Feature: Report Generation
Background:
Given I have a dog
@feeding
@feeding @feed_dog
Scenario: Feeding the Dog
Given the dog is hungery
Given the dog is hungry
When I give dog food to the dog
Then the dog will eat it
Expand Down Expand Up @@ -45,9 +45,9 @@ Feature: Report Generation
Background:
Given I have a cat
@feeding
@feeding @feed_cat
Scenario: Feeding the Cat
Given the cat is hungery
Given the cat is hungry
When I give the following food to the cat:
| fish |
| steak |
Expand Down Expand Up @@ -117,6 +117,24 @@ Feature: Report Generation
| 'feeding' |
| '@feeding' |

Scenario Outline: Generating an HTML report with scenarios filtered by a tag ending with a wildcard
If the provided tag ends with a wildcard (`*`), the features and scenarios are filtered to the ones with
tags that begin with the given tag value.

When a report is generated with the code "new Generator().generate(this.allFeaturesPath, null, <tag:>)"
Then the report will contain 2 features
And the report will contain 2 scenarios
And the report name on the sidebar will be <tag:>
And the sidebar will contain 2 feature buttons
And the sidebar will contain 2 scenario buttons

Examples:
| tag: |
| '@feeding*'|
| 'feeding*' |
| 'feed_*' |
| '@feed_*' |

Scenario: Generating an HTML report with features filtered by a tag
The features and scenarios included in a report can be filtered based on their tags.

Expand All @@ -142,7 +160,7 @@ Feature: Report Generation
@feeding
Scenario: Feeding the Dog
Given the dog is hungery
Given the dog is hungry
When I give dog food to the dog
Then the dog will eat it
"""
Expand All @@ -153,7 +171,7 @@ Feature: Report Generation
Given there is a file named 'invalid.feature' in the 'feature/dog' directory with the following contents:
"""
Feature: Dog Care
Given the dog is hungery
Given the dog is hungry
When I give dog food to the dog
Then the dog will eat it
"""
Expand All @@ -163,7 +181,7 @@ Feature: Report Generation
Scenario: Generating a report when the directory contains a feature file that has only Cucumber steps
Given there is a file named 'invalid.feature' in the 'feature/dog' directory with the following contents:
"""
Given the dog is hungery
Given the dog is hungry
When I give dog food to the dog
Then the dog will eat it
"""
Expand Down Expand Up @@ -264,7 +282,7 @@ Feature: Report Generation
# language: american
Feature: Dog Care
Scenario: Feeding the Dog
Given the dog is hungery
Given the dog is hungry
When I give dog food to the dog
Then the dog will eat it
"""
Expand Down
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 9 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
"main": "src/Generator.js",
"types": "types/Generator.d.ts",
"scripts": {
"test": "./node_modules/.bin/cucumber-js features/*.feature",
"lint": "npx eslint src --color",
"build:types": "npx -p typescript tsc -p tsconfig.declaration.json",
"test": "cucumber-js features/*.feature",
"lint": "eslint src --color",
"lint:fix": "eslint src --color --fix",
"build:types": "tsc -p tsconfig.declaration.json",
"prepublishOnly": "npm run build:types"
},
"repository": {
Expand All @@ -24,7 +25,9 @@
"author": "Cerner Corporation",
"license": "Apache-2.0",
"release": {
"branches": ["main"],
"branches": [
"main"
],
"repositoryUrl": "https://github.com/cerner/cucumber-forge-report-generator.git"
},
"dependencies": {
Expand All @@ -41,6 +44,7 @@
"eslint": "^7.9.0",
"eslint-config-airbnb-base": "^14.2.0",
"eslint-plugin-import": "^2.22.0",
"jsdom": "^16.4.0"
"jsdom": "^16.4.0",
"typescript": "^4.1.3"
}
}
22 changes: 17 additions & 5 deletions src/Generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,12 +186,24 @@ const getFeatureFromFile = (featureFilename) => {
return feature;
};

const getFilteredScenarios = (scenarios) => scenarios.map((scenario) => {
if (scenario.tags && scenario.tags.includes(tagFilter)) {
return scenario;
const filterScenarioByTag = (scenario) => {
// empty filter: allow all
if (!tagFilter) return true;

let allow = false;
const wild = tagFilter.endsWith('*');
const strippedFilter = tagFilter.endsWith('*') ? tagFilter.slice(0, -1) : tagFilter;
if (scenario.tags) {
scenario.tags.forEach((tag) => {
if ((wild && tag.startsWith(strippedFilter)) || tag === strippedFilter) {
allow = true;
}
});
}
return undefined;
}).filter((scenario) => scenario);
return allow;
};

const getFilteredScenarios = (scenarios) => scenarios.filter(filterScenarioByTag);

const populateHtmlIdentifiers = (feature) => {
feature.featureId = idSequence;
Expand Down

0 comments on commit ecbc504

Please sign in to comment.