From e8893bffe9df2e7beef9d924214095c6c73e0182 Mon Sep 17 00:00:00 2001 From: Mark Allison Date: Thu, 29 Feb 2024 12:29:12 +0000 Subject: [PATCH] Check for testIsolation on Examples --- features/suite_only_options.feature | 68 +++++++++++++++++++++++++++++ lib/browser-runtime.ts | 18 +++++++- 2 files changed, 84 insertions(+), 2 deletions(-) diff --git a/features/suite_only_options.feature b/features/suite_only_options.feature index 840ef350..9feb29b9 100644 --- a/features/suite_only_options.feature +++ b/features/suite_only_options.feature @@ -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 + """ diff --git a/lib/browser-runtime.ts b/lib/browser-runtime.ts index 4f672b61..150fd07a 100644 --- a/lib/browser-runtime.ts +++ b/lib/browser-runtime.ts @@ -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); + + 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 )