|
1 | 1 | const { createTestFromScenario } = require("./createTestFromScenario"); |
| 2 | +const { shouldProceedCurrentStep, getEnvTags } = require("./tagsHelper"); |
2 | 3 |
|
3 | 4 | const createTestsFromFeature = parsedFeature => { |
| 5 | + const featureTags = parsedFeature.feature.tags; |
| 6 | + const hasEnvTags = !!getEnvTags(); |
| 7 | + const hasFeatureTags = featureTags && featureTags.length > 0; |
| 8 | + |
| 9 | + let featureShouldRun = true; |
| 10 | + if (hasEnvTags) { |
| 11 | + if (hasFeatureTags) { |
| 12 | + featureShouldRun = shouldProceedCurrentStep(featureTags); |
| 13 | + } else { |
| 14 | + featureShouldRun = false; |
| 15 | + } |
| 16 | + } |
| 17 | + |
| 18 | + const taggedScenarioShouldRun = parsedFeature.feature.children.some( |
| 19 | + section => |
| 20 | + section.tags && |
| 21 | + section.tags.length && |
| 22 | + shouldProceedCurrentStep(section.tags) |
| 23 | + ); |
| 24 | + |
4 | 25 | // eslint-disable-next-line prefer-arrow-callback |
5 | 26 | describe(parsedFeature.feature.name, function() { |
6 | | - const backgroundSection = parsedFeature.feature.children.find( |
7 | | - section => section.type === "Background" |
8 | | - ); |
9 | | - const otherSections = parsedFeature.feature.children.filter( |
10 | | - section => section.type !== "Background" |
11 | | - ); |
12 | | - otherSections.forEach(section => { |
13 | | - createTestFromScenario(section, backgroundSection); |
14 | | - }); |
| 27 | + if (featureShouldRun || taggedScenarioShouldRun) { |
| 28 | + const backgroundSection = parsedFeature.feature.children.find( |
| 29 | + section => section.type === "Background" |
| 30 | + ); |
| 31 | + const otherSections = parsedFeature.feature.children.filter( |
| 32 | + section => section.type !== "Background" |
| 33 | + ); |
| 34 | + otherSections.forEach(section => { |
| 35 | + const scenarioHasTags = section.tags.length > 0; |
| 36 | + const shouldRun = |
| 37 | + hasEnvTags && scenarioHasTags |
| 38 | + ? shouldProceedCurrentStep(section.tags.concat(featureTags)) // concat handles inheritance of tags from feature |
| 39 | + : featureShouldRun; |
| 40 | + if (shouldRun) { |
| 41 | + createTestFromScenario(section, backgroundSection); |
| 42 | + } |
| 43 | + }); |
| 44 | + } |
15 | 45 | }); |
16 | 46 | }; |
17 | 47 |
|
|
0 commit comments