fix(jest): report tests from custom environments#9194
Conversation
Overall package sizeSelf size: 6.53 MB Dependency sizes| name | version | self size | total size | |------|---------|-----------|------------| | import-in-the-middle | 3.2.0 | 104.26 kB | 843.44 kB | | opentracing | 0.14.7 | 194.81 kB | 194.81 kB | | dc-polyfill | 0.1.11 | 25.74 kB | 25.74 kB |🤖 This report was automatically generated by heaviest-objects-in-the-universe |
|
@codex review |
|
/datadog autotest review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8038fc8927
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
🎉 All green!🧪 All tests passed 🎯 Code Coverage (details) 🔗 Commit SHA: c96ddba | Docs | Datadog PR Page | Give us feedback! |
BenchmarksBenchmark execution time: 2026-07-03 06:31:00 Comparing candidate commit c96ddba in PR branch Found 0 performance improvements and 0 performance regressions! Performance is the same for 2251 metrics, 35 unstable metrics.
|
There was a problem hiding this comment.
More details
The wrapper logic in wrapCustomHandleTestEvent is correct across all adversarial scenarios: normal environments (no wrapper installed), custom envs without super (DD fires after custom), custom envs with super (DD fires exactly once via dedup), sync/async mismatches (returns thenable preserving custom return value), sync throws and async rejections (propagate cleanly without triggering DD), and multi-level inheritance (DD always fires after the outermost override). The module-scope handledJestEvents WeakSet is safe because Jest creates fresh event objects per dispatch and workers are isolated processes.
📊 Validated against 12 scenarios · Open Bits AI session
🤖 Datadog Autotest · Commit 8038fc8 · What is Autotest? · Any feedback? Reach out in #autotest
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #9194 +/- ##
=======================================
Coverage 93.64% 93.64%
=======================================
Files 898 898
Lines 52365 52421 +56
Branches 12324 12340 +16
=======================================
+ Hits 49037 49091 +54
- Misses 3328 3330 +2 Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
@codex review |
|
/datadog autotest review |
|
Codex Review: Didn't find any major issues. Another round soon, please! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c6a2b5cf16
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
More details
The wrapper correctly handles all three custom-environment patterns (prototype override without super, instance field, async add_test) — 9 adversarial scenarios executed locally all pass. The WeakSet deduplication prevents double-firing when a custom env does call super, and the setup() re-check correctly defers instance-field wrapping until after the subclass constructor completes.
📊 Validated against 9 scenarios · Open Bits AI session
🤖 Datadog Autotest · Commit c6a2b5c · What is Autotest? · Any feedback? Reach out in #autotest
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3c616effad
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
@codex review |
|
Codex Review: Didn't find any major issues. 🎉 Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
What does this PR do?
Ensures dd-trace still reports Jest test events when a project uses a custom Jest environment that overrides
handleTestEventwithout callingsuper.handleTestEvent.The Jest environment wrapper now detects custom
handleTestEventoverrides and runs Datadog's event handler after the custom handler when the event has not already been handled.Motivation
While validating Test Optimization against
webpack/webpack, the runbook reported session, module, and suite events, but zero test events. The project uses a custom Jest environment, and that environment shadows Datadog's Jest circushandleTestEventhook. As a result, per-test events never reached the intake even though the broader Jest lifecycle was instrumented.