Skip to content

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

Open
DavertMik wants to merge 1 commit into
4.xfrom
fix/workers-grep-distribution
Open

DavertMik wants to merge 1 commit 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>

This branch has not been deployed

No deployments
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.

1 participant