fix(jest): instrument resolved build file loads#9211
Conversation
Overall package sizeSelf size: 6.53 MB Dependency sizes| name | version | self size | total size | |------|---------|-----------|------------| | import-in-the-middle | 3.3.0 | 117.14 kB | 432.47 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 |
🎉 All green!🧪 All tests passed 🎯 Code Coverage (details) 🔗 Commit SHA: fc2af13 | Docs | Datadog PR Page | Give us 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". |
BenchmarksBenchmark execution time: 2026-07-06 12:18:51 Comparing candidate commit fc2af13 in PR branch Found 0 performance improvements and 0 performance regressions! Performance is the same for 2254 metrics, 32 unstable metrics.
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #9211 +/- ##
==========================================
- Coverage 93.65% 93.63% -0.03%
==========================================
Files 899 899
Lines 52473 52476 +3
Branches 12352 12352
==========================================
- Hits 49145 49134 -11
- Misses 3328 3342 +14 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:
|
|
/datadog autotest review |
fc4ce56 to
7a8f7c1
Compare
7a8f7c1 to
372df25
Compare
372df25 to
32a3d8b
Compare
There was a problem hiding this comment.
More details
Instrumentation hooks correctly added for resolved build-file paths (jest-environment-node/build/index.js, jest-environment-jsdom/build/index.js, @jest/test-sequencer/build/index.js). No double-wrapping risk—the hook system matches only the exact computed module name. Refactored testSequencerWrapper function reused for both package-root and build-file hooks with identical semantics. Jest 30+ regression test validates the fix. All changes are safe and correct.
📊 Validated against 3 scenarios · Open Bits AI session
🤖 Datadog Autotest · Commit fc4ce56 · What is Autotest? · Any feedback? Reach out in #autotest
What does this PR do?
Adds Jest instrumentation hooks for the resolved
build/index.jsload shape ofjest-environment-node,jest-environment-jsdom, and@jest/test-sequencer.The existing package-root hooks are kept. This change makes the instrumentation cover both ways Jest can load these packages: as the public package name and as the concrete build file Jest resolved internally.
It also adds a Jest integration regression that copies
jest-environment-nodeinto an isolatednode_modulestree and points Jest at that absolutebuild/index.jsfile. That reproduces the important pnpm-like condition: Jest successfully loads the environment by absolute file path, but normal package-root resolution points somewhere else.Motivation
This is not primarily about users importing Jest internals directly. A normal Jest configuration can name the environment or sequencer in the usual way, then Jest resolves that package to an absolute file path and loads the resolved build file.
In the pnpm workspace validation that exposed this bug, Jest 30 resolved the test environment and test sequencer to absolute
build/index.jsfiles. With pnpm's store/symlink layout, the require hook classified those absolute loads as package subpaths likejest-environment-node/build/index.jsinstead of package-root loads likejest-environment-node. Because the instrumentation only registered package-root hooks for those modules, the environment wrapper did not attach.That left Test Optimization with session/module events, but no suite/test events. The fix is to instrument both package-root and resolved build-file module-load shapes.