Skip to content

Commit

Permalink
Filter non-feature specs as if containing an empty set of tags
Browse files Browse the repository at this point in the history
This fixes #1116 [1].

[1] #1116
  • Loading branch information
badeball committed Nov 16, 2023
1 parent 5b17a41 commit 0b2702b
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 23 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ All notable changes to this project will be documented in this file.

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

- Avoid filtering non-feature specs upon tag expressions containing negating expressions, fixes [#1116](https://github.com/badeball/cypress-cucumber-preprocessor/issues/1116).

- Non-feature specs are filtered as if containing an empty set of tags.

## v19.1.0

- Add `BeforeAll(..)` and `AfterAll(..)` hooks, fixes [#758](https://github.com/badeball/cypress-cucumber-preprocessor/issues/758).
Expand Down
88 changes: 65 additions & 23 deletions features/tags/spec_filter.feature
Original file line number Diff line number Diff line change
@@ -1,31 +1,73 @@
Feature: filter spec

Scenario: 1 / 2 specs matching
Background:
Given additional preprocessor configuration
"""
{
"filterSpecs": true
}
"""
And a file named "cypress/e2e/a.feature" with:
"""
@foo
Feature: some feature
Scenario: first scenario
Given a step
"""
And a file named "cypress/e2e/b.feature" with:
"""
@bar
Feature: some other feature
Scenario: second scenario
Given a step
"""
And a file named "cypress/support/step_definitions/steps.js" with:
"""
const { Given } = require("@badeball/cypress-cucumber-preprocessor");
Given("a step", function() {})
"""
When I run cypress with "--env tags=@foo"
Then it passes
And it should appear to not have ran spec "b.feature"

Rule: it should filter features based on whether they contain a matching scenario

Scenario: 1 / 2 specs matching
Given a file named "cypress/e2e/a.feature" with:
"""
@foo
Feature: some feature
Scenario: first scenario
Given a step
"""
And a file named "cypress/e2e/b.feature" with:
"""
@bar
Feature: some other feature
Scenario: second scenario
Given a step
"""
And a file named "cypress/support/step_definitions/steps.js" with:
"""
const { Given } = require("@badeball/cypress-cucumber-preprocessor");
Given("a step", function() {})
"""
When I run cypress with "--env tags=@foo"
Then it passes
And it should appear to not have ran spec "b.feature"

Rule: non-feature specs should be filtered as if they have tags equalling the empty set

Background:
Given additional Cypress configuration
"""
{
"e2e": {
"specPattern": "**/*.{spec.js,feature}"
}
}
"""
And a file named "cypress/e2e/a.feature" with:
"""
@bar
Feature: some feature
Scenario: first scenario
Given a step
"""
And a file named "cypress/support/step_definitions/steps.js" with:
"""
const { Given } = require("@badeball/cypress-cucumber-preprocessor");
Given("a step", function() {})
"""
And a file named "cypress/e2e/b.spec.js" with:
"""
it("should work", () => {});
"""

Scenario: logical not
When I run cypress with "--env 'tags=not @foo'"
Then it passes
And it should appear to have ran spec "a.feature" and "b.spec.js"

Scenario: not logical not
When I run cypress with "--env tags=@bar"
Then it passes
And it should appear as if only a single test ran
4 changes: 4 additions & 0 deletions lib/add-cucumber-preprocessor-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@ export async function addCucumberPreprocessorPlugin(
const testFiles = getTestFiles(
config as unknown as ICypressConfiguration
).filter((testFile) => {
if (!testFile.endsWith(".feature")) {
return node.evaluate([]);
}

const content = fs.readFileSync(testFile).toString("utf-8");

const options = {
Expand Down

0 comments on commit 0b2702b

Please sign in to comment.