Skip to content

Global test (scenario) timeout doesn't work if BeforeSuite() in a test is present #5265

@mirao

Description

@mirao

Use this test Timeout_test.ts:

Feature('Timeout');

BeforeSuite(() => {
    // No stuff needed here to reproduce the issue
});

Scenario('Test timeout',  ({ I }) => {
    I.wait(4);
});

config codecept.conf.ts (with 2 secs global timeout (timeout for every scenario)):

import { setHeadlessWhen, setCommonPlugins } from '@codeceptjs/configure';
// turn on headless mode when running with HEADLESS=true environment variable
// export HEADLESS=true && npx codeceptjs run
setHeadlessWhen(process.env.HEADLESS);

// enable all common plugins https://github.com/codeceptjs/configure#setcommonplugins
setCommonPlugins();

export const config: CodeceptJS.MainConfig = {
  tests: './*_test.ts',
  output: './output',
  helpers: {
    Playwright: {
      browser: 'chromium',
      url: 'http://localhost',
      show: true
    }
  },
  include: {
    I: './steps_file'
  },
  plugins: {
    htmlReporter: {
      enabled: true
    }
  },
  name: 'my',
  timeout: 2
}

Run the test

mirao@rog:~/workspace/my$ codeceptjs run --verbose
***************************************
nodeInfo:  20.19.5
osInfo:  Linux 6.14 Ubuntu 24.04.3 LTS 24.04.3 LTS (Noble Numbat)
cpuInfo:  (16) x64 AMD Ryzen 7 9700X 8-Core Processor
chromeInfo:  141.0.7390.107
edgeInfo:  "N/A"
firefoxInfo:  undefined
safariInfo:  N/A
playwrightBrowsers:  "chromium: 141.0.7390.37, firefox: 142.0.1, webkit: 26.0"
If you need more detailed info, just run this: npx codeceptjs info
***************************************
CodeceptJS v3.7.5 #StandWithUkraine
Using test root "/home/mirao/workspace/my"
Helpers: Playwright
Plugins: screenshotOnFail, htmlReporter, retryFailedStep, eachElement

Timeout --
/home/mirao/workspace/my/Timeout_test.ts
    [1]  Starting recording promises
    Timeouts: 2
 › [Session] Starting singleton browser session
  BeforeSuite()

  Test timeout
 › [New Session] {"ignoreHTTPSErrors":false,"acceptDownloads":true}
  Scenario()
    I wait 4
HTML Reporter: Test finished - Test timeout, State: passed, Retries: 0
HTML Reporter: Test Test timeout artifacts at test.finished: []
HTML Reporter: Added new test - Test timeout, State: passed
  ✔ OK in 4003ms


  OK  | 1 passed   // 4s

Expected result:
It fails on timeout

Actual result:
It doesn't fail

If you omit BeforeSuite(), it works as expected

Feature('Timeout');

// BeforeSuite(() => {
//     // Not stuff needed here to reproduce the issue
// });

Scenario('Test timeout',  ({ I }) => {
    I.wait(4);
});

Now the test is failing as expected ✔️ :

mirao@rog:~/workspace/my$ codeceptjs run --verbose
***************************************
nodeInfo:  20.19.5
osInfo:  Linux 6.14 Ubuntu 24.04.3 LTS 24.04.3 LTS (Noble Numbat)
cpuInfo:  (16) x64 AMD Ryzen 7 9700X 8-Core Processor
chromeInfo:  141.0.7390.107
edgeInfo:  "N/A"
firefoxInfo:  undefined
safariInfo:  N/A
playwrightBrowsers:  "chromium: 141.0.7390.37, firefox: 142.0.1, webkit: 26.0"
If you need more detailed info, just run this: npx codeceptjs info
***************************************
CodeceptJS v3.7.5 #StandWithUkraine
Using test root "/home/mirao/workspace/my"
Helpers: Playwright
Plugins: screenshotOnFail, htmlReporter, retryFailedStep, eachElement

Timeout --
/home/mirao/workspace/my/Timeout_test.ts
    [1]  Starting recording promises
    Timeouts: 2
 › [Session] Starting singleton browser session
  Test timeout
 › Test Timeout: 2s
 › [New Session] {"ignoreHTTPSErrors":false,"acceptDownloads":true}
  Scenario()
    I wait 4
    [1]  Error (Non-Terminated) | TimeoutError: Action wait: 4 was interrupted on timeout 2000ms | err => { // we wrap timeout errors in a StepTimeou...
    [1]  Error (Non-Terminated) | TestTimeoutError: Timeout 2s exceeded (with Before hook) | err => { step.status = 'failed' step.endTime = +Da...
    [1] Error | TestTimeoutError: Timeout 2s exceeded (with Before hook) undefined...
HTML Reporter: Test finished - Test timeout, State: failed, Retries: 0
HTML Reporter: Test Test timeout artifacts at test.finished: []
HTML Reporter: Added new test - Test timeout, State: failed
    [1] <teardown>  Stopping recording promises
 › <screenshotOnFail> Test failed, try to save a screenshot
 › [Screenshot] output/Test_timeout.failed.png
  ✖ FAILED in 2039ms

    [2]  Starting recording promises

-- FAILURES:

  1) Timeout
       Test timeout:
     
  Timeout 2s exceeded (with Before hook)
  TestTimeoutError: 
      at /home/mirao/workspace/my/node_modules/codeceptjs/lib/listener/globalTimeout.js:135:17
      at /home/mirao/workspace/my/node_modules/codeceptjs/lib/recorder.js:299:16
  
  
  ◯ File: file:///home/mirao/workspace/my/Timeout_test.ts
  
  ◯ Scenario Steps:
  ✖ I.wait(4) at Test.<anonymous> (./Timeout_test.ts:8:7)
  
  ◯ Artifacts:
  - screenshot: /home/mirao/workspace/my/output/Test_timeout.failed.png
  
  ◯ Metadata:
  - browser: chromium
  - browserVersion: 141.0.7390.37
  - windowSize: 1280x720


  FAIL  | 0 passed, 1 failed   // 2s

Used SW:

  • CodeceptJS 3.7.5
  • Playwright 1.56.1

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