[test optimization] Add support for --workerThreads flag in jest#7840
[test optimization] Add support for --workerThreads flag in jest#7840juan-fernandez merged 3 commits intomasterfrom
--workerThreads flag in jest#7840Conversation
Hook jest-worker's NodeThreadsWorker (ExperimentalWorker) for <30 and detect worker type in the >=30 enqueue wrapper via _child vs _worker. In the test-worker writer, remove the vitest-only guard on parentPort so jest worker threads can also send trace/coverage/logs/telemetry payloads back to the parent via worker_threads. Add integration tests verifying test events are reported correctly when jest runs with worker_threads (agentless and evp proxy). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #7840 +/- ##
==========================================
- Coverage 74.41% 74.39% -0.02%
==========================================
Files 768 768
Lines 35788 35800 +12
==========================================
+ Hits 26630 26632 +2
- Misses 9158 9168 +10 Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Overall package sizeSelf size: 5.06 MB Dependency sizes| name | version | self size | total size | |------|---------|-----------|------------| | import-in-the-middle | 3.0.0 | 81.15 kB | 815.98 kB | | dc-polyfill | 0.1.10 | 26.73 kB | 26.73 kB |🤖 This report was automatically generated by heaviest-objects-in-the-universe |
BenchmarksBenchmark execution time: 2026-03-30 14:11:23 Comparing candidate commit 4134b15 in PR branch Found 0 performance improvements and 0 performance regressions! Performance is the same for 229 metrics, 31 unstable metrics. |
--workerThreads flag in jest
--workerThreads flag in jest--workerThreads flag in jest
|
✅ Tests 🎉 All green!❄️ No new flaky tests detected 🎯 Code Coverage (details) 🔗 Commit SHA: 4134b15 | Docs | Datadog PR Page | Was this helpful? React with 👍/👎 or give us feedback! |
What does this PR do?
Adds support for jest's
--workerThreadsflag so that test optimization instrumentation works when jest runs tests in worker threads instead of child processes.Instrumentation (
packages/datadog-instrumentations/src/jest.js):jest-worker'sNodeThreadsWorker(ExperimentalWorker) for versions<30wrapWorkerhelper that detects worker type in the>=30enqueueWrappervia_child(child_process) vs_worker(worker_threads)onMessageWrapperagainst non-array messages that can arrive in worker threads (e.g. from user code callingparentPort.postMessage)Writer (
packages/dd-trace/src/ci-visibility/exporters/test-worker/writer.js):parentPortso jest worker threads can also send trace/coverage/logs/telemetry payloads back to the parentprocess.send(child_process) →parentPort.postMessage(worker_threads) → fallbackMotivation
Jest supports
--workerThreadsto run tests inworker_threadsinstead ofchild_process. Our instrumentation previously only handled child process workers, so trace/coverage data was silently lost when this flag was enabled.Testing
--workerThreads(both agentless and evp proxy)parentPort)