Skip to content

[test optimization] Detect and warn about new tests with dynamic names#7841

Merged
juan-fernandez merged 7 commits intomasterfrom
juan-fernandez/jest-dynamic-name-detection
Mar 30, 2026
Merged

[test optimization] Detect and warn about new tests with dynamic names#7841
juan-fernandez merged 7 commits intomasterfrom
juan-fernandez/jest-dynamic-name-detection

Conversation

@juan-fernandez
Copy link
Copy Markdown
Collaborator

@juan-fernandez juan-fernandez commented Mar 23, 2026

What does this PR do?

Detect tests flagged as "new" whose names contain patterns that are almost certainly runtime-generated (unix timestamps, UUIDs, ISO dates, random localhost ports).
Consolidate ignored-failures and dynamic-name warnings into a single session-end "Datadog Test Optimization" summary banner.

Motivation

Let the user know about issues with new test detection

Detect tests flagged as "new" whose names contain patterns that are
almost certainly runtime-generated (unix timestamps, UUIDs, ISO dates,
random localhost ports). Detection runs in the worker via _onAddTest
and flows to the main process via two paths:
- runInBand: shared newTestsWithDynamicNames Set works directly
- parallel workers: _dd.has_dynamic_name span tag travels via
  worker-report:trace; onMessageWrapper extracts it

Consolidate ignored-failures and dynamic-name warnings into a single
session-end "Datadog Test Optimization" summary banner.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Mar 23, 2026

Overall package size

Self size: 5.06 MB
Deduped: 5.9 MB
No deduping: 5.9 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

@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 23, 2026

Codecov Report

❌ Patch coverage is 10.95890% with 65 lines in your changes missing coverage. Please review.
✅ Project coverage is 74.51%. Comparing base (a6f3a6f) to head (879fd82).
⚠️ Report is 25 commits behind head on master.

Files with missing lines Patch % Lines
packages/datadog-instrumentations/src/jest.js 4.16% 23 Missing ⚠️
packages/dd-trace/src/plugins/util/test.js 9.52% 19 Missing ⚠️
packages/datadog-instrumentations/src/vitest.js 28.57% 5 Missing ⚠️
packages/datadog-plugin-playwright/src/index.js 0.00% 4 Missing ⚠️
...ckages/datadog-instrumentations/src/mocha/utils.js 40.00% 3 Missing ⚠️
...ackages/datadog-instrumentations/src/playwright.js 25.00% 3 Missing ⚠️
...ackages/datadog-instrumentations/src/mocha/main.js 0.00% 2 Missing ⚠️
packages/datadog-plugin-jest/src/index.js 0.00% 2 Missing ⚠️
packages/datadog-plugin-mocha/src/index.js 0.00% 2 Missing ⚠️
packages/datadog-plugin-vitest/src/index.js 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #7841      +/-   ##
==========================================
- Coverage   80.48%   74.51%   -5.98%     
==========================================
  Files         749      768      +19     
  Lines       32457    35733    +3276     
==========================================
+ Hits        26124    26626     +502     
- Misses       6333     9107    +2774     
Flag Coverage Δ
aiguard-macos 39.23% <ø> (-0.02%) ⬇️
aiguard-ubuntu 39.35% <ø> (-0.02%) ⬇️
aiguard-windows 39.02% <ø> (-0.05%) ⬇️
apm-capabilities-tracing-macos 49.04% <6.45%> (+0.02%) ⬆️
apm-capabilities-tracing-ubuntu 48.95% <6.45%> (-0.10%) ⬇️
apm-capabilities-tracing-windows 48.80% <6.45%> (+0.01%) ⬆️
apm-integrations-child-process 38.56% <ø> (-0.03%) ⬇️
apm-integrations-couchbase-18 37.36% <ø> (-0.07%) ⬇️
apm-integrations-couchbase-eol 37.71% <ø> (-0.21%) ⬇️
apm-integrations-oracledb 37.69% <ø> (-0.06%) ⬇️
appsec-express 55.17% <ø> (-0.09%) ⬇️
appsec-fastify 51.52% <ø> (-0.07%) ⬇️
appsec-graphql 51.69% <ø> (-0.07%) ⬇️
appsec-kafka 44.31% <ø> (-0.07%) ⬇️
appsec-ldapjs 43.94% <ø> (-0.07%) ⬇️
appsec-lodash 43.54% <ø> (-0.09%) ⬇️
appsec-macos 58.10% <14.28%> (-0.16%) ⬇️
appsec-mongodb-core 48.70% <ø> (-0.07%) ⬇️
appsec-mongoose 49.36% <ø> (-0.07%) ⬇️
appsec-mysql 50.79% <ø> (-0.07%) ⬇️
appsec-node-serialize 43.12% <ø> (-0.06%) ⬇️
appsec-passport 47.55% <ø> (-0.07%) ⬇️
appsec-postgres 50.53% <ø> (-0.07%) ⬇️
appsec-sourcing 42.37% <ø> (-0.24%) ⬇️
appsec-stripe 44.55% <ø> (?)
appsec-template 43.29% <ø> (-0.06%) ⬇️
appsec-ubuntu 58.18% <14.28%> (-0.15%) ⬇️
appsec-windows 57.93% <14.28%> (-0.17%) ⬇️
instrumentations-instrumentation-bluebird 32.20% <ø> (-0.17%) ⬇️
instrumentations-instrumentation-body-parser 40.46% <ø> (-0.07%) ⬇️
instrumentations-instrumentation-child_process 37.90% <ø> (-0.04%) ⬇️
instrumentations-instrumentation-cookie-parser 34.23% <ø> (-0.10%) ⬇️
instrumentations-instrumentation-express 34.55% <ø> (-0.10%) ⬇️
instrumentations-instrumentation-express-mongo-sanitize 34.36% <ø> (-0.10%) ⬇️
instrumentations-instrumentation-express-session 40.10% <ø> (-0.07%) ⬇️
instrumentations-instrumentation-fs 31.89% <ø> (-0.11%) ⬇️
instrumentations-instrumentation-generic-pool 29.34% <14.28%> (-0.13%) ⬇️
instrumentations-instrumentation-http 39.81% <ø> (+<0.01%) ⬆️
instrumentations-instrumentation-knex 32.27% <ø> (-0.11%) ⬇️
instrumentations-instrumentation-mongoose 33.39% <ø> (-0.10%) ⬇️
instrumentations-instrumentation-multer 40.21% <ø> (-0.07%) ⬇️
instrumentations-instrumentation-mysql2 38.24% <ø> (-0.07%) ⬇️
instrumentations-instrumentation-passport 43.98% <ø> (-0.07%) ⬇️
instrumentations-instrumentation-passport-http 43.66% <ø> (-0.07%) ⬇️
instrumentations-instrumentation-passport-local 44.19% <ø> (-0.07%) ⬇️
instrumentations-instrumentation-pg 37.68% <ø> (-0.07%) ⬇️
instrumentations-instrumentation-promise 32.13% <ø> (-0.18%) ⬇️
instrumentations-instrumentation-promise-js 32.14% <ø> (-0.18%) ⬇️
instrumentations-instrumentation-q 32.18% <ø> (-0.18%) ⬇️
instrumentations-instrumentation-url 32.10% <ø> (-0.18%) ⬇️
instrumentations-instrumentation-when 32.15% <ø> (-0.18%) ⬇️
llmobs-ai 42.37% <ø> (+0.11%) ⬆️
llmobs-anthropic 40.39% <ø> (+0.08%) ⬆️
llmobs-bedrock 39.18% <ø> (-0.06%) ⬇️
llmobs-google-genai 39.72% <ø> (-0.06%) ⬇️
llmobs-langchain 40.08% <ø> (-0.05%) ⬇️
llmobs-openai 43.90% <ø> (-0.07%) ⬇️
llmobs-vertex-ai 39.97% <ø> (-0.07%) ⬇️
platform-core 31.47% <ø> (ø)
platform-esbuild 34.42% <ø> (ø)
platform-instrumentations-misc 48.41% <ø> (ø)
platform-shimmer 37.56% <ø> (ø)
platform-unit-guardrails 32.89% <ø> (ø)
platform-webpack 20.02% <12.69%> (?)
plugins-azure-durable-functions 25.74% <ø> (ø)
plugins-azure-event-hubs 25.90% <ø> (ø)
plugins-azure-service-bus 25.26% <ø> (ø)
plugins-bullmq 44.27% <ø> (+<0.01%) ⬆️
plugins-cassandra 37.73% <ø> (-0.20%) ⬇️
plugins-cookie 26.96% <ø> (ø)
plugins-cookie-parser 26.75% <ø> (ø)
plugins-crypto 26.73% <ø> (ø)
plugins-dd-trace-api 38.26% <ø> (-0.06%) ⬇️
plugins-express-mongo-sanitize 26.89% <ø> (ø)
plugins-express-session 26.70% <ø> (ø)
plugins-fastify 42.18% <ø> (-0.07%) ⬇️
plugins-fetch 38.35% <ø> (-0.02%) ⬇️
plugins-fs 38.59% <ø> (-0.07%) ⬇️
plugins-generic-pool 25.94% <ø> (ø)
plugins-google-cloud-pubsub 45.49% <ø> (+0.06%) ⬆️
plugins-grpc 40.85% <ø> (-0.07%) ⬇️
plugins-handlebars 26.94% <ø> (ø)
plugins-hapi 40.10% <ø> (-0.07%) ⬇️
plugins-hono 40.43% <ø> (+0.01%) ⬆️
plugins-ioredis 38.40% <ø> (-0.07%) ⬇️
plugins-knex 26.57% <ø> (ø)
plugins-langgraph 38.45% <ø> (-0.03%) ⬇️
plugins-ldapjs 24.43% <ø> (ø)
plugins-light-my-request 26.30% <ø> (ø)
plugins-limitd-client 32.48% <ø> (-0.17%) ⬇️
plugins-lodash 26.03% <ø> (ø)
plugins-mariadb 39.44% <ø> (-0.07%) ⬇️
plugins-memcached 38.14% <ø> (-0.04%) ⬇️
plugins-microgateway-core 39.17% <ø> (-0.07%) ⬇️
plugins-moleculer 40.46% <ø> (-0.07%) ⬇️
plugins-mongodb 39.11% <ø> (-0.07%) ⬇️
plugins-mongodb-core 38.95% <ø> (-0.07%) ⬇️
plugins-mongoose 38.83% <ø> (-0.07%) ⬇️
plugins-multer 26.70% <ø> (ø)
plugins-mysql 39.14% <ø> (-0.07%) ⬇️
plugins-mysql2 39.23% <ø> (-0.07%) ⬇️
plugins-node-serialize 27.00% <ø> (ø)
plugins-opensearch 37.59% <ø> (-0.03%) ⬇️
plugins-passport-http 26.76% <ø> (ø)
plugins-postgres 35.48% <14.28%> (-0.11%) ⬇️
plugins-process 26.73% <ø> (ø)
plugins-pug 26.96% <ø> (ø)
plugins-redis 38.86% <ø> (-0.06%) ⬇️
plugins-router 43.03% <ø> (+0.06%) ⬆️
plugins-sequelize 25.55% <ø> (ø)
plugins-test-and-upstream-amqp10 38.45% <ø> (-0.07%) ⬇️
plugins-test-and-upstream-amqplib 44.15% <ø> (+0.26%) ⬆️
plugins-test-and-upstream-apollo 39.08% <ø> (-0.06%) ⬇️
plugins-test-and-upstream-avsc 38.52% <ø> (-0.10%) ⬇️
plugins-test-and-upstream-bunyan 33.80% <ø> (-0.10%) ⬇️
plugins-test-and-upstream-connect 40.75% <ø> (-0.07%) ⬇️
plugins-test-and-upstream-graphql 40.10% <ø> (-0.01%) ⬇️
plugins-test-and-upstream-koa 40.34% <ø> (-0.07%) ⬇️
plugins-test-and-upstream-protobufjs 38.75% <ø> (-0.10%) ⬇️
plugins-test-and-upstream-rhea 44.18% <ø> (+0.15%) ⬆️
plugins-undici 39.07% <ø> (-0.06%) ⬇️
plugins-url 26.73% <ø> (ø)
plugins-valkey 38.11% <ø> (-0.03%) ⬇️
plugins-vm 26.73% <ø> (ø)
plugins-winston 33.99% <ø> (-0.10%) ⬇️
plugins-ws 41.93% <ø> (+0.03%) ⬆️
profiling-macos 40.47% <ø> (-0.09%) ⬇️
profiling-ubuntu 40.59% <ø> (-0.52%) ⬇️
profiling-windows 42.15% <ø> (-0.07%) ⬇️
serverless-azure-functions-client 25.62% <ø> (ø)
serverless-azure-functions-eventhubs 25.62% <ø> (ø)
serverless-azure-functions-servicebus 25.62% <ø> (ø)

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

☔ View full report in Codecov by Sentry.
📢 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.

@pr-commenter
Copy link
Copy Markdown

pr-commenter Bot commented Mar 23, 2026

Benchmarks

Benchmark execution time: 2026-03-30 10:47:19

Comparing candidate commit 879fd82 in PR branch juan-fernandez/jest-dynamic-name-detection with baseline commit a6f3a6f in branch master.

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

juan-fernandez and others added 4 commits March 23, 2026 11:55
Add a test fixture with a dynamic test name (Date.now() in template
literal) and an integration test that verifies:
- The _dd.has_dynamic_name tag is set on tests with dynamic names
- Non-dynamic new tests do not get the tag
- The session-end warning message is logged

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Replace hardcoded '_dd.has_dynamic_name' string with a constant defined
in packages/dd-trace/src/plugins/util/test.js, consistent with how
other test tags (TEST_IS_NEW, TEST_IS_MODIFIED, etc.) are defined.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…me test cases

Use TEST_SUITE and TEST_NAME constants instead of literal strings in
collectDynamicNamesFromTraces. Add test cases for all four dynamic
name patterns: timestamp, localhost port, UUID, and ISO date. Update
integration test to verify all four patterns are detected.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@juan-fernandez juan-fernandez changed the title feat(jest): detect and warn about new tests with dynamic names [test optimization] Detect and warn about new tests with dynamic names in jest Mar 25, 2026
@juan-fernandez juan-fernandez marked this pull request as ready for review March 25, 2026 09:48
@juan-fernandez juan-fernandez requested a review from a team as a code owner March 25, 2026 09:48
@datadog-prod-us1-6
Copy link
Copy Markdown

datadog-prod-us1-6 Bot commented Mar 25, 2026

✅ Tests

🎉 All green!

❄️ No new flaky tests detected
🧪 All tests passed

🎯 Code Coverage (details)
Patch Coverage: 10.67%
Overall Coverage: 68.95%

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 879fd82 | Docs | Datadog PR Page | Was this helpful? React with 👍/👎 or give us feedback!

@juan-fernandez juan-fernandez marked this pull request as draft March 25, 2026 09:48
@juan-fernandez juan-fernandez changed the title [test optimization] Detect and warn about new tests with dynamic names in jest [test optimization] Detect and warn about new tests with dynamic names Mar 25, 2026
The dynamic-name-test.js fixture was placed in the default playwright
testDir, causing it to be picked up by all existing playwright
integration tests and inflating test/suite counts.

Moves it to a dedicated playwright-tests-dynamic/ directory and updates
the integration test to point TEST_DIR at that directory.

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
@juan-fernandez juan-fernandez marked this pull request as ready for review March 30, 2026 10:53
@juan-fernandez juan-fernandez merged commit 51e9264 into master Mar 30, 2026
788 checks passed
@juan-fernandez juan-fernandez deleted the juan-fernandez/jest-dynamic-name-detection branch March 30, 2026 14:00
@dd-octo-sts dd-octo-sts Bot mentioned this pull request Mar 31, 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