Skip to content

test_runner: expose worker ID for concurrent test execution#61394

Merged
nodejs-github-bot merged 1 commit into
nodejs:mainfrom
thisalihassan:test-runner-worker-id
Feb 24, 2026
Merged

test_runner: expose worker ID for concurrent test execution#61394
nodejs-github-bot merged 1 commit into
nodejs:mainfrom
thisalihassan:test-runner-worker-id

Conversation

@thisalihassan

Copy link
Copy Markdown
Contributor

This adds support for identifying which worker is running a test file when tests execute concurrently, similar to JEST_WORKER_ID in Jest, VITEST_POOL_ID in Vitest, and MOCHA_WORKER_ID in Mocha.

When running with --test-isolation=process (default), each test file runs in a separate child process and receives a unique worker ID from 1 to N. When running with --test-isolation=none, all tests run in the same process and the worker ID is always 1.

This enables users to allocate separate resources (databases, ports, etc.) for each test worker to avoid conflicts during concurrent execution.

Changes:

  • Add WorkerIdPool class to manage worker ID allocation and reuse
  • Set NODE_TEST_WORKER_ID environment variable for child processes
  • Add context.workerId getter to TestContext class
  • Add tests for worker ID functionality
  • Add documentation for NODE_TEST_WORKER_ID and context.workerId

Fixes: #55842

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

commit-queue-squash Add this label to instruct the Commit Queue to squash all the PR commits into the first one. needs-ci PRs that need a full CI run. semver-minor PRs that contain new features and should be released in the next minor version. test_runner Issues and PRs related to the test runner subsystem.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Expose an id for concurrent test runners (like JEST_WORKER_ID)

7 participants