Skip to content

fix(workers): distribute only tests matching grep - #5727

Merged
DavertMik merged 2 commits into
4.xfrom
fix/workers-grep-distribution
Oct 8, 2026
Merged

DavertMik merged 2 commits into
4.xfrom
fix/workers-grep-distribution

Conversation

@DavertMik

Copy link
Copy Markdown
Contributor

Problem

run-workers splits all loaded tests across workers and each worker applies --grep afterwards. With a narrow pattern the matching tests can land on one worker, while the others start only to print "No tests found by pattern".

On the sandbox fixture (7 tests, 2 match):

$ codeceptjs run-workers 3 --grep "From worker"
Test distribution:
  Worker 1: 3 tests
  Worker 2: 2 tests
  Worker 3: 2 tests

Change

  • createGroupsOfTests / createGroupsOfSuites assign only tests matching mocha's grep. That covers --grep, --invert, the grep config key and Feature.only / Scenario.only.
  • Workers that would get no tests are not started (at least one is always kept).
  • When nothing matches, distribution is unchanged, so workers still print the empty-run hint and CI still fails on an empty run.

After:

$ codeceptjs run-workers 3 --grep "From worker"
Test distribution:
  Worker 1: 1 test
  Worker 2: 1 test

Not changed

  • --by pool hands out files, not tests, so it still loads files that have no matching test.
  • The "Running tests in N workers..." banner still prints the requested count.
  • Groups returned by createGroupsOfTests(n) to custom scripts keep length n; only the built-in split drops empty ones.

Tests

test/runner/run_workers_test.js and test/unit/worker_test.js pass locally (45 passing, 2 pending).

🤖 Generated with Claude Code

run-workers split every loaded test across workers and let each worker
apply --grep afterwards. A narrow pattern could put all matching tests
on one worker while the others started only to report an empty run.

Tests are now filtered by grep (and --invert, config grep, .only) before
they are assigned, and workers that would get no tests are not started.
When nothing matches, distribution is unchanged so workers still print
the empty-run hint.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* feat(workers): run serial tests after parallel workers

Tests matching the new `serial` config pattern are kept out of the
parallel workers. Once those exit, one more worker starts and runs the
serial tests one by one, inside the same run: bootstrapAll, teardownAll
and workers.result fire once and the exit code covers both parts.

Works with every --by strategy and combines with --grep.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* feat(workers): add --serial option to run-workers

Sets or overrides the serial config pattern for a single run.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: DavertMik <davert@testomat.io>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
@DavertMik
DavertMik merged commit b90f04a into 4.x Oct 8, 2026
14 checks passed
@DavertMik
DavertMik deleted the fix/workers-grep-distribution branch October 8, 2026 00:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants