Skip to content

Commit d9043da

Browse files
committed
Add support for skipped steps
This fixes #1053 [1]. [1] #1053
1 parent 2bd954c commit d9043da

File tree

8 files changed

+225
-11
lines changed

8 files changed

+225
-11
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+
- Add support for skipped steps, fixes [#1053](https://github.com/badeball/cypress-cucumber-preprocessor/issues/1053).
8+
59
## v18.0.1
610

711
- Give each TestStep (from `@cucumber/messages`) a unique ID, fixes [#1034](https://github.com/badeball/cypress-cucumber-preprocessor/issues/1034).

docs/cucumber-basics.md

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ Custom parameter types can be registered using `defineParameterType()`. They sha
4646

4747
# Pending steps
4848

49-
You can return `"pending"` from a step defintion or a chain to mark a step as pending. This will halt the execution and Cypress will report the test as "skipped".
49+
You can return `"pending"` from a step defintion or a chain to mark a step as pending. This will halt the execution and Cypress will report the test as "skipped". This is generally used for marking steps as "unimplemented" and allows you to commit unfinished work without breaking the test suite.
5050

5151
```ts
5252
import { When } from "@badeball/cypress-cucumber-preprocessor";
@@ -66,6 +66,28 @@ When("a step", () => {
6666
});
6767
```
6868

69+
# Skipped steps
70+
71+
You can return `"skipped"` from a step defintion or a chain to mark a step as pending. This will halt the execution and Cypress will report the test as "skipped". This however is generally used for conditionally short circuiting a test.
72+
73+
```ts
74+
import { When } from "@badeball/cypress-cucumber-preprocessor";
75+
76+
When("a step", () => {
77+
return "skipped";
78+
});
79+
```
80+
81+
```ts
82+
import { When } from "@badeball/cypress-cucumber-preprocessor";
83+
84+
When("a step", () => {
85+
cy.then(() => {
86+
return "skipped";
87+
});
88+
});
89+
```
90+
6991
# Nested steps
7092

7193
You can invoke other steps from a step using `Step()`, as shown below.
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
[
2+
{
3+
"description": "",
4+
"elements": [
5+
{
6+
"description": "",
7+
"id": "a-feature;a-scenario",
8+
"keyword": "Scenario",
9+
"line": 2,
10+
"name": "a scenario",
11+
"steps": [
12+
{
13+
"arguments": [],
14+
"keyword": "Given ",
15+
"line": 3,
16+
"name": "a preceding step",
17+
"match": {
18+
"location": "not available:0"
19+
},
20+
"result": {
21+
"status": "passed",
22+
"duration": 0
23+
}
24+
},
25+
{
26+
"arguments": [],
27+
"keyword": "And ",
28+
"line": 4,
29+
"name": "a skipped step",
30+
"match": {
31+
"location": "not available:0"
32+
},
33+
"result": {
34+
"status": "skipped",
35+
"duration": 0
36+
}
37+
},
38+
{
39+
"arguments": [],
40+
"keyword": "And ",
41+
"line": 5,
42+
"name": "a succeeding step",
43+
"match": {
44+
"location": "not available:0"
45+
},
46+
"result": {
47+
"status": "skipped",
48+
"duration": 0
49+
}
50+
}
51+
],
52+
"tags": [],
53+
"type": "scenario"
54+
}
55+
],
56+
"id": "a-feature",
57+
"line": 1,
58+
"keyword": "Feature",
59+
"name": "a feature",
60+
"tags": [],
61+
"uri": "cypress/e2e/a.feature"
62+
}
63+
]
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{"testRunStarted":{"timestamp":{"seconds":0,"nanos":0}}}
2+
{"source":{"data":"Feature: a feature\n Scenario: a scenario\n Given a preceding step\n And a skipped step\n And a succeeding step","uri":"cypress/e2e/a.feature","mediaType":"text/x.cucumber.gherkin+plain"}}
3+
{"gherkinDocument":{"feature":{"tags":[],"location":{"line":1,"column":1},"language":"en","keyword":"Feature","name":"a feature","description":"","children":[{"scenario":{"id":"id","tags":[],"location":{"line":2,"column":3},"keyword":"Scenario","name":"a scenario","description":"","steps":[{"id":"id","location":{"line":3,"column":5},"keyword":"Given ","keywordType":"Context","text":"a preceding step"},{"id":"id","location":{"line":4,"column":5},"keyword":"And ","keywordType":"Conjunction","text":"a skipped step"},{"id":"id","location":{"line":5,"column":5},"keyword":"And ","keywordType":"Conjunction","text":"a succeeding step"}],"examples":[]}}]},"comments":[],"uri":"cypress/e2e/a.feature"}}
4+
{"pickle":{"id":"id","uri":"cypress/e2e/a.feature","astNodeIds":["id"],"tags":[],"name":"a scenario","language":"en","steps":[{"id":"id","text":"a preceding step","type":"Context","astNodeIds":["id"]},{"id":"id","text":"a skipped step","type":"Context","astNodeIds":["id"]},{"id":"id","text":"a succeeding step","type":"Context","astNodeIds":["id"]}]}}
5+
{"stepDefinition":{"id":"id","pattern":{"type":"CUCUMBER_EXPRESSION","source":"a preceding step"},"sourceReference":{"uri":"not available","location":{"line":0}}}}
6+
{"stepDefinition":{"id":"id","pattern":{"type":"CUCUMBER_EXPRESSION","source":"a skipped step"},"sourceReference":{"uri":"not available","location":{"line":0}}}}
7+
{"stepDefinition":{"id":"id","pattern":{"type":"CUCUMBER_EXPRESSION","source":"a succeeding step"},"sourceReference":{"uri":"not available","location":{"line":0}}}}
8+
{"testCase":{"id":"id","pickleId":"id","testSteps":[{"id":"id","pickleStepId":"id","stepDefinitionIds":["id"]},{"id":"id","pickleStepId":"id","stepDefinitionIds":["id"]},{"id":"id","pickleStepId":"id","stepDefinitionIds":["id"]}]}}
9+
{"testCaseStarted":{"id":"id","testCaseId":"id","attempt":0,"timestamp":{"seconds":0,"nanos":0}}}
10+
{"testStepStarted":{"testStepId":"id","testCaseStartedId":"id","timestamp":{"seconds":0,"nanos":0}}}
11+
{"testStepFinished":{"testStepId":"id","testCaseStartedId":"id","testStepResult":{"status":"PASSED","duration":0},"timestamp":{"seconds":0,"nanos":0}}}
12+
{"testStepStarted":{"testStepId":"id","testCaseStartedId":"id","timestamp":{"seconds":0,"nanos":0}}}
13+
{"testStepFinished":{"testStepId":"id","testCaseStartedId":"id","testStepResult":{"status":"SKIPPED","duration":0},"timestamp":{"seconds":0,"nanos":0}}}
14+
{"testStepStarted":{"testStepId":"id","testCaseStartedId":"id","timestamp":{"seconds":0,"nanos":0}}}
15+
{"testStepFinished":{"testStepId":"id","testCaseStartedId":"id","testStepResult":{"status":"SKIPPED","duration":0},"timestamp":{"seconds":0,"nanos":0}}}
16+
{"testCaseFinished":{"testCaseStartedId":"id","timestamp":{"seconds":0,"nanos":0},"willBeRetried":false}}
17+
{"testRunFinished":{"timestamp":{"seconds":0,"nanos":0}}}

features/reporters/json.feature

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,28 @@ Feature: JSON formatter
140140
Then it passes
141141
And there should be a JSON output similar to "fixtures/pending-steps.json"
142142

143+
Scenario: skipped step
144+
Given a file named "cypress/e2e/a.feature" with:
145+
"""
146+
Feature: a feature
147+
Scenario: a scenario
148+
Given a preceding step
149+
And a skipped step
150+
And a succeeding step
151+
"""
152+
And a file named "cypress/support/step_definitions/steps.js" with:
153+
"""
154+
const { Given } = require("@badeball/cypress-cucumber-preprocessor");
155+
Given("a preceding step", function () {})
156+
Given("a skipped step", function () {
157+
return "skipped";
158+
});
159+
Given("a succeeding step", function () {})
160+
"""
161+
When I run cypress
162+
Then it passes
163+
And there should be a JSON output similar to "fixtures/skipped-steps.json"
164+
143165
Scenario: retried
144166
Given additional Cypress configuration
145167
"""

features/reporters/messages.feature

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,28 @@ Feature: messages report
140140
Then it passes
141141
And there should be a messages similar to "fixtures/pending-steps.ndjson"
142142

143+
Scenario: skipped step
144+
Given a file named "cypress/e2e/a.feature" with:
145+
"""
146+
Feature: a feature
147+
Scenario: a scenario
148+
Given a preceding step
149+
And a skipped step
150+
And a succeeding step
151+
"""
152+
And a file named "cypress/support/step_definitions/steps.js" with:
153+
"""
154+
const { Given } = require("@badeball/cypress-cucumber-preprocessor");
155+
Given("a preceding step", function () {})
156+
Given("a skipped step", function () {
157+
return "skipped";
158+
});
159+
Given("a succeeding step", function () {})
160+
"""
161+
When I run cypress
162+
Then it passes
163+
And there should be a messages similar to "fixtures/skipped-steps.ndjson"
164+
143165
Scenario: retried
144166
Given additional Cypress configuration
145167
"""

features/skipped_steps.feature

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
Feature: skipped steps
2+
Background:
3+
Given a file named "cypress/e2e/a.feature" with:
4+
"""
5+
Feature: a feature
6+
Scenario: a scenario
7+
Given a skipped step
8+
"""
9+
And a file named "cypress/support/step_definitions/steps.js" with:
10+
"""
11+
const { Given } = require("@badeball/cypress-cucumber-preprocessor")
12+
Given("a skipped step", function() {
13+
return "skipped"
14+
})
15+
"""
16+
17+
Rule: skipped steps make the test skipped
18+
19+
Scenario: basic skipped step
20+
When I run cypress
21+
Then it passes
22+
And it should appear to have skipped the scenario "a scenario"
23+
24+
Scenario: with step hooks returning strings
25+
Given a file named "cypress/support/step_definitions/hooks.js" with:
26+
"""
27+
const { BeforeStep, AfterStep } = require("@badeball/cypress-cucumber-preprocessor")
28+
BeforeStep(function() {
29+
return "foobar"
30+
})
31+
AfterStep(function() {
32+
return "foobar"
33+
})
34+
"""
35+
When I run cypress
36+
Then it passes
37+
And it should appear to have skipped the scenario "a scenario"
38+
39+
Scenario: with step hooks returning chains
40+
Given a file named "cypress/support/step_definitions/hooks.js" with:
41+
"""
42+
const { BeforeStep, AfterStep } = require("@badeball/cypress-cucumber-preprocessor")
43+
BeforeStep(function() {
44+
return cy.wrap("foobar")
45+
})
46+
AfterStep(function() {
47+
return cy.wrap("foobar")
48+
})
49+
"""
50+
When I run cypress
51+
Then it passes
52+
And it should appear to have skipped the scenario "a scenario"

lib/browser-runtime.ts

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -589,16 +589,28 @@ function createPickle(context: CompositionContext, pickle: messages.Pickle) {
589589
.then(({ start, result }) => {
590590
const end = createTimestamp();
591591

592-
if (result === "pending") {
593-
taskTestStepFinished(context, {
594-
testStepId,
595-
testCaseStartedId,
596-
testStepResult: {
597-
status: messages.TestStepResultStatus.PENDING,
598-
duration: duration(start, end),
599-
},
600-
timestamp: end,
601-
});
592+
if (result === "pending" || result === "skipped") {
593+
if (result === "pending") {
594+
taskTestStepFinished(context, {
595+
testStepId,
596+
testCaseStartedId,
597+
testStepResult: {
598+
status: messages.TestStepResultStatus.PENDING,
599+
duration: duration(start, end),
600+
},
601+
timestamp: end,
602+
});
603+
} else {
604+
taskTestStepFinished(context, {
605+
testStepId,
606+
testCaseStartedId,
607+
testStepResult: {
608+
status: messages.TestStepResultStatus.SKIPPED,
609+
duration: duration(start, end),
610+
},
611+
timestamp: end,
612+
});
613+
}
602614

603615
remainingSteps.shift();
604616

0 commit comments

Comments
 (0)