Skip to content

Commit dcd5022

Browse files
committed
Correctly output messages on skip by method invocation
This fixes #1054 [1]. Why this requires a change to ./test-d/tsconfig.json, but not ./tsconfig.json is beyond me right now. Somehow, when building ./test-d, Cypress' Mocha-types takes precedence over Mocha's own types, but only in said project. [1] #1054
1 parent d9043da commit dcd5022

File tree

5 files changed

+112
-5
lines changed

5 files changed

+112
-5
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
- Add support for skipped steps, fixes [#1053](https://github.com/badeball/cypress-cucumber-preprocessor/issues/1053).
88

9+
- Handle use of `this.skip()` correctly in reports, fixes [#1054](https://github.com/badeball/cypress-cucumber-preprocessor/issues/1054).
10+
911
## v18.0.1
1012

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

features/reporters/json.feature

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ 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
143+
Scenario: skipped step through return value
144144
Given a file named "cypress/e2e/a.feature" with:
145145
"""
146146
Feature: a feature
@@ -162,6 +162,28 @@ Feature: JSON formatter
162162
Then it passes
163163
And there should be a JSON output similar to "fixtures/skipped-steps.json"
164164

165+
Scenario: skipped step through method invocation
166+
Given a file named "cypress/e2e/a.feature" with:
167+
"""
168+
Feature: a feature
169+
Scenario: a scenario
170+
Given a preceding step
171+
And a skipped step
172+
And a succeeding step
173+
"""
174+
And a file named "cypress/support/step_definitions/steps.js" with:
175+
"""
176+
const { Given } = require("@badeball/cypress-cucumber-preprocessor");
177+
Given("a preceding step", function () {})
178+
Given("a skipped step", function () {
179+
this.skip();
180+
});
181+
Given("a succeeding step", function () {})
182+
"""
183+
When I run cypress
184+
Then it passes
185+
And there should be a JSON output similar to "fixtures/skipped-steps.json"
186+
165187
Scenario: retried
166188
Given additional Cypress configuration
167189
"""

features/reporters/messages.feature

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ 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
143+
Scenario: skipped step through return value
144144
Given a file named "cypress/e2e/a.feature" with:
145145
"""
146146
Feature: a feature
@@ -162,6 +162,28 @@ Feature: messages report
162162
Then it passes
163163
And there should be a messages similar to "fixtures/skipped-steps.ndjson"
164164

165+
Scenario: skipped step through method invocation
166+
Given a file named "cypress/e2e/a.feature" with:
167+
"""
168+
Feature: a feature
169+
Scenario: a scenario
170+
Given a preceding step
171+
And a skipped step
172+
And a succeeding step
173+
"""
174+
And a file named "cypress/support/step_definitions/steps.js" with:
175+
"""
176+
const { Given } = require("@badeball/cypress-cucumber-preprocessor");
177+
Given("a preceding step", function () {})
178+
Given("a skipped step", function () {
179+
this.skip();
180+
});
181+
Given("a succeeding step", function () {})
182+
"""
183+
When I run cypress
184+
Then it passes
185+
And there should be a messages similar to "fixtures/skipped-steps.ndjson"
186+
165187
Scenario: retried
166188
Given additional Cypress configuration
167189
"""

lib/browser-runtime.ts

Lines changed: 62 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -823,8 +823,13 @@ function afterEachHandler(this: Mocha.Context, context: CompositionContext) {
823823
timestamp: endTimestamp,
824824
});
825825
}
826-
} else {
827-
for (const skippedStep of remainingSteps) {
826+
} else if (this.currentTest?.state === "pending") {
827+
if (currentStepStartedAt) {
828+
const skippedStep = assertAndReturn(
829+
remainingSteps.shift(),
830+
"Expected there to be a remaining step"
831+
);
832+
828833
const hookIdOrPickleStepId = assertAndReturn(
829834
skippedStep.hook?.id ?? skippedStep.pickleStep?.id,
830835
"Expected a step to either be a hook or a pickleStep"
@@ -836,6 +841,61 @@ function afterEachHandler(this: Mocha.Context, context: CompositionContext) {
836841
hookIdOrPickleStepId,
837842
});
838843

844+
taskTestStepFinished(context, {
845+
testStepId,
846+
testCaseStartedId,
847+
testStepResult: {
848+
status: messages.TestStepResultStatus.SKIPPED,
849+
duration: duration(currentStepStartedAt, endTimestamp),
850+
},
851+
timestamp: endTimestamp,
852+
});
853+
}
854+
855+
for (const remainingStep of remainingSteps) {
856+
const hookIdOrPickleStepId = assertAndReturn(
857+
remainingStep.hook?.id ?? remainingStep.pickleStep?.id,
858+
"Expected a step to either be a hook or a pickleStep"
859+
);
860+
861+
const testStepId = getTestStepId({
862+
context,
863+
pickleId: pickle.id,
864+
hookIdOrPickleStepId,
865+
});
866+
867+
taskTestStepStarted(context, {
868+
testStepId,
869+
testCaseStartedId,
870+
timestamp: endTimestamp,
871+
});
872+
873+
taskTestStepFinished(context, {
874+
testStepId,
875+
testCaseStartedId,
876+
testStepResult: {
877+
status: messages.TestStepResultStatus.SKIPPED,
878+
duration: {
879+
seconds: 0,
880+
nanos: 0,
881+
},
882+
},
883+
timestamp: endTimestamp,
884+
});
885+
}
886+
} else {
887+
for (const remainingStep of remainingSteps) {
888+
const hookIdOrPickleStepId = assertAndReturn(
889+
remainingStep.hook?.id ?? remainingStep.pickleStep?.id,
890+
"Expected a step to either be a hook or a pickleStep"
891+
);
892+
893+
const testStepId = getTestStepId({
894+
context,
895+
pickleId: pickle.id,
896+
hookIdOrPickleStepId,
897+
});
898+
839899
taskTestStepStarted(context, {
840900
testStepId,
841901
testCaseStartedId,

test-d/tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
{
22
"extends": "../tsconfig.json",
33
"compilerOptions": {
4-
"noEmit": true
4+
"noEmit": true,
5+
"types": ["node", "mocha", "cypress"],
56
},
67
"include": [
78
"*.test-d.ts",

0 commit comments

Comments
 (0)