Skip to content

Commit

Permalink
feat(cypress-tags.js): scenario outlines with examples were not corre…
Browse files Browse the repository at this point in the history
…ctly filtered by tags (#609)

* fix(cypress-tags.js): scenario outlines with examples were not correctly filtered by tags

Now the script supports filtering examples of scenario outlines too. I have removed the optimization
that we should check scenario tags if there are any, because they do not work for negated tags (e.g.
`not @tag1`). Additionally, just checking the feature tag itself is also wrong, because a feature
with tag `@feature` having a scenario with tag `@scenario` would incorrectly run when we filter for
`not @scenario`. So the best is to leave the tag checking for "leaf nodes", i.e. scenarios or
examples. Also consider the corner case where a feature has no scenarios or scenario outlines at
all, i.e. again we would not run such a feature at all.

Fixes #196.

* fixup! fix(cypress-tags.js): scenario outlines with examples were not correctly filtered by tags
  • Loading branch information
rkrisztian authored Oct 4, 2021
1 parent 2789e0b commit f177e54
Showing 1 changed file with 20 additions and 19 deletions.
39 changes: 20 additions & 19 deletions cypress-tags.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,31 +71,32 @@ const paths = glob
})
.filter((pathName) => pathName.endsWith(".feature"));

const featuresToRun = [];

paths.forEach((featurePath) => {
const featuresToRun = paths.filter((featurePath) => {
const spec = `${fs.readFileSync(featurePath)}`;
const parsedFeature = new Parser().parse(spec);
const { feature } = new Parser().parse(spec);

if (!parsedFeature.feature) {
if (!feature) {
debug(`Feature: ${featurePath} is empty`);
return;
return false;
}

const featureTags = parsedFeature.feature.tags;
const featureShouldRun = shouldProceedCurrentStep(featureTags, envTags);
const taggedScenarioShouldRun = parsedFeature.feature.children.some(
(section) =>
section.tags &&
section.tags.length &&
shouldProceedCurrentStep(section.tags.concat(featureTags), envTags)
);
debug(
`Feature: ${featurePath}, featureShouldRun: ${featureShouldRun}, taggedScenarioShouldRun: ${taggedScenarioShouldRun}`
const shouldRun = feature.children.some((scenario) =>
scenario.examples
? scenario.examples.some((example) =>
shouldProceedCurrentStep(
[...example.tags, ...(scenario.tags || []), ...feature.tags],
envTags
)
)
: shouldProceedCurrentStep(
[...(scenario.tags || []), ...feature.tags],
envTags
)
);
if (featureShouldRun || taggedScenarioShouldRun) {
featuresToRun.push(featurePath);
}

debug(`Feature: ${featurePath}, shouldRun: ${shouldRun}`);

return shouldRun;
});

function getOsSpecificExecutable(command) {
Expand Down

0 comments on commit f177e54

Please sign in to comment.