Skip to content

Commit

Permalink
Apply Feature configuration tags to suite
Browse files Browse the repository at this point in the history
  • Loading branch information
mallison committed Feb 20, 2024
1 parent 5e5580b commit bbcce85
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ lib/version.ts

# Temporary directory for test execution
tmp/
node_modules
31 changes: 31 additions & 0 deletions features/suite_only_options.feature
Original file line number Diff line number Diff line change
@@ -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
26 changes: 21 additions & 5 deletions lib/browser-runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -286,7 +287,17 @@ function createStepDescription({
}

function createFeature(context: CompositionContext, feature: messages.Feature) {
describe(feature.name || "<unamed feature>", () => {
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 || "<unamed feature>", suiteOptions, () => {
before(function () {
beforeHandler.call(this, context);
});
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 2 additions & 0 deletions lib/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"];

0 comments on commit bbcce85

Please sign in to comment.