You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
After and AfterSuite hooks return exit code 0 on failure instead of 1, incorrectly indicating success #5057
When an error is thrown inside an After or AfterSuite hook in CodeceptJS, the process should exit with a non-zero exit code (e.g. 1), indicating failure.
What do you get instead?
Process exits with code 0, indicating success. This misleads CI systems and users, as the test run should be considered failed when any lifecycle hook fails. This worked correctly in CodeceptJS 3.6.6.
It also works correctly for Before and BeforeSuite hooks.
Reproduction steps
Feature('after-hook');
Before(({ I }) => {
I.amOnPage('https://www.google.com')
I.waitForText('Google')
})
After(({ I }) => {
I.waitForText('Google-xxx-FAIL') // This will fail
})
Scenario('test something', ({ I }) => {
I.waitForText('Google')
})
To obtain exit code, you can run with npm run codeceptjs; echo "Exit code: $?"
I wanted to open a PR for this but based on the current implementation it almost seems like this is the intended behavior?
This started with version 3.7.0. Previous implementation emits event.test.failed for the whole suite, regardless of which hook failed. Maybe not the ideal implementation since it's mixing up test and suite concepts
In my opinion suiteTestFailedHookError should be called for any hook failure, like this was done before, otherwise a failed after hook will just silently skip all the remaining tests and never indicate any problems.
Activity
nikzupancic commentedon Aug 5, 2025
I wanted to open a PR for this but based on the current implementation it almost seems like this is the intended behavior?
This started with version 3.7.0. Previous implementation emits
event.test.failedfor the whole suite, regardless of which hook failed. Maybe not the ideal implementation since it's mixing up test and suite conceptsThe new version fixes the suite and test differences with suiteTestFailedHookError but it's only triggered for
beforeandbeforeSuitefailuresIn my opinion
suiteTestFailedHookErrorshould be called for any hook failure, like this was done before, otherwise a failed after hook will just silently skip all the remaining tests and never indicate any problems.