Skip to content

Commit 97d3158

Browse files
committed
Allow overriding env
This fixes #792.
1 parent 9dc9938 commit 97d3158

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
All notable changes to this project will be documented in this file.
44

5+
## Unreleased
6+
7+
- Allow overriding env using tags, fixes [#792](https://github.com/badeball/cypress-cucumber-preprocessor/issues/792).
8+
59
## v12.0.0
610

711
Breaking changes:

features/issues/792.feature

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# https://github.com/badeball/cypress-cucumber-preprocessor/issues/792
2+
3+
Feature: overriding env
4+
Scenario: overriding env
5+
Given a file named "cypress/e2e/foo/bar.feature" with:
6+
"""
7+
@env(foo="bar")
8+
Feature: a feature
9+
Scenario: a scenario
10+
Given a step
11+
"""
12+
And a file named "cypress/e2e/foo/bar.js" with:
13+
"""
14+
const { Given } = require("@badeball/cypress-cucumber-preprocessor");
15+
Given("a step", () => {
16+
expect(Cypress.env("foo")).to.equal("bar");
17+
});
18+
"""
19+
When I run cypress
20+
Then it passes

lib/create-tests.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -373,14 +373,20 @@ function createPickle(
373373
remainingSteps: [...steps],
374374
};
375375

376-
const env = { [INTERNAL_PROPERTY_NAME]: internalProperties };
376+
const internalEnv = { [INTERNAL_PROPERTY_NAME]: internalProperties };
377377

378378
const suiteOptions = tags
379379
.filter(looksLikeOptions)
380380
.map(tagToCypressOptions)
381381
.reduce(Object.assign, {});
382382

383-
it(scenarioName, { env, ...suiteOptions }, function () {
383+
if (suiteOptions.env) {
384+
Object.assign(suiteOptions.env, internalEnv);
385+
} else {
386+
suiteOptions.env = internalEnv;
387+
}
388+
389+
it(scenarioName, suiteOptions, function () {
384390
const { remainingSteps, testCaseStartedId } = retrieveInternalProperties();
385391

386392
assignRegistry(registry);

0 commit comments

Comments
 (0)