Fix/refactor autoexit#5556
Merged
Merged
Conversation
…hes pause()
When run_test's timeout was shorter than the time the test needed to
reach pause() (e.g. 50ms timeout vs 30s Playwright helper timeout),
Mocha kept running in the background, eventually entered paused state
forever (because cancelRun had reset abortRun=false), and every
subsequent run_test threw "Mocha instance is currently running tests".
The only recovery was killing the MCP process.
Three changes:
- lib/codecept.js: capture the Runner returned by mocha.run() as
mocha.runner, so callers have a clean handle to abort. Previously
the return value was discarded.
- cancelRun(): call mocha.runner.abort() to actually stop Mocha (sets
the runner's _abort flag, makes the run callback fire fast). Drop
the 5s race against pendingRunPromise — with runner.abort() the
promise settles quickly; relying on a short race meant a 30s
Playwright step would outlive the cancel and Mocha state stayed
RUNNING.
- abortRun lifecycle: stop resetting it inside cancelRun. Reset it at
the start of each new run_test / run_step_by_step instead. This way
if a late pause() fires after cancelRun returns (test reached pause
asynchronously after the timeout), setPauseHandler still rejects it
instead of trapping forever.
Repro fixed:
run_test({timeout: 50}) → Timeout after 50ms
run_test({timeout: 60000}) → completed, stats: {tests:1, passes:1}
(was: second call permanently failed with "Mocha is already running")
Refs: testomatio/e2e-tests#103
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
DavertMik
commented
May 10, 2026
| }, 1000).unref() | ||
| } | ||
| } | ||
| await autoExit() |
Contributor
Author
There was a problem hiding this comment.
@kobenguyent I refactored the previously written code for it
I hope having a single point would make this it clearer and easy to control
DavertMik
added a commit
that referenced
this pull request
May 11, 2026
* fix(plugins): resolve async race conditions in aiTrace, analyze, screencast, pageInfo, heal Fix 8 bugs across 6 plugin files where async operations outside the recorder chain, missing force flags, and incorrect filtering caused silent data loss, premature process exit, and broken healing limits. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix(analyze,screencast): rework for new autoExit + fix unit tests analyze.js: CODECEPT_DISABLE_AUTO_EXIT was removed in #5556 (autoExit refactor). Push printReport onto the recorder so it's awaited inside codecept.run()'s done() before autoExit fires. screencast tests: emit event.test.started in unit tests to match the production event sequence (asyncWrapper.js fires it between event.test.before and the first event.step.started). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> --------- Co-authored-by: gololdf1sh <oleksandr.kiriukhin@gmail.com> Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com> Co-authored-by: DavertMik <davert@testomat.io>
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.
Motivation/Description of the PR
Applicable helpers:
Applicable plugins:
Type of change
Checklist:
npm run docs)npm run lint)npm test)