Skip to content

Commit

Permalink
fix: cucumberSupport fail if there is no examples in scenario (#183)
Browse files Browse the repository at this point in the history
* fix: cucumberSupport fail if there is no examples in scenario

* shorter
  • Loading branch information
LironEr authored Feb 22, 2024
1 parent 9f4b76f commit 633da67
Showing 1 changed file with 22 additions and 19 deletions.
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,
});
});

0 comments on commit 633da67

Please sign in to comment.