Skip to content

Commit 3c12732

Browse files
committed
Make usage formatter tests deterministic
This is done by placing strategic waits among the tests, to ensure the desired output with respect to sorting. The problem of deterministic sorting was something I originally thought best could best be solved by introducing a flag in the usage formatter in cucumber-js [1]. However, a cuople of strategic waits was much simpler than I thought it would be and it's sufficiently deterministic. I've run the usage formatter tests a thousand times without any flake. This patch has the fortunate effect of removing the need for patch-package altogether, which has been troublesome [2]. [1] cucumber/cucumber-js#2633 [2] #1255
1 parent ccb9fd1 commit 3c12732

File tree

5 files changed

+44
-64
lines changed

5 files changed

+44
-64
lines changed

CHANGELOG.md

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

1111
- This is similar to how steps themselves can also return the above mentioned literals. This is in line with how cucumber-js behaves.
1212

13+
- Remove use of patch-package in development mode, which was causing some issues, closes [#1255](https://github.com/badeball/cypress-cucumber-preprocessor/pull/1255).
14+
1315
## v23.2.1
1416

1517
- Determine interactive mode correctly, fixes [#1323](https://github.com/badeball/cypress-cucumber-preprocessor/issues/1323).

features/reporters/usage.feature

Lines changed: 41 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -122,18 +122,24 @@ Feature: usage report
122122
And a file named "cypress/support/step_definitions/steps.js" with:
123123
"""
124124
const { Given } = require("@badeball/cypress-cucumber-preprocessor");
125-
Given("a step", function() {});
125+
let count = 0;
126+
Given("a step", function() {
127+
// This makes sure a.feature:3 takes longest and is printed top-post.
128+
if (count++ === 0) {
129+
cy.wait(1000);
130+
}
131+
});
126132
"""
127133
When I run cypress
128134
Then the output should contain a usage report
129135
"""
130-
┌────────────────┬──────────┬─────────────────────────────────────────────┐
131-
│ Pattern / Text │ Duration │ Location │
132-
├────────────────┼──────────┼─────────────────────────────────────────────┤
133-
│ a step │ 0.00ms │ cypress/support/step_definitions/steps.js:2
134-
│ a step │ 0.00ms │ cypress/e2e/a.feature:3 │
135-
│ a step │ 0.00ms │ cypress/e2e/a.feature:4 │
136-
└────────────────┴──────────┴─────────────────────────────────────────────┘
136+
┌────────────────┬──────────┬─────────────────────────────────────────────┐
137+
│ Pattern / Text │ Duration │ Location │
138+
├────────────────┼──────────┼─────────────────────────────────────────────┤
139+
│ a step │ 0.00ms │ cypress/support/step_definitions/steps.js:3
140+
│ a step │ 0.00ms │ cypress/e2e/a.feature:3 │
141+
│ a step │ 0.00ms │ cypress/e2e/a.feature:4 │
142+
└────────────────┴──────────┴─────────────────────────────────────────────┘
137143
"""
138144

139145
Scenario: two definitions
@@ -147,21 +153,24 @@ Feature: usage report
147153
And a file named "cypress/support/step_definitions/steps.js" with:
148154
"""
149155
const { Given } = require("@badeball/cypress-cucumber-preprocessor");
150-
Given("a step", function() {});
156+
Given("a step", function() {
157+
// This makes sure "a step" takes longest and is printed top-post.
158+
cy.wait(1000);
159+
});
151160
Given("another step", function() {});
152161
"""
153162
When I run cypress
154163
Then the output should contain a usage report
155164
"""
156-
┌────────────────┬──────────┬─────────────────────────────────────────────┐
157-
│ Pattern / Text │ Duration │ Location │
158-
├────────────────┼──────────┼─────────────────────────────────────────────┤
159-
│ a step │ 0.00ms │ cypress/support/step_definitions/steps.js:2 │
160-
│ a step │ 0.00ms │ cypress/e2e/a.feature:3 │
161-
├────────────────┼──────────┼─────────────────────────────────────────────┤
162-
│ another step │ 0.00ms │ cypress/support/step_definitions/steps.js:3
163-
│ another step │ 0.00ms │ cypress/e2e/a.feature:4 │
164-
└────────────────┴──────────┴─────────────────────────────────────────────┘
165+
┌────────────────┬──────────┬─────────────────────────────────────────────┐
166+
│ Pattern / Text │ Duration │ Location │
167+
├────────────────┼──────────┼─────────────────────────────────────────────┤
168+
│ a step │ 0.00ms │ cypress/support/step_definitions/steps.js:2 │
169+
│ a step │ 0.00ms │ cypress/e2e/a.feature:3 │
170+
├────────────────┼──────────┼─────────────────────────────────────────────┤
171+
│ another step │ 0.00ms │ cypress/support/step_definitions/steps.js:6
172+
│ another step │ 0.00ms │ cypress/e2e/a.feature:4 │
173+
└────────────────┴──────────┴─────────────────────────────────────────────┘
165174
"""
166175

167176
Scenario: two features
@@ -179,17 +188,23 @@ Feature: usage report
179188
"""
180189
And a file named "cypress/support/step_definitions/steps.js" with:
181190
"""
182-
const { Given } = require("@badeball/cypress-cucumber-preprocessor");
191+
const { Given, BeforeStep } = require("@badeball/cypress-cucumber-preprocessor");
192+
BeforeStep(function ({ pickle }) {
193+
// This makes sure a.feature takes longest and is printed top-post.
194+
if (pickle.name === "a scenario name") {
195+
cy.wait(1000);
196+
}
197+
});
183198
Given("a step", function() {});
184199
"""
185200
When I run cypress
186201
Then the output should contain a usage report
187202
"""
188-
┌────────────────┬──────────┬─────────────────────────────────────────────┐
189-
│ Pattern / Text │ Duration │ Location │
190-
├────────────────┼──────────┼─────────────────────────────────────────────┤
191-
│ a step │ 0.00ms │ cypress/support/step_definitions/steps.js:2
192-
│ a step │ 0.00ms │ cypress/e2e/a.feature:3 │
193-
│ a step │ 0.00ms │ cypress/e2e/b.feature:3 │
194-
└────────────────┴──────────┴─────────────────────────────────────────────┘
203+
┌────────────────┬──────────┬─────────────────────────────────────────────┐
204+
│ Pattern / Text │ Duration │ Location │
205+
├────────────────┼──────────┼─────────────────────────────────────────────┤
206+
│ a step │ 0.00ms │ cypress/support/step_definitions/steps.js:8
207+
│ a step │ 0.00ms │ cypress/e2e/a.feature:3 │
208+
│ a step │ 0.00ms │ cypress/e2e/b.feature:3 │
209+
└────────────────┴──────────┴─────────────────────────────────────────────┘
195210
"""

package.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,9 @@
3737
},
3838
"files": [
3939
"dist/**/*.js",
40-
"dist/**/*.d.ts",
41-
"patches/patch.js"
40+
"dist/**/*.d.ts"
4241
],
4342
"scripts": {
44-
"postinstall": "node patches/patch.js",
4543
"clear-dist": "rm -rf dist",
4644
"clean-install": "rm -rf node_modules && npm install",
4745
"genversion": "genversion --semi --double --es6 lib/version.ts",
@@ -119,7 +117,6 @@
119117
"eslint-plugin-simple-import-sort": "^12.1.1",
120118
"genversion": "^3.2.0",
121119
"jsdom": "^24.1.1",
122-
"patch-package": "^8.0.0",
123120
"pngjs": "^7.0.0",
124121
"prettier": "^3.3.3",
125122
"recast": "^0.23.9",

patches/@cucumber+cucumber+10.9.0.patch

Lines changed: 0 additions & 25 deletions
This file was deleted.

patches/patch.js

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)