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

Commit

Permalink
fix(Generator): prevent crashing when features are filtered out by tag (
Browse files Browse the repository at this point in the history
#45)

Co-authored-by: jkuester <[email protected]>
  • Loading branch information
jkuester and jkuester authored Apr 11, 2020
1 parent ff26fe4 commit 1a1ed66
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
12 changes: 11 additions & 1 deletion features/generate_report.feature
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ Feature: Report Generation
Then the title on the report will be "Pet Project - {current_date}"
And the project title on the sidebar will be "Pet Project"

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

Expand All @@ -117,6 +117,16 @@ Feature: Report Generation
| 'feeding' |
| '@feeding' |

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.

When a report is generated with the code "new Generator().generate(this.allFeaturesPath, null, '@cats')"
Then the report will contain 1 feature
And the report will contain 2 scenarios
And the report name on the sidebar will be '@cats'
And the sidebar will contain 1 feature button
And the sidebar will contain 2 scenario buttons

@exception
Scenario: Generating a report when no path is provided
When a report is generated with the code "new Generator().generate()"
Expand Down
23 changes: 11 additions & 12 deletions src/Generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,19 +190,18 @@ const populateTagStrings = (feature) => {
});
};

const includeFeature = (feature) => {
if (!tagFilter || feature.tags.includes(tagFilter)) {
return true;
}
feature.scenarios = getFilteredScenarios(feature.scenarios);
return feature.scenarios.length > 0;
};

// eslint-disable-next-line no-unused-vars
const parseFeatureFile = (item, nodePath, fsStats) => {
let feature = getFeatureFromFile(item.path);

if (tagFilter) {
const filteredScenarios = getFilteredScenarios(feature.scenarios);
if (filteredScenarios.length > 0) {
feature.scenarios = filteredScenarios;
} else {
feature = undefined;
}
}
if (feature) {
const feature = getFeatureFromFile(item.path);
if (includeFeature(feature)) {
item.feature = feature;
populateHtmlIdentifiers(feature);
populateTagStrings(feature);
Expand All @@ -211,7 +210,7 @@ const parseFeatureFile = (item, nodePath, fsStats) => {

const pruneFeatureFileTree = (featureFileTree) => {
featureFileTree.children = featureFileTree.children
.filter((child) => child.type === 'file' || pruneFeatureFileTree(child));
.filter((child) => (child.type === 'file' ? child.feature : pruneFeatureFileTree(child)));
return featureFileTree.children.length > 0;
};

Expand Down

0 comments on commit 1a1ed66

Please sign in to comment.