fix(pause): stop pause() at the right step in 4.x (#5652)#5653
Open
mirao wants to merge 1 commit into
Open
Conversation
…t step (codeceptjs#5652) global.pause was an async wrapper doing a lazy `await import('./pause.js')`. A scenario body runs synchronously to build the recorder queue, so the await deferred pause's `recorder.add('Start new session')` to a later microtask — after the following steps had already been queued. As a result pause() stopped *after* the next step instead of before it. initCodeceptGlobals is already async, so resolve the module up front and assign the real pause function directly, making it synchronous at call time and restoring queue order. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #5652
Problem
In 4.x,
pause()stops after the following step instead of before it:Works correctly in 3.7.9; broken in 4.0.x and 4.1 beta.
Root cause
global.pausewas wired as an async wrapper doing a lazy dynamic import inlib/globals.js:A scenario body runs synchronously to build the recorder queue — every
I.*call doesrecorder.add(...)synchronously. Becausepausewas async, calling it returned at theawait import(...), deferring itsrecorder.add('Start new session', ...)to a later microtask — after the rest of the synchronous body had already been queued.DEBUG=codeceptjs:recorderfor the repro:This also explains why
await pause()worked as a workaround: awaiting suspends the synchronous body until pause'srecorder.addhas run.Fix
initCodeceptGlobalsis alreadyasync, so resolve the module up front and assign the real function directly, makingpausesynchronous at call time:Ordering is restored:
Test
Added a regression test in
test/unit/pause_test.jsthat wiresglobal.pauseviainitCodeceptGlobalsand asserts:global.pauseis the real (synchronous)pausefunction, not an async wrapper;amOnPage → pause → see), theStart new sessionstep is queued between the surrounding steps (checked synchronously viarecorder.scheduled()).The test fails against the old async-wrapper implementation and passes with the fix. Full
test/unitsuite is green (759 passing).🤖 Generated with Claude Code