Skip to content

Commit 7a522f2

Browse files
committed
Add pickleStep to window.testState
This fixes #800.
1 parent 970991b commit 7a522f2

File tree

5 files changed

+25
-0
lines changed

5 files changed

+25
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ All notable changes to this project will be documented in this file.
66

77
- Start time and execution time is shown in HTML reports, fixes [#798](https://github.com/badeball/cypress-cucumber-preprocessor/issues/798).
88

9+
- Add current step information to `window.testState`, fixes [#800](https://github.com/badeball/cypress-cucumber-preprocessor/issues/800).
10+
911
## v12.0.1
1012

1113
- Allow overriding env using tags, fixes [#792](https://github.com/badeball/cypress-cucumber-preprocessor/issues/792).

features/test_state.feature

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,20 @@ Feature: window.testState
4949
"""
5050
When I run cypress
5151
Then it passes
52+
53+
Scenario: pickleStep
54+
Given a file named "cypress/e2e/a.feature" with:
55+
"""
56+
Feature: a feature name
57+
Scenario: a scenario name
58+
Given a step
59+
"""
60+
And a file named "cypress/e2e/a.js" with:
61+
"""
62+
const { Given } = require("@badeball/cypress-cucumber-preprocessor");
63+
Given("a step", function() {
64+
expect(testState.pickleStep.text).to.equal("a step");
65+
});
66+
"""
67+
When I run cypress
68+
Then it passes

lib/create-tests.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,8 @@ function createPickle(
407407

408408
for (const step of steps) {
409409
if (step.hook) {
410+
delete window.testState.pickleStep;
411+
410412
const hook = step.hook;
411413

412414
cy.then(() => {
@@ -455,6 +457,8 @@ function createPickle(
455457
remainingSteps.shift();
456458
});
457459
} else if (step.pickleStep) {
460+
window.testState.pickleStep = step.pickleStep;
461+
458462
const pickleStep = step.pickleStep;
459463

460464
const text = assertAndReturn(

lib/index.test-d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,3 +112,4 @@ After({ tags: "foo" }, function () {
112112
expectType<messages.GherkinDocument>(window.testState.gherkinDocument);
113113
expectType<messages.Pickle[]>(window.testState.pickles);
114114
expectType<messages.Pickle>(window.testState.pickle);
115+
expectType<messages.PickleStep | undefined>(window.testState.pickleStep);

lib/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ declare global {
1616
gherkinDocument: messages.GherkinDocument;
1717
pickles: messages.Pickle[];
1818
pickle: messages.Pickle;
19+
pickleStep?: messages.PickleStep;
1920
};
2021
}
2122
}

0 commit comments

Comments
 (0)