Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions lib/listener/globalTimeout.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,29 @@ module.exports = function () {

// disable timeout for BeforeSuite/AfterSuite hooks
// add separate configs to them?
// When a BeforeSuite/AfterSuite hook starts we want to disable the
// per-test timeout during that hook execution only. Previously the
// code cleared `suiteTimeout` permanently which caused the suite
// level timeout to be lost for subsequent tests. Save previous
// values and restore them when the hook finishes.
let __prevTimeout = undefined
let __prevSuiteTimeout = undefined

event.dispatcher.on(event.hook.started, hook => {
if (hook instanceof BeforeSuiteHook) {
if (hook instanceof BeforeSuiteHook || hook instanceof AfterSuiteHook) {
__prevTimeout = timeout
// copy array to preserve original values
__prevSuiteTimeout = suiteTimeout.slice()
timeout = null
suiteTimeout = []
}
if (hook instanceof AfterSuiteHook) {
timeout = null
suiteTimeout = []
})

event.dispatcher.on(event.hook.finished, hook => {
if (hook instanceof BeforeSuiteHook || hook instanceof AfterSuiteHook) {
// restore previously stored values
timeout = __prevTimeout
suiteTimeout = __prevSuiteTimeout.slice()
}
})

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Feature('Global Timeout with BeforeSuite')

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

Scenario('enforce global timeout with BeforeSuite', ({ I }) => {
I.waitForSleep(4 * 1000)
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
exports.config = {
tests: './*_test.js',
output: './output',
helpers: {
CustomHelper: {
require: './customHelper.js',
},
},
name: 'beforeSuiteTimeout',
timeout: 2,
}
10 changes: 10 additions & 0 deletions test/runner/timeout_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,14 @@ describe('CodeceptJS Timeouts', function () {
done()
})
})

it('should enforce global timeout even with BeforeSuite', done => {
exec(config_run_config('codecept.beforeSuiteTimeout.conf.js', 'enforce global timeout with BeforeSuite', true), (err, stdout) => {
debug_this_test && console.log(stdout)
expect(stdout).toContain('Timeout 2s exceeded')
expect(stdout).toContain('TestTimeoutError')
expect(err).toBeTruthy()
done()
})
})
})