Skip to content

fix(jest): instrument resolved build file loads#9211

Merged
juan-fernandez merged 2 commits into
masterfrom
juan-fernandez/fix-jest-absolute-build-index-hooks
Jul 6, 2026
Merged

fix(jest): instrument resolved build file loads#9211
juan-fernandez merged 2 commits into
masterfrom
juan-fernandez/fix-jest-absolute-build-index-hooks

Conversation

@juan-fernandez

@juan-fernandez juan-fernandez commented Jul 3, 2026

Copy link
Copy Markdown
Collaborator

What does this PR do?

Adds Jest instrumentation hooks for the resolved build/index.js load shape of jest-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-node into an isolated node_modules tree and points Jest at that absolute build/index.js file. 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.js files. With pnpm's store/symlink layout, the require hook classified those absolute loads as package subpaths like jest-environment-node/build/index.js instead of package-root loads like jest-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.

@dd-octo-sts

dd-octo-sts Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Overall package size

Self size: 6.53 MB
Deduped: 7.19 MB
No deduping: 7.19 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

@juan-fernandez juan-fernandez changed the title fix(jest): instrument build index module loads fix(jest): instrument resolved build file loads Jul 3, 2026
@datadog-datadog-prod-us1

datadog-datadog-prod-us1 Bot commented Jul 3, 2026

Copy link
Copy Markdown

Tests

🎉 All green!

🧪 All tests passed
❄️ No new flaky tests detected

🎯 Code Coverage (details)
Patch Coverage: 100.00%
Overall Coverage: 87.86% (-0.00%)

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: fc2af13 | Docs | Datadog PR Page | Give us feedback!

@juan-fernandez

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🚀

Reviewed commit: fc4ce5691d

ℹ️ 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".

@pr-commenter

pr-commenter Bot commented Jul 3, 2026

Copy link
Copy Markdown

Benchmarks

Benchmark execution time: 2026-07-06 12:18:51

Comparing candidate commit fc2af13 in PR branch juan-fernandez/fix-jest-absolute-build-index-hooks with baseline commit 02cb1a1 in branch master.

📊 Benchmarking dashboard

Found 0 performance improvements and 0 performance regressions! Performance is the same for 2254 metrics, 32 unstable metrics.

Explanation

This is an A/B test comparing a candidate commit's performance against that of a baseline commit. Performance changes are noted in the tables below as:

  • 🟩 = significantly better candidate vs. baseline
  • 🟥 = significantly worse candidate vs. baseline

We compute a confidence interval (CI) over the relative difference of means between metrics from the candidate and baseline commits, considering the baseline as the reference.

If the CI is entirely outside the configured SIGNIFICANT_IMPACT_THRESHOLD (or the deprecated UNCONFIDENCE_THRESHOLD), the change is considered significant.

Feel free to reach out to #apm-benchmarking-platform on Slack if you have any questions.

More details about the CI and significant changes

You can imagine this CI as a range of values that is likely to contain the true difference of means between the candidate and baseline commits.

CIs of the difference of means are often centered around 0%, because often changes are not that big:

---------------------------------(------|---^--------)-------------------------------->
                              -0.6%    0%  0.3%     +1.2%
                                 |          |        |
         lower bound of the CI --'          |        |
sample mean (center of the CI) -------------'        |
         upper bound of the CI ----------------------'

As described above, a change is considered significant if the CI is entirely outside the configured SIGNIFICANT_IMPACT_THRESHOLD (or the deprecated UNCONFIDENCE_THRESHOLD).

For instance, for an execution time metric, this confidence interval indicates a significantly worse performance:

----------------------------------------|---------|---(---------^---------)---------->
                                       0%        1%  1.3%      2.2%      3.1%
                                                  |   |         |         |
       significant impact threshold --------------'   |         |         |
                      lower bound of CI --------------'         |         |
       sample mean (center of the CI) --------------------------'         |
                      upper bound of CI ----------------------------------'

Unstable benchmarks

These benchmarks have a confidence interval too wide to call a change; treat them as noise rather than signal.

scenario:appsec-appsec-enabled-24

  • unstable execution_time [-188.282ms; +184.563ms] or [-7.148%; +7.007%]

scenario:appsec-appsec-enabled-26

  • unstable execution_time [-206.472ms; +209.073ms] or [-8.178%; +8.281%]

scenario:appsec-appsec-enabled-with-attacks-26

  • unstable execution_time [-158.130ms; +153.943ms] or [-5.485%; +5.340%]

scenario:appsec-control-20

  • unstable execution_time [-102.471ms; +125.532ms] or [-6.297%; +7.714%]

scenario:appsec-control-24

  • unstable execution_time [-105965.826µs; +107816.126µs] or [-8.735%; +8.888%]

scenario:appsec-control-26

  • unstable execution_time [-111828.999µs; +113065.066µs] or [-9.255%; +9.357%]

scenario:appsec-iast-no-vulnerability-control-20

  • unstable execution_time [-9.537ms; +16.825ms] or [-3.857%; +6.805%]

scenario:debugger-line-probe-with-snapshot-default-24

  • unstable cpu_user_time [-492.564ms; +306.934ms] or [-6.225%; +3.879%]
  • unstable instructions [-4221.0M instructions; +2558.1M instructions] or [-6.588%; +3.992%]

scenario:debugger-line-probe-with-snapshot-default-26

  • unstable cpu_user_time [-2847.153ms; +2927.482ms] or [-28.644%; +29.452%]
  • unstable execution_time [-2855.131ms; +2931.811ms] or [-26.850%; +27.571%]
  • unstable instructions [-25792.0M instructions; +26463.5M instructions] or [-31.160%; +31.971%]
  • unstable max_rss_usage [-8451.949KB; +8949.549KB] or [-5.242%; +5.550%]
  • unstable throughput [-653.708op/s; +621.849op/s] or [-20.776%; +19.764%]

scenario:debugger-line-probe-with-snapshot-minimal-24

  • unstable cpu_user_time [-2860.300ms; +4081.659ms] or [-29.451%; +42.027%]
  • unstable execution_time [-2895.471ms; +4129.165ms] or [-27.828%; +39.685%]
  • unstable instructions [-23.8G instructions; +34.6G instructions] or [-29.928%; +43.548%]
  • unstable max_rss_usage [-10.211MB; +14.461MB] or [-6.335%; +8.972%]
  • unstable throughput [-1004.349op/s; +754.344op/s] or [-30.855%; +23.175%]

scenario:debugger-line-probe-with-snapshot-minimal-26

  • unstable cpu_user_time [-3488.195ms; +3719.911ms] or [-34.523%; +36.817%]
  • unstable execution_time [-3532.202ms; +3787.043ms] or [-32.762%; +35.125%]
  • unstable instructions [-30.6G instructions; +32.9G instructions] or [-36.146%; +38.779%]
  • unstable max_rss_usage [-10693.837KB; +11520.237KB] or [-6.614%; +7.125%]
  • unstable throughput [-741.343op/s; +732.847op/s] or [-23.646%; +23.375%]

scenario:debugger-line-probe-without-snapshot-26

  • unstable cpu_user_time [-1887.924ms; +617.933ms] or [-20.162%; +6.599%]
  • unstable execution_time [-1889.257ms; +622.735ms] or [-18.791%; +6.194%]
  • unstable instructions [-16.9G instructions; +5.5G instructions] or [-21.770%; +7.053%]
  • unstable throughput [-137.526op/s; +408.874op/s] or [-4.203%; +12.496%]

scenario:dogstatsd-with-tags-20

  • unstable cpu_user_time [-174.818ms; +432.924ms] or [-3.493%; +8.649%]
  • unstable execution_time [-175.721ms; +436.371ms] or [-3.460%; +8.592%]
  • unstable throughput [-149217.749op/s; +58664.712op/s] or [-9.033%; +3.551%]

scenario:test-optimization-large-suite-20

  • unstable max_rss_usage [-5303.651KB; +6969.985KB] or [-6.471%; +8.504%]

@codecov

codecov Bot commented Jul 3, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.63%. Comparing base (02cb1a1) to head (fc2af13).

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     
Flag Coverage Δ
aiguard 34.98% <ø> (-0.08%) ⬇️
aiguard-integration 41.98% <ø> (ø)
apm-bucket-0 34.84% <ø> (-0.08%) ⬇️
apm-bucket-1 40.51% <ø> (-0.07%) ⬇️
apm-bucket-2 37.50% <ø> (-0.07%) ⬇️
apm-capabilities-tracing 48.93% <ø> (ø)
apm-integrations-aerospike 33.13% <ø> (-0.08%) ⬇️
apm-integrations-confluentinc-kafka-javascript 40.03% <ø> (-0.17%) ⬇️
apm-integrations-couchbase 33.24% <ø> (-0.24%) ⬇️
apm-integrations-http 42.05% <ø> (-0.07%) ⬇️
apm-integrations-kafkajs 40.26% <ø> (-0.12%) ⬇️
apm-integrations-next 29.59% <ø> (-0.11%) ⬇️
apm-integrations-prisma 35.18% <ø> (-0.07%) ⬇️
apm-integrations-tedious 34.04% <ø> (-0.08%) ⬇️
appsec 57.91% <ø> (-0.07%) ⬇️
appsec-express_fastify_graphql 53.86% <ø> (-0.07%) ⬇️
appsec-integration 35.63% <80.00%> (+<0.01%) ⬆️
appsec-kafka_ldapjs_lodash 43.84% <ø> (+0.02%) ⬆️
appsec-mongodb-core_mongoose_mysql 48.90% <ø> (-0.06%) ⬇️
appsec-next 28.05% <80.00%> (-0.06%) ⬇️
appsec-node-serialize_passport_postgres 48.09% <ø> (-0.11%) ⬇️
appsec-sourcing_stripe_template 45.64% <ø> (-0.06%) ⬇️
debugger 44.63% <ø> (-0.05%) ⬇️
instrumentations-bucket-0 28.16% <ø> (-0.08%) ⬇️
instrumentations-bucket-1 37.57% <ø> (-0.07%) ⬇️
instrumentations-bucket-10 40.51% <ø> (-0.07%) ⬇️
instrumentations-bucket-11 27.96% <ø> (-0.08%) ⬇️
instrumentations-bucket-12 28.79% <ø> (-0.08%) ⬇️
instrumentations-bucket-13 27.79% <ø> (-0.08%) ⬇️
instrumentations-bucket-2 30.36% <ø> (-0.08%) ⬇️
instrumentations-bucket-3 36.06% <ø> (-0.08%) ⬇️
instrumentations-bucket-4 28.57% <ø> (-0.08%) ⬇️
instrumentations-bucket-5 36.42% <ø> (-0.07%) ⬇️
instrumentations-bucket-6 38.42% <ø> (-0.08%) ⬇️
instrumentations-bucket-7 36.07% <ø> (-0.16%) ⬇️
instrumentations-bucket-8 37.11% <ø> (-0.07%) ⬇️
instrumentations-bucket-9 39.61% <ø> (-0.07%) ⬇️
instrumentations-instrumentation-couchbase 46.48% <ø> (ø)
instrumentations-integration-esbuild 24.48% <80.00%> (+<0.01%) ⬆️
llmobs-ai_anthropic_bedrock 39.68% <ø> (-0.07%) ⬇️
llmobs-google-genai_langchain_vertex-ai 36.98% <ø> (-0.06%) ⬇️
llmobs-openai 39.74% <ø> (-0.07%) ⬇️
llmobs-sdk 43.59% <ø> (-0.08%) ⬇️
master-coverage 93.63% <100.00%> (?)
openfeature 37.94% <ø> (ø)
openfeature-unit 50.47% <ø> (ø)
platform-core_esbuild_instrumentations-misc 22.93% <80.00%> (+<0.01%) ⬆️
platform-integration 47.58% <ø> (ø)
platform-shimmer_unit-guardrails_webpack 18.45% <80.00%> (+0.01%) ⬆️
plugins-bucket-0 36.52% <ø> (-0.07%) ⬇️
plugins-bucket-1 39.78% <ø> (ø)
plugins-bucket-11 38.63% <ø> (-0.08%) ⬇️
plugins-bucket-17 39.22% <ø> (-0.07%) ⬇️
plugins-bucket-18 42.17% <ø> (-0.07%) ⬇️
plugins-bucket-19 39.97% <ø> (-0.07%) ⬇️
plugins-bucket-20 43.43% <ø> (-0.07%) ⬇️
plugins-bucket-4 37.88% <ø> (-0.07%) ⬇️
plugins-bullmq_cassandra_cookie 39.93% <ø> (-0.07%) ⬇️
plugins-cookie-parser_crypto_dd-trace-api 33.22% <ø> (-0.08%) ⬇️
plugins-fetch_fs_generic-pool 36.21% <ø> (-0.08%) ⬇️
plugins-google-cloud-pubsub_grpc_handlebars 43.08% <ø> (-0.07%) ⬇️
plugins-hapi_hono_ioredis 37.94% <ø> (-0.07%) ⬇️
plugins-jest_knex_langgraph 32.61% <ø> (-0.08%) ⬇️
plugins-ldapjs_light-my-request_limitd-client 27.86% <ø> (-0.08%) ⬇️
plugins-lodash_mariadb_memcached 35.17% <ø> (-0.08%) ⬇️
plugins-mongodb_mongodb-core_mongoose 36.46% <ø> (-0.07%) ⬇️
plugins-multer_mysql_mysql2 35.15% <ø> (-0.08%) ⬇️
plugins-nats_node-serialize_opensearch 37.31% <ø> (-0.08%) ⬇️
plugins-passport-http_pino_postgres 35.53% <ø> (-0.08%) ⬇️
plugins-process_pug_redis 34.26% <ø> (-0.08%) ⬇️
plugins-undici_url_valkey 36.03% <ø> (-0.07%) ⬇️
plugins-vm_winston_ws 37.72% <ø> (-0.08%) ⬇️
profiling 43.81% <ø> (-0.07%) ⬇️
serverless-aws-sdk-aws-sdk 33.32% <ø> (-0.07%) ⬇️
serverless-aws-sdk-bedrockruntime 32.19% <ø> (-0.07%) ⬇️
serverless-aws-sdk-client 37.16% <ø> (ø)
serverless-aws-sdk-dynamodb 34.19% <ø> (-0.02%) ⬇️
serverless-aws-sdk-eventbridge 27.36% <ø> (-0.07%) ⬇️
serverless-aws-sdk-kinesis 37.55% <ø> (-0.07%) ⬇️
serverless-aws-sdk-lambda 34.64% <ø> (-0.07%) ⬇️
serverless-aws-sdk-s3 32.63% <ø> (-0.07%) ⬇️
serverless-aws-sdk-serverless-peer-service 39.74% <ø> (+0.01%) ⬆️
serverless-aws-sdk-sns 38.40% <ø> (-0.21%) ⬇️
serverless-aws-sdk-sqs 38.14% <ø> (-0.07%) ⬇️
serverless-aws-sdk-stepfunctions 33.22% <ø> (-0.07%) ⬇️
serverless-aws-sdk-util 47.95% <ø> (ø)
serverless-bucket-0 39.63% <ø> (ø)
serverless-lambda 34.34% <ø> (-0.09%) ⬇️
test-optimization-cucumber 52.55% <ø> (+0.11%) ⬆️
test-optimization-cypress 49.73% <ø> (+0.17%) ⬆️
test-optimization-jest 55.70% <100.00%> (+0.05%) ⬆️
test-optimization-mocha 53.62% <ø> (+0.08%) ⬆️
test-optimization-playwright-playwright-atr 43.53% <ø> (+0.08%) ⬆️
test-optimization-playwright-playwright-efd 43.82% <ø> (+0.08%) ⬆️
test-optimization-playwright-playwright-final-status 43.94% <ø> (+0.08%) ⬆️
test-optimization-playwright-playwright-impacted-tests 43.36% <ø> (ø)
test-optimization-playwright-playwright-reporting 43.47% <ø> (+0.08%) ⬆️
test-optimization-playwright-playwright-test-management 44.94% <ø> (+0.08%) ⬆️
test-optimization-playwright-playwright-test-span 44.73% <ø> (+0.08%) ⬆️
test-optimization-selenium 45.50% <100.00%> (+0.07%) ⬆️
test-optimization-testopt 46.82% <100.00%> (+0.09%) ⬆️
test-optimization-vitest 52.18% <ø> (-0.52%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@juan-fernandez

Copy link
Copy Markdown
Collaborator Author

/datadog autotest review

@juan-fernandez
juan-fernandez marked this pull request as ready for review July 6, 2026 08:41
@juan-fernandez
juan-fernandez requested a review from a team as a code owner July 6, 2026 08:41
@juan-fernandez
juan-fernandez force-pushed the juan-fernandez/fix-jest-absolute-build-index-hooks branch from fc4ce56 to 7a8f7c1 Compare July 6, 2026 08:41
@juan-fernandez
juan-fernandez requested a review from a team as a code owner July 6, 2026 08:41
@juan-fernandez
juan-fernandez requested review from crysmags and removed request for a team July 6, 2026 08:41
@juan-fernandez
juan-fernandez force-pushed the juan-fernandez/fix-jest-absolute-build-index-hooks branch from 7a8f7c1 to 372df25 Compare July 6, 2026 08:46
@juan-fernandez
juan-fernandez force-pushed the juan-fernandez/fix-jest-absolute-build-index-hooks branch from 372df25 to 32a3d8b Compare July 6, 2026 08:50

@datadog-datadog-prod-us1 datadog-datadog-prod-us1 Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Datadog Autotest: PASS

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.

Was this helpful? React 👍 or 👎

📊 Validated against 3 scenarios · Open Bits AI session

🤖 Datadog Autotest · Commit fc4ce56 · What is Autotest? · Any feedback? Reach out in #autotest

@juan-fernandez
juan-fernandez merged commit d4687d7 into master Jul 6, 2026
806 of 808 checks passed
@juan-fernandez
juan-fernandez deleted the juan-fernandez/fix-jest-absolute-build-index-hooks branch July 6, 2026 12:33
This was referenced Jul 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants