Skip to content

fix(pause): only pause on fail when the test fails - #5736

Open
luantaraschi wants to merge 1 commit into
codeceptjs:4.xfrom
luantaraschi:fix/pause-on-fail-swallowed-step
Open

luantaraschi wants to merge 1 commit into
codeceptjs:4.xfrom
luantaraschi:fix/pause-on-fail-swallowed-step

Conversation

@luantaraschi

Copy link
Copy Markdown
Contributor

Motivation/Description of the PR

Fixes #4516.

With -p pauseOnFail (or -p pause:on=fail), a scenario that passes still drops into the interactive shell if one of its steps failed inside tryTo. The fail mode in lib/plugin/pause.js set its flag on event.step.failed, and that event fires for every failed step, including the ones tryTo, hopeThat and retryTo swallow afterwards. At test.after the plugin then paused without looking at how the test ended.

The flag is now set on event.test.failed. Hook failures still pause, because they reach the test as test.failed before test.after.

I checked it in a small sandbox with the FileSystem helper and a handler that only logs when the pause would open:

Scenario Test result 4.x today This PR
step swallowed by tryTo passes pauses no pause
step swallowed by hopeThat passes pauses no pause
retryTo that passes on the 2nd attempt passes pauses no pause
a real failing step fails pauses pauses
failure in Before / After fails pauses pauses
failure in BeforeSuite / AfterSuite fails no pause no pause
plain throw or JS assertion, no failed step fails no pause pauses

The last row is a behaviour change. A test that fails without a failed step used to slip through, and now it pauses, which matches docs/plugins/pauseOnFail.md ("Starts an interactive pause when a test fails"). If you'd rather keep the old behaviour there, I can require both a failed step and a failed test instead.

The new test/unit/plugin/pause_test.js covers these cases (8 tests). On 4.x, 4 of them fail: tryTo, hopeThat, retryTo and the plain throw. I also updated the JSDoc of the fail mode and the line in docs/debugging.md.

I targeted 4.x because the same logic on 3.x lives in lib/plugin/pauseOnFail.js and that branch has only been getting dependency updates.

Applicable helpers:

  • Playwright
  • Puppeteer
  • WebDriver
  • REST
  • FileHelper
  • Appium

Applicable plugins:

  • aiTrace
  • autoDelay
  • autoLogin
  • customLocator
  • pause
  • coverage
  • heal
  • retryFailedStep
  • screenshot
  • selenoid
  • stepTimeout
  • subtitles

Type of change

  • 🔥 Breaking changes
  • 🚀 New functionality
  • 🐛 Bug fix
  • 🧹 Chore
  • 📋 Documentation changes/updates
  • ♨️ Hot fix
  • 🔨 Markdown files fix - not related to source code
  • 💅 Polish code

Checklist:

  • Tests have been added
  • Documentation has been added (Run npm run docs)
  • Lint checking (Run npm run lint)
  • Local tests are passed (Run npm test)

I ran the whole unit suite (npx mocha test/unit --recursive) on Windows: the same 11 failures as 4.x without the change, all path-related (workers, sharding, trace), plus the new tests passing. The runner tests don't run on Windows, so I didn't run npm test. I haven't tried workers or Scenario().retry with the plugin.

The fail mode of the pause plugin (and the pauseOnFail alias) set its flag
on step.failed, so a step that failed inside tryTo, hopeThat or retryTo
opened the interactive shell even though the test passed. Track
test.failed instead. Hook failures still pause because they are reported
through test.failed before test.after.

Fixes codeceptjs#4516

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

tryTo() triggering false positive to pauseOnFail - stopping at first scenario

1 participant