Skip to content

test: do not hide mocha errors#8147

Merged
BridgeAR merged 3 commits intomasterfrom
BridgeAR/2026-04-28-louder-mocha-hook-errors
Apr 29, 2026
Merged

test: do not hide mocha errors#8147
BridgeAR merged 3 commits intomasterfrom
BridgeAR/2026-04-28-louder-mocha-hook-errors

Conversation

@BridgeAR
Copy link
Copy Markdown
Member

If a after* hook fails after a failure in a before* hook or the test, the after hook error is going to be read first and tears down the test runner. This causes the actual error not to be visible anymore.

This surfaces these again by hooking into mocha internals and ignoring the after* errors, if it comes after a former error. That way we know what actually fails.

Downside is not knowing about teardown issues that are in addition to former issues, while that is in almost all cases not important.

Hiding also seemed better than logging both to let us focus on the main problem area.

If a after* hook fails after a failure in a before* hook or the test,
the after hook error is going to be read first and tears down the
test runner. This causes the actual error not to be visible anymore.

This surfaces these again by hooking into mocha internals and
ignoring the after* errors, if it comes after a former error. That
way we know what actually fails.

Downside is not knowing about teardown issues that are in addition
to former issues, while that is in almost all cases not important.

Hiding also seemed better than logging both to let us focus on the
main problem area.
@BridgeAR BridgeAR requested a review from a team as a code owner April 28, 2026 18:52
@datadog-datadog-prod-us1
Copy link
Copy Markdown

datadog-datadog-prod-us1 Bot commented Apr 28, 2026

Tests

🎉 All green!

❄️ No new flaky tests detected
🧪 All tests passed

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

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8981cbf87d

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread packages/dd-trace/test/setup/mocha-hooks.js Outdated
Comment thread packages/dd-trace/test/setup/mocha-hooks.js Outdated
@pr-commenter
Copy link
Copy Markdown

pr-commenter Bot commented Apr 28, 2026

Benchmarks

Benchmark execution time: 2026-04-29 12:35:51

Comparing candidate commit d053029 in PR branch BridgeAR/2026-04-28-louder-mocha-hook-errors with baseline commit 8fc99d0 in branch master.

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

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 28, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 77.19%. Comparing base (8fc99d0) to head (d053029).
⚠️ Report is 22 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #8147      +/-   ##
==========================================
+ Coverage   73.82%   77.19%   +3.37%     
==========================================
  Files         784      813      +29     
  Lines       36369    37659    +1290     
==========================================
+ Hits        26849    29071    +2222     
+ Misses       9520     8588     -932     
Flag Coverage Δ
aiguard-macos 35.82% <ø> (-0.65%) ⬇️
aiguard-ubuntu 35.93% <ø> (-0.65%) ⬇️
aiguard-windows 35.73% <ø> (-0.65%) ⬇️
apm-capabilities-tracing-macos 48.20% <ø> (+0.03%) ⬆️
apm-capabilities-tracing-ubuntu-active 48.23% <ø> (+0.04%) ⬆️
apm-capabilities-tracing-ubuntu-latest 48.20% <ø> (+0.03%) ⬆️
apm-capabilities-tracing-ubuntu-maintenance 48.23% <ø> (+0.04%) ⬆️
apm-capabilities-tracing-ubuntu-oldest 48.22% <ø> (+0.03%) ⬆️
apm-capabilities-tracing-windows 47.85% <ø> (-0.15%) ⬇️
apm-integrations-aerospike-18-gte.5.2.0 34.97% <ø> (?)
apm-integrations-aerospike-20-gte.5.5.0 34.99% <ø> (?)
apm-integrations-aerospike-22-gte.5.12.1 34.99% <ø> (?)
apm-integrations-aerospike-22-gte.6.0.0 34.99% <ø> (?)
apm-integrations-aerospike-eol- 34.89% <ø> (?)
apm-integrations-child-process 36.15% <ø> (+0.02%) ⬆️
apm-integrations-confluentinc-kafka-javascript-18 41.84% <ø> (?)
apm-integrations-confluentinc-kafka-javascript-20 41.86% <ø> (?)
apm-integrations-confluentinc-kafka-javascript-22 41.86% <ø> (?)
apm-integrations-confluentinc-kafka-javascript-24 41.79% <ø> (?)
apm-integrations-couchbase-18 35.16% <ø> (+0.03%) ⬆️
apm-integrations-couchbase-eol 35.24% <ø> (+0.05%) ⬆️
apm-integrations-dns 35.00% <ø> (?)
apm-integrations-elasticsearch 35.56% <ø> (?)
apm-integrations-http-latest 42.99% <ø> (?)
apm-integrations-http-maintenance 43.05% <ø> (?)
apm-integrations-http-oldest 43.06% <ø> (?)
apm-integrations-http2 40.35% <ø> (?)
apm-integrations-kafkajs-latest 41.72% <ø> (?)
apm-integrations-kafkajs-oldest 41.78% <ø> (?)
apm-integrations-net 35.67% <ø> (?)
apm-integrations-next-11.1.4 29.46% <ø> (?)
apm-integrations-next-13.2.0 31.29% <ø> (?)
apm-integrations-next-gte.10.2.0.and.lt.11 23.33% <ø> (?)
apm-integrations-next-gte.11.0.0.and.lt.13 31.30% <ø> (?)
apm-integrations-next-gte.13.0.0.and.lt.14 31.54% <ø> (?)
apm-integrations-next-gte.14.0.0.and.lte.14.2.6 31.36% <ø> (?)
apm-integrations-next-gte.14.2.7.and.lt.15 31.36% <ø> (?)
apm-integrations-next-gte.15.0.0 31.42% <ø> (?)
apm-integrations-oracledb ?
apm-integrations-prisma-18-gte.6.16.0.and.lt.7.0.0 35.53% <ø> (?)
apm-integrations-prisma-latest-all 35.85% <ø> (?)
apm-integrations-sharedb 34.58% <ø> (?)
apm-integrations-tedious 35.14% <ø> (?)
appsec-express 52.78% <ø> (-0.03%) ⬇️
appsec-fastify 49.26% <ø> (-0.02%) ⬇️
appsec-graphql 49.44% <ø> (-0.12%) ⬇️
appsec-kafka 42.08% <ø> (+0.04%) ⬆️
appsec-ldapjs 41.31% <ø> (-0.08%) ⬇️
appsec-lodash 41.42% <ø> (+0.01%) ⬆️
appsec-macos 56.79% <ø> (-0.04%) ⬇️
appsec-mongodb-core 45.69% <ø> (-0.01%) ⬇️
appsec-mongoose 46.58% <ø> (+<0.01%) ⬆️
appsec-mysql 48.75% <ø> (-0.01%) ⬇️
appsec-next-latest-11.1.4 29.61% <ø> (?)
appsec-next-latest-13.2.0 31.50% <ø> (?)
appsec-next-latest-gte.10.2.0.and.lt.11 31.60% <ø> (?)
appsec-next-latest-gte.11.0.0.and.lt.13 31.48% <ø> (?)
appsec-next-latest-gte.13.0.0.and.lt.14 31.68% <ø> (?)
appsec-next-latest-gte.14.0.0.and.lte.14.2.6 31.52% <ø> (?)
appsec-next-latest-gte.14.2.7.and.lt.15 31.52% <ø> (?)
appsec-next-latest-gte.15.0.0 31.52% <ø> (?)
appsec-next-oldest-11.1.4 29.62% <ø> (?)
appsec-next-oldest-13.2.0 31.73% <ø> (?)
appsec-next-oldest-gte.10.2.0.and.lt.11 31.76% <ø> (?)
appsec-next-oldest-gte.11.0.0.and.lt.13 31.50% <ø> (?)
appsec-next-oldest-gte.13.0.0.and.lt.14 31.93% <ø> (?)
appsec-next-oldest-gte.14.0.0.and.lte.14.2.6 31.77% <ø> (?)
appsec-next-oldest-gte.14.2.7.and.lt.15 31.77% <ø> (?)
appsec-next-oldest-gte.15.0.0 31.77% <ø> (?)
appsec-node-serialize 40.60% <ø> (+0.01%) ⬆️
appsec-passport 44.59% <ø> (-0.01%) ⬇️
appsec-postgres 48.34% <ø> (-0.01%) ⬇️
appsec-sourcing 40.09% <ø> (+<0.01%) ⬆️
appsec-stripe 42.32% <ø> (+<0.01%) ⬆️
appsec-template 40.77% <ø> (+0.01%) ⬆️
appsec-ubuntu 56.87% <ø> (-0.04%) ⬇️
appsec-windows 56.69% <ø> (-0.04%) ⬇️
debugger-ubuntu-active 62.13% <ø> (?)
debugger-ubuntu-latest 62.03% <ø> (?)
debugger-ubuntu-maintenance 62.13% <ø> (?)
debugger-ubuntu-oldest 62.23% <ø> (?)
instrumentations-instrumentation-bluebird 29.89% <ø> (+0.05%) ⬆️
instrumentations-instrumentation-body-parser 37.75% <ø> (+0.02%) ⬆️
instrumentations-instrumentation-child_process 35.53% <ø> (+0.03%) ⬆️
instrumentations-instrumentation-cookie-parser 31.82% <ø> (+0.04%) ⬆️
instrumentations-instrumentation-express 32.03% <ø> (+0.04%) ⬆️
instrumentations-instrumentation-express-mongo-sanitize 31.94% <ø> (+0.04%) ⬆️
instrumentations-instrumentation-express-session 37.38% <ø> (+0.02%) ⬆️
instrumentations-instrumentation-fs 29.57% <ø> (+0.05%) ⬆️
instrumentations-instrumentation-generic-pool 30.59% <ø> (+0.06%) ⬆️
instrumentations-instrumentation-http 37.00% <ø> (+0.03%) ⬆️
instrumentations-instrumentation-knex 29.86% <ø> (+0.05%) ⬆️
instrumentations-instrumentation-light-my-request 37.31% <ø> (+0.02%) ⬆️
instrumentations-instrumentation-mongoose 30.94% <ø> (+0.03%) ⬆️
instrumentations-instrumentation-multer 37.52% <ø> (+0.02%) ⬆️
instrumentations-instrumentation-mysql2 35.50% <ø> (+0.02%) ⬆️
instrumentations-instrumentation-passport 41.18% <ø> (-0.07%) ⬇️
instrumentations-instrumentation-passport-http 40.96% <ø> (+0.01%) ⬆️
instrumentations-instrumentation-passport-local 41.47% <ø> (+0.01%) ⬆️
instrumentations-instrumentation-pg 35.04% <ø> (+0.04%) ⬆️
instrumentations-instrumentation-promise 29.83% <ø> (+0.05%) ⬆️
instrumentations-instrumentation-promise-js 29.83% <ø> (+0.05%) ⬆️
instrumentations-instrumentation-q 29.86% <ø> (+0.05%) ⬆️
instrumentations-instrumentation-url 29.83% <ø> (+0.05%) ⬆️
instrumentations-instrumentation-when 29.84% <ø> (+0.05%) ⬆️
llmobs-ai 38.45% <ø> (+0.01%) ⬆️
llmobs-anthropic 37.95% <ø> (+0.04%) ⬆️
llmobs-bedrock 37.15% <ø> (+0.01%) ⬆️
llmobs-google-genai 37.59% <ø> (+0.01%) ⬆️
llmobs-langchain 37.10% <ø> (+0.03%) ⬆️
llmobs-openai 41.27% <ø> (+0.01%) ⬆️
llmobs-vertex-ai 37.77% <ø> (+0.08%) ⬆️
openfeature-unit-active 50.43% <ø> (?)
openfeature-unit-latest 50.28% <ø> (?)
openfeature-unit-maintenance 50.43% <ø> (?)
openfeature-unit-oldest 50.43% <ø> (?)
platform-core 36.53% <ø> (+6.49%) ⬆️
platform-esbuild 40.80% <ø> (+7.97%) ⬆️
platform-instrumentations-misc 31.35% <ø> (-8.67%) ⬇️
platform-shimmer 42.11% <ø> (+6.39%) ⬆️
platform-unit-guardrails 35.88% <ø> (+4.48%) ⬆️
platform-webpack 20.78% <ø> (+0.05%) ⬆️
plugins-azure-durable-functions 25.36% <ø> (ø)
plugins-azure-event-hubs 25.51% <ø> (ø)
plugins-azure-service-bus 24.92% <ø> (ø)
plugins-bullmq 40.69% <ø> (-0.07%) ⬇️
plugins-cassandra 35.26% <ø> (-0.07%) ⬇️
plugins-cookie 26.47% <ø> (ø)
plugins-cookie-parser 26.28% <ø> (ø)
plugins-crypto 27.32% <ø> (+1.62%) ⬆️
plugins-dd-trace-api 35.48% <ø> (+0.03%) ⬆️
plugins-express-mongo-sanitize 26.42% <ø> (ø)
plugins-express-session 26.24% <ø> (ø)
plugins-fastify 39.38% <ø> (+0.05%) ⬆️
plugins-fetch 35.88% <ø> (+0.03%) ⬆️
plugins-fs 35.76% <ø> (+0.02%) ⬆️
plugins-generic-pool 25.40% <ø> (ø)
plugins-google-cloud-pubsub 43.07% <ø> (+<0.01%) ⬆️
plugins-grpc 38.12% <ø> (+0.02%) ⬆️
plugins-handlebars 26.46% <ø> (ø)
plugins-hapi 37.37% <ø> (+0.03%) ⬆️
plugins-hono 37.61% <ø> (+0.02%) ⬆️
plugins-ioredis 35.81% <ø> (+0.03%) ⬆️
plugins-knex 26.14% <ø> (ø)
plugins-langgraph 35.15% <ø> (+0.03%) ⬆️
plugins-ldapjs 24.02% <ø> (ø)
plugins-light-my-request 25.88% <ø> (ø)
plugins-limitd-client 30.12% <ø> (+0.05%) ⬆️
plugins-lodash 25.47% <ø> (ø)
plugins-mariadb 36.68% <ø> (+0.03%) ⬆️
plugins-memcached 35.46% <ø> (+0.03%) ⬆️
plugins-microgateway-core 36.46% <ø> (+0.03%) ⬆️
plugins-modelcontextprotocol-sdk 34.39% <ø> (+0.03%) ⬆️
plugins-moleculer 38.15% <ø> (+0.02%) ⬆️
plugins-mongodb 36.76% <ø> (+0.17%) ⬆️
plugins-mongodb-core 36.28% <ø> (+0.06%) ⬆️
plugins-mongoose 36.13% <ø> (+0.03%) ⬆️
plugins-multer 26.24% <ø> (ø)
plugins-mysql 36.41% <ø> (-0.10%) ⬇️
plugins-mysql2 36.51% <ø> (+0.02%) ⬆️
plugins-node-serialize 26.51% <ø> (ø)
plugins-opensearch 35.12% <ø> (+0.02%) ⬆️
plugins-passport-http 26.30% <ø> (ø)
plugins-pino 31.92% <ø> (+0.04%) ⬆️
plugins-postgres 34.53% <ø> (+0.06%) ⬆️
plugins-process 27.32% <ø> (+1.62%) ⬆️
plugins-pug 26.47% <ø> (ø)
plugins-redis 36.01% <ø> (+0.03%) ⬆️
plugins-router 39.78% <ø> (-0.08%) ⬇️
plugins-sequelize 25.18% <ø> (ø)
plugins-test-and-upstream-amqp10 35.64% <ø> (+0.03%) ⬆️
plugins-test-and-upstream-amqplib 40.92% <ø> (+0.01%) ⬆️
plugins-test-and-upstream-apollo 36.62% <ø> (+0.03%) ⬆️
plugins-test-and-upstream-avsc 35.11% <ø> (-0.40%) ⬇️
plugins-test-and-upstream-bunyan 31.26% <ø> (+0.04%) ⬆️
plugins-test-and-upstream-connect 37.95% <ø> (+0.02%) ⬆️
plugins-test-and-upstream-graphql 37.29% <ø> (+0.02%) ⬆️
plugins-test-and-upstream-koa 37.56% <ø> (+0.02%) ⬆️
plugins-test-and-upstream-protobufjs 35.32% <ø> (-0.40%) ⬇️
plugins-test-and-upstream-rhea 41.00% <ø> (+0.01%) ⬆️
plugins-undici 36.62% <ø> (+0.03%) ⬆️
plugins-url 27.32% <ø> (+1.62%) ⬆️
plugins-valkey 35.49% <ø> (+0.03%) ⬆️
plugins-vm 27.32% <ø> (+1.62%) ⬆️
plugins-winston 31.74% <ø> (+0.20%) ⬆️
plugins-ws 39.08% <ø> (+0.02%) ⬆️
profiling-macos 40.69% <ø> (+2.77%) ⬆️
profiling-ubuntu 40.86% <ø> (+2.77%) ⬆️
profiling-windows 40.87% <ø> (+1.87%) ⬆️
serverless-azure-functions-client 25.25% <ø> (ø)
serverless-azure-functions-eventhubs 25.25% <ø> (ø)
serverless-azure-functions-servicebus 25.25% <ø> (ø)
serverless-lambda 33.57% <ø> (?)

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.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 28, 2026

Overall package size

Self size: 5.67 MB
Deduped: 6.51 MB
No deduping: 6.51 MB

Dependency sizes | name | version | self size | total size | |------|---------|-----------|------------| | import-in-the-middle | 3.0.1 | 82.56 kB | 817.39 kB | | dc-polyfill | 0.1.10 | 26.73 kB | 26.73 kB |

🤖 This report was automatically generated by heaviest-objects-in-the-universe

IlyasShabi
IlyasShabi previously approved these changes Apr 29, 2026
Comment thread integration-tests/helpers/index.js Outdated
Comment thread packages/dd-trace/test/setup/mocha-hooks.js Outdated
@BridgeAR BridgeAR enabled auto-merge (squash) April 29, 2026 12:30
@BridgeAR BridgeAR merged commit 6089c44 into master Apr 29, 2026
918 of 920 checks passed
@BridgeAR BridgeAR deleted the BridgeAR/2026-04-28-louder-mocha-hook-errors branch April 29, 2026 12:43
dd-octo-sts Bot pushed a commit that referenced this pull request Apr 29, 2026
If a after* hook fails after a failure in a before* hook or the test,
the after hook error is going to be read first and tears down the
test runner. This causes the actual error not to be visible anymore.

This surfaces these again by hooking into mocha internals and
ignoring the after* errors, if it comes after a former error. That
way we know what actually fails.

Downside is not knowing about teardown issues that are in addition
to former issues, while that is in almost all cases not important.

Hiding also seemed better than logging both to let us focus on the
main problem area.
@dd-octo-sts dd-octo-sts Bot mentioned this pull request Apr 29, 2026
BridgeAR added a commit that referenced this pull request Apr 30, 2026
If a after* hook fails after a failure in a before* hook or the test,
the after hook error is going to be read first and tears down the
test runner. This causes the actual error not to be visible anymore.

This surfaces these again by hooking into mocha internals and
ignoring the after* errors, if it comes after a former error. That
way we know what actually fails.

Downside is not knowing about teardown issues that are in addition
to former issues, while that is in almost all cases not important.

Hiding also seemed better than logging both to let us focus on the
main problem area.
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.

3 participants