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
Error processing test.finish event: TypeError: finish is not a function #5461
I believe this is a small fix but I can't figure it from where.
Maybe someone could help to check and guide, or even better already has a solution for this:
Error processing test.finish event:
TypeError: finish is not a function
at EventEmitter. (/.../node_modules/codeceptjs/lib/pause.js:40:5)
at EventEmitter.emit (node:events:529:35)
at Object.emit (/.../node_modules/codeceptjs/lib/event.js:162:28)
at /.../node_modules/codeceptjs/lib/mocha/asyncWrapper.js:74:13
at /.../node_modules/codeceptjs/lib/recorder.js:274:9
finish is declared as a module-level variable (line 18) but is only assigned inside pauseSession() (line 86), where it's set to the resolve function of a Promise:
returnnewPromise(resolve=>{finish=resolve// ← only assigned herereturnaskForStep()})
The Race Condition
The event.test.finished listener is registered at line 39 and calls finish() at line 40:
event.dispatcher.on(event.test.finished,()=>{finish()// ← called hererecorder.session.restore('pause')rl.close()history.save()})
This will throw TypeError: finish is not a function if event.test.finished fires before pauseSession() has ever been called — because finish is still undefined at that point.
When Can This Happen?
A test finishes very quickly (e.g., skipped, errored early) beforerecorder.add('Start new session', ...) has had a chance to invoke pauseSession().
The pause() function is called, the event listener is registered, but the recorder hasn't yet executed the pauseSession callback by the time the test.finished event fires.
Activity
kobenguyent commentedon Apr 7, 2026
noticed this was introduced by #4713
kobenguyent commentedon Apr 7, 2026
@incoming-th may you try this fix locally?
Here's why:
The Bug
finishis declared as a module-level variable (line 18) but is only assigned insidepauseSession()(line 86), where it's set to theresolvefunction of aPromise:The Race Condition
The
event.test.finishedlistener is registered at line 39 and callsfinish()at line 40:This will throw
TypeError: finish is not a functionifevent.test.finishedfires beforepauseSession()has ever been called — becausefinishis stillundefinedat that point.When Can This Happen?
recorder.add('Start new session', ...)has had a chance to invokepauseSession().pause()function is called, the event listener is registered, but the recorder hasn't yet executed thepauseSessioncallback by the time thetest.finishedevent fires.Fix
Guard the
finish()call with a type check:The same guard should also be applied to the
parseInputcall at line 97, which has the same vulnerability.Add safeguards fo finish in pause.js codeceptjs#5461
incoming-th commentedon Apr 7, 2026
@kobenguyent Thanks for looking into this. The safeguard is fine.
resolve codeceptjs#5461
resolve #5461 (#5612)