Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support for background and feature hooks #130

Merged
merged 1 commit into from
Jul 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions lib/collect-jsons.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ module.exports = function collectJSONS(options) {
files.map(file => {
// Cucumber json can be empty, it's likely being created by another process (#47)
const data = fs.readFileSync(file).toString() || "[]";

JSON.parse(data).map(json => {
if (options.metadata && !json.metadata) {
json.metadata = options.metadata;
Expand All @@ -38,6 +39,27 @@ module.exports = function collectJSONS(options) {
}
}, json);
}

// Only check the feature hooks if there are elements (fail safe)
const {elements} = json;

if (elements) {
const scenarios = elements.map(scenario => {
const {before, after} = scenario;

if (before) {
scenario.steps = parseFeatureHooks(before, 'Before').concat(scenario.steps);
}
if (after) {
scenario.steps = scenario.steps.concat(parseFeatureHooks(after, 'After'));
}

return scenario
})

json.elements = scenarios
}

jsonOutput.push(json)
});
});
Expand All @@ -54,3 +76,38 @@ module.exports = function collectJSONS(options) {
console.log(chalk.yellow(`WARNING: No JSON files found in '${options.jsonDir}'. NO REPORT CAN BE CREATED!`));
return [];
};

/**
* Add the feature hooks to the steps so the report will pick them up properly
*
* @param {object} data
* @param {string} keyword
* @returns {{
* arguments: array,
* keyword: string,
* name: string,
* result: {
* status: string,
* },
* line: string,
* match: {
* location: string
* },
* embeddings: []
* }}
*/
function parseFeatureHooks(data, keyword) {
return data.map(step => {
const match = step.match && step.match.location ? step.match : {location: 'can not be determined'};

return {
arguments: step.arguments || [],
keyword: keyword,
name: 'Hook',
result: step.result,
line: '',
match,
embeddings: step.embeddings || []
}
})
}
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@
"uuid": "^3.4.0"
},
"devDependencies": {
"coveralls": "^3.0.9",
"coveralls": "^3.1.0",
"istanbul": "^0.4.5",
"jasmine": "^3.5.0",
"np": "^6.0.0"
"np": "^6.3.2"
}
}
2 changes: 1 addition & 1 deletion templates/components/scenarios.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<% } %>
</div>

<h2>Scenario: <small><%= scenario.name %></small></h2>
<h2><%= scenario.keyword %>: <small><%= scenario.name %></small></h2>

<ul class="nav navbar-right panel_toolbox">
<li>
Expand Down
Loading