Skip to content

After and AfterSuite hooks return exit code 0 on failure instead of 1, incorrectly indicating success #5057

@h2oJan

Description

@h2oJan

What are you trying to achieve?

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: $?"

Details

  • CodeceptJS version: 3.7.3
  • Working CodeceptJS version: 3.6.6
  • Helper: Playwright
  • NodeJS version: 24.3.0
  • Operating System: MacOS

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions