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
fix(effects): make within/tryTo/hopeThat/retryTo work under tsx/cjs (#5632)
When a TypeScript test imports effects through a CommonJS loader
(`import { tryTo } from 'codeceptjs/effects'` under `tsx/cjs`), Node loads a
second, disconnected CJS copy of effects.js together with its own copies of the
`recorder` and `container` singletons. That recorder is never started
(`running=false`), so every `recorder.add()` short-circuits: tryTo() and
hopeThat() return undefined without running their callback, within() silently
skips its steps (and its empty container never calls `_withinBegin`), and
retryTo() never resolves and hangs.
This is the default situation for essentially every TS project, because
CodeceptJS loads test files through Mocha's synchronous `require()` (CJS realm)
while the framework itself runs as ESM.
Fix by making the singletons realm-agnostic via the same globalThis bridge the
framework already uses for `global.codeceptjs`:
- recorder.js: start() registers the running instance on
`globalThis.__codeceptjs_recorder` (only the started instance registers).
- container.js: create() registers the live container on
`globalThis.__codeceptjs_container`.
- effects.js: resolve recorder/container through `_getRecorder()` /
`_getContainer()`, which prefer the globalThis instances and fall back to the
local imports under pure ESM (no behavior change there).
Adds a runner regression test (test/data/effects-tsx-cjs + effects_tsx_test.js)
that drives a real `tsx/cjs` project and asserts all four effects execute. It
fails without the fix (and a timeout guard keeps a regressed retryTo() from
hanging the suite) and passes with it.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
0 commit comments