Skip to content
This repository was archived by the owner on Mar 29, 2023. It is now read-only.

Commit 60b9cbf

Browse files
authored
feat: add burn parameter to repeat filtered tests (#33)
* feat: add burn parameter to repeat filtered tests * update README
1 parent a731a4e commit 60b9cbf

File tree

4 files changed

+42
-1
lines changed

4 files changed

+42
-1
lines changed

.github/workflows/ci.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,13 @@ jobs:
125125
--env grepTags=@smoke \
126126
--expect expects/describe-tags-spec.json
127127
128+
# repeat the selected test 3 times
129+
- name: Burn grepped test 🧪
130+
run: |
131+
npx cypress-expect \
132+
--env grep="hello w",burn=3 \
133+
--expect expects/hello-burn.json
134+
128135
- name: Semantic Release 🚀
129136
uses: cycjimmy/semantic-release-action@v2
130137
with:

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,16 @@ You can run tests that match one tag or another using spaces. Make sure to quote
212212
--env grepTags='@slow @critical'
213213
```
214214

215+
## Burn
216+
217+
You can repeat (burn) the filtered tests to make sure they are flake-free
218+
219+
```
220+
npx cypress run --env grep="hello world",burn=5
221+
```
222+
223+
You can pass the number of times to run the tests via environment name `burn` or `grepBurn` or `grep-burn`. Note, if a lot of tests match the grep and grep tags, a lot of tests will be burnt!
224+
215225
## General advice
216226

217227
- keep it simple.

expects/hello-burn.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"hello world: burning 1 of 3": "passed",
3+
"hello world: burning 2 of 3": "passed",
4+
"hello world: burning 3 of 3": "passed",
5+
"works": "pending",
6+
"works 2 @tag1": "pending",
7+
"works 2 @tag1 @tag2": "pending",
8+
"works @tag2": "pending"
9+
}

src/support.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,15 @@ function cypressGrep() {
2424
return
2525
}
2626

27-
debug('grep %o', { grep, grepTags })
27+
/** @type {number} Number of times to repeat each running test */
28+
const grepBurn =
29+
Cypress.env('grepBurn') ||
30+
Cypress.env('grep-burn') ||
31+
Cypress.env('burn') ||
32+
1
33+
34+
debug('grep %o', { grep, grepTags, grepBurn })
35+
// TODO validate grepBurn value
2836
const parsedGrep = parseGrep(grep, grepTags)
2937
debug('parsed grep %o', parsedGrep)
3038

@@ -47,6 +55,13 @@ function cypressGrep() {
4755
const shouldRun = shouldTestRun(parsedGrep, name, configTags)
4856

4957
if (shouldRun) {
58+
if (grepBurn > 1) {
59+
// repeat the same test to make sure it is solid
60+
return Cypress._.times(grepBurn, (k) => {
61+
const fullName = `${name}: burning ${k + 1} of ${grepBurn}`
62+
_it(fullName, options, callback)
63+
})
64+
}
5065
return _it(name, options, callback)
5166
}
5267

0 commit comments

Comments
 (0)