Skip to content

Commit

Permalink
Check for testIsolation on Examples
Browse files Browse the repository at this point in the history
  • Loading branch information
mallison committed Feb 29, 2024
1 parent 99e9df3 commit e8893bf
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 2 deletions.
68 changes: 68 additions & 0 deletions features/suite_only_options.feature
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,71 @@ Feature: suite only options
"""
Tag @testIsolation(false) can only be used on a Feature or a Rule
"""

Scenario: Configuring testIsolation on a Scenario Outline fails
Given additional Cypress configuration
"""
{
"e2e": {
"testIsolation": true
}
}
"""
And a file named "cypress/e2e/a.feature" with:
"""
Feature: a feature
@testIsolation(false)
Scenario Outline: a scenario
Given a step
Examples:
| foo |
| bar |
"""
And a file named "cypress/support/step_definitions/steps.js" with:
"""
const { Given, Then } = require("@badeball/cypress-cucumber-preprocessor");
Given("a step", () => {
cy.get("body").invoke('html', 'Hello world')
});
"""
When I run cypress
Then it fails
And the output should contain
"""
Tag @testIsolation(false) can only be used on a Feature or a Rule
"""

Scenario: Configuring testIsolation on Examples fails
Given additional Cypress configuration
"""
{
"e2e": {
"testIsolation": true
}
}
"""
And a file named "cypress/e2e/a.feature" with:
"""
Feature: a feature
Scenario Outline: a scenario
Given a step
@testIsolation(false)
Examples:
| foo |
| bar |
"""
And a file named "cypress/support/step_definitions/steps.js" with:
"""
const { Given, Then } = require("@badeball/cypress-cucumber-preprocessor");
Given("a step", () => {
cy.get("body").invoke('html', 'Hello world')
});
"""
When I run cypress
Then it fails
And the output should contain
"""
Tag @testIsolation(false) can only be used on a Feature or a Rule
"""
18 changes: 16 additions & 2 deletions lib/browser-runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -451,10 +451,24 @@ function createPickle(context: CompositionContext, pickle: messages.Pickle) {
`Expected to find scenario associated with id = ${pickle.astNodeIds?.[0]}`
);

if ("tags" in scenario) {
for (const tag of scenario.tags) {
if ("tags" in scenario && 'id' in scenario) {
const tagsDefinedOnThisScenarioTagNameAstIdMap = scenario.tags.reduce((acc, tag) => {
acc[tag.name] = tag.id;
return acc;
}, {} as Record<string, string>);

if ('examples' in scenario) {
for (const example of scenario.examples) {
example.tags.forEach((tag) => {
tagsDefinedOnThisScenarioTagNameAstIdMap[tag.name] = tag.id;
});
}
}

for (const tag of pickle.tags) {
if (
looksLikeOptions(tag.name) &&
tagsDefinedOnThisScenarioTagNameAstIdMap[tag.name] === tag.astNodeId &&
Object.keys(tagToCypressOptions(tag.name)).every(
(key) => key === TEST_ISOLATION_CONFIGURATION_OPTION
)
Expand Down

0 comments on commit e8893bf

Please sign in to comment.