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

fix: cucumberSupport fail if there is no examples in scenario #183

Merged
merged 2 commits into from
Feb 22, 2024
Merged
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
41 changes: 22 additions & 19 deletions cucumberSupport.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,28 @@ const consts = require('./lib/consts');
* Store the Cucumber source in the context for later usage
*/
Before(({ pickle, gherkinDocument }) => {
// (poor-man deep copy)
const gherkinDocumentWithSingleScenario = JSON.parse(JSON.stringify({
...gherkinDocument,
feature: {
...gherkinDocument.feature,
// keep only the scenario corresponding to the current pickle
children: gherkinDocument.feature.children.filter(f => !f.scenario || f.scenario.id === pickle.astNodeIds[0]),
},
}));
// (poor-man deep copy)
const gherkinDocumentWithSingleScenario = JSON.parse(
JSON.stringify({
...gherkinDocument,
feature: {
...gherkinDocument.feature,
// keep only the scenario corresponding to the current pickle
children: gherkinDocument.feature.children.filter((f) => !f.scenario || f.scenario.id === pickle.astNodeIds[0]),
},
})
);

// for scenario outlines, only keep the corresponding example
const scenario = gherkinDocumentWithSingleScenario.feature.children.filter(f => f.scenario)[0]?.scenario;
if (scenario.examples.length) {
const example = scenario.examples[0];
example.tableBody = example.tableBody.filter(row => row.id === pickle.astNodeIds[1]);
}
// for scenario outlines, only keep the corresponding example
const scenario = gherkinDocumentWithSingleScenario.feature.children.filter((f) => f.scenario)[0]?.scenario;

cy.addTestContext({
title: consts.cucumberStepsContextKey,
value: gherkinDocumentWithSingleScenario,
});
if (scenario?.examples?.length) {
const example = scenario.examples[0];
example.tableBody = example.tableBody.filter((row) => row.id === pickle.astNodeIds[1]);
}

cy.addTestContext({
title: consts.cucumberStepsContextKey,
value: gherkinDocumentWithSingleScenario,
});
});
Loading