diff --git a/.gitignore b/.gitignore index bd55b46a..c3c9e730 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ lib/version.ts # Temporary directory for test execution tmp/ +node_modules diff --git a/features/suite_only_options.feature b/features/suite_only_options.feature new file mode 100644 index 00000000..e1725cc8 --- /dev/null +++ b/features/suite_only_options.feature @@ -0,0 +1,31 @@ +Feature: suite only options + Scenario: suite specific test isolation + Given additional Cypress configuration + """ + { + "e2e": { + "testIsolation": true + } + } + """ + And a file named "cypress/e2e/a.feature" with: + """ + @testIsolation(false) + Feature: a feature + Scenario: a scenario + Given a step + Scenario: another scenario + Then another step + """ + 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') + }); + Given("another step", () => { + cy.contains("Hello world").should("exist"); + }); + """ + When I run cypress + Then it passes diff --git a/lib/browser-runtime.ts b/lib/browser-runtime.ts index 3bf2a4d6..e79778bd 100644 --- a/lib/browser-runtime.ts +++ b/lib/browser-runtime.ts @@ -34,19 +34,20 @@ import { HOOK_FAILURE_EXPR, INTERNAL_SPEC_PROPERTIES, INTERNAL_SUITE_PROPERTIES, + SUITE_CONFIGURATION_OPTIONS, } from "./constants"; import { ITaskSpecEnvelopes, - ITaskTestCaseStarted, ITaskTestCaseFinished, - ITaskTestStepStarted, + ITaskTestCaseStarted, ITaskTestStepFinished, + ITaskTestStepStarted, TASK_SPEC_ENVELOPES, - TASK_TEST_CASE_STARTED, TASK_TEST_CASE_FINISHED, - TASK_TEST_STEP_STARTED, + TASK_TEST_CASE_STARTED, TASK_TEST_STEP_FINISHED, + TASK_TEST_STEP_STARTED, } from "./cypress-task-definitions"; import { notNull } from "./helpers/type-guards"; @@ -286,7 +287,17 @@ function createStepDescription({ } function createFeature(context: CompositionContext, feature: messages.Feature) { - describe(feature.name || "", () => { + const suiteOptions = collectTagNames(feature.tags) + .filter(looksLikeOptions) + .map(tagToCypressOptions) + .filter((tag) => { + return Object.keys(tag).every((key) => + SUITE_CONFIGURATION_OPTIONS.includes(key) + ); + }) + .reduce(Object.assign, {}); + + describe(feature.name || "", suiteOptions, () => { before(function () { beforeHandler.call(this, context); }); @@ -423,6 +434,11 @@ function createPickle(context: CompositionContext, pickle: messages.Pickle) { const suiteOptions = tags .filter(looksLikeOptions) .map(tagToCypressOptions) + .filter((tag) => { + Object.keys(tag).every((key) => { + return !SUITE_CONFIGURATION_OPTIONS.includes(key); + }); + }) .reduce(Object.assign, {}); if (suiteOptions.env) { diff --git a/lib/constants.ts b/lib/constants.ts index e6beb50c..33777762 100644 --- a/lib/constants.ts +++ b/lib/constants.ts @@ -7,3 +7,5 @@ export const INTERNAL_SUITE_PROPERTIES = INTERNAL_PROPERTY_NAME + "_suite"; export const HOOK_FAILURE_EXPR = /Because this error occurred during a `[^`]+` hook we are skipping all of the remaining tests\./; + +export const SUITE_CONFIGURATION_OPTIONS = ["testIsolation"]; \ No newline at end of file