Skip to content

Commit 3483d4b

Browse files
authored
add examples to prove retry and fail fast interplay (cucumber#1567)
* add examples to prove retry and fail fast interplay * fix name * update cli docs
1 parent 4811647 commit 3483d4b

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed

docs/cli.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,8 @@ abort the run on first failure (default: false)
153153

154154
By default, cucumber-js runs the entire suite and reports all the failures. This flag allows a developer workflow where you work on one failure at a time. Combining this feature with rerun files allows you to work through all failures in an efficient manner.
155155

156+
A note on using in conjunction with `--retry`: we consider a test case to have failed if it exhausts retries and still fails, but passed if it passes on a retry having failed previous attempts, so `--fail-fast` does still allow retries to happen.
157+
156158
## Retry failing tests
157159

158160
Use `--retry <int>` to rerun tests that have been failing. This can be very helpful for flaky tests.

features/retry.feature

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,3 +534,60 @@ Feature: Retry flaky tests
534534
"""
535535
When I run cucumber-js with `--retry 1`
536536
Then it passes
537+
538+
Rule: using retry in combination with fail-fast will exhaust retries before failing test run
539+
540+
Scenario: a flaky scenario that passes on the second attempt, set to fail fast
541+
Given a file named "features/a.feature" with:
542+
"""
543+
Feature:
544+
Scenario: Flaky
545+
Given a flaky step
546+
547+
Scenario: Passing
548+
Given a passing step
549+
"""
550+
Given a file named "features/step_definitions/cucumber_steps.js" with:
551+
"""
552+
const {Given} = require('@cucumber/cucumber')
553+
554+
let willPass = false
555+
556+
Given(/^a flaky step$/, function() {
557+
if (willPass) {
558+
return
559+
}
560+
willPass = true
561+
throw 'fail'
562+
})
563+
564+
Given(/^a passing step$/, function() {})
565+
"""
566+
When I run cucumber-js with `--retry 1 --fail-fast`
567+
Then it passes
568+
And scenario "Flaky" attempt 0 step "Given a flaky step" has status "failed"
569+
And scenario "Flaky" attempt 1 step "Given a flaky step" has status "passed"
570+
And scenario "Passing" step "Given a passing step" has status "passed"
571+
572+
Scenario: a scenario that fails every allotted attempt, set to fail fast
573+
Given a file named "features/a.feature" with:
574+
"""
575+
Feature:
576+
Scenario: Failing
577+
Given a failing step
578+
579+
Scenario: Passing
580+
Given a passing step
581+
"""
582+
Given a file named "features/step_definitions/cucumber_steps.js" with:
583+
"""
584+
const {Given} = require('@cucumber/cucumber')
585+
586+
Given(/^a failing step$/, function() { throw 'fail' })
587+
Given(/^a passing step$/, function() {})
588+
"""
589+
When I run cucumber-js with `--retry 1 --fail-fast`
590+
Then it fails
591+
And scenario "Failing" attempt 0 step "Given a failing step" has status "failed"
592+
And scenario "Failing" attempt 1 step "Given a failing step" has status "failed"
593+
And scenario "Passing" step "Given a passing step" has status "skipped"

0 commit comments

Comments
 (0)