Skip to content

Commit 0b2702b

Browse files
committed
Filter non-feature specs as if containing an empty set of tags
This fixes #1116 [1]. [1] #1116
1 parent 5b17a41 commit 0b2702b

File tree

3 files changed

+73
-23
lines changed

3 files changed

+73
-23
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ All notable changes to this project will be documented in this file.
66

77
- Mock and imitate Cypress globals during diagnostics / dry run, fixes [#1120](https://github.com/badeball/cypress-cucumber-preprocessor/issues/1120).
88

9+
- Avoid filtering non-feature specs upon tag expressions containing negating expressions, fixes [#1116](https://github.com/badeball/cypress-cucumber-preprocessor/issues/1116).
10+
11+
- Non-feature specs are filtered as if containing an empty set of tags.
12+
913
## v19.1.0
1014

1115
- Add `BeforeAll(..)` and `AfterAll(..)` hooks, fixes [#758](https://github.com/badeball/cypress-cucumber-preprocessor/issues/758).

features/tags/spec_filter.feature

Lines changed: 65 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,73 @@
11
Feature: filter spec
22

3-
Scenario: 1 / 2 specs matching
3+
Background:
44
Given additional preprocessor configuration
55
"""
66
{
77
"filterSpecs": true
88
}
99
"""
10-
And a file named "cypress/e2e/a.feature" with:
11-
"""
12-
@foo
13-
Feature: some feature
14-
Scenario: first scenario
15-
Given a step
16-
"""
17-
And a file named "cypress/e2e/b.feature" with:
18-
"""
19-
@bar
20-
Feature: some other feature
21-
Scenario: second scenario
22-
Given a step
23-
"""
24-
And a file named "cypress/support/step_definitions/steps.js" with:
25-
"""
26-
const { Given } = require("@badeball/cypress-cucumber-preprocessor");
27-
Given("a step", function() {})
28-
"""
29-
When I run cypress with "--env tags=@foo"
30-
Then it passes
31-
And it should appear to not have ran spec "b.feature"
10+
11+
Rule: it should filter features based on whether they contain a matching scenario
12+
13+
Scenario: 1 / 2 specs matching
14+
Given a file named "cypress/e2e/a.feature" with:
15+
"""
16+
@foo
17+
Feature: some feature
18+
Scenario: first scenario
19+
Given a step
20+
"""
21+
And a file named "cypress/e2e/b.feature" with:
22+
"""
23+
@bar
24+
Feature: some other feature
25+
Scenario: second scenario
26+
Given a step
27+
"""
28+
And a file named "cypress/support/step_definitions/steps.js" with:
29+
"""
30+
const { Given } = require("@badeball/cypress-cucumber-preprocessor");
31+
Given("a step", function() {})
32+
"""
33+
When I run cypress with "--env tags=@foo"
34+
Then it passes
35+
And it should appear to not have ran spec "b.feature"
36+
37+
Rule: non-feature specs should be filtered as if they have tags equalling the empty set
38+
39+
Background:
40+
Given additional Cypress configuration
41+
"""
42+
{
43+
"e2e": {
44+
"specPattern": "**/*.{spec.js,feature}"
45+
}
46+
}
47+
"""
48+
And a file named "cypress/e2e/a.feature" with:
49+
"""
50+
@bar
51+
Feature: some feature
52+
Scenario: first scenario
53+
Given a step
54+
"""
55+
And a file named "cypress/support/step_definitions/steps.js" with:
56+
"""
57+
const { Given } = require("@badeball/cypress-cucumber-preprocessor");
58+
Given("a step", function() {})
59+
"""
60+
And a file named "cypress/e2e/b.spec.js" with:
61+
"""
62+
it("should work", () => {});
63+
"""
64+
65+
Scenario: logical not
66+
When I run cypress with "--env 'tags=not @foo'"
67+
Then it passes
68+
And it should appear to have ran spec "a.feature" and "b.spec.js"
69+
70+
Scenario: not logical not
71+
When I run cypress with "--env tags=@bar"
72+
Then it passes
73+
And it should appear as if only a single test ran

lib/add-cucumber-preprocessor-plugin.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,10 @@ export async function addCucumberPreprocessorPlugin(
136136
const testFiles = getTestFiles(
137137
config as unknown as ICypressConfiguration
138138
).filter((testFile) => {
139+
if (!testFile.endsWith(".feature")) {
140+
return node.evaluate([]);
141+
}
142+
139143
const content = fs.readFileSync(testFile).toString("utf-8");
140144

141145
const options = {

0 commit comments

Comments
 (0)