Skip to content

fix(cypress): handle missing beforeEach task result#9129

Merged
juan-fernandez merged 1 commit into
masterfrom
juan-fernandez/cypress-beforeeach-task-hardening
Jun 29, 2026
Merged

fix(cypress): handle missing beforeEach task result#9129
juan-fernandez merged 1 commit into
masterfrom
juan-fernandez/cypress-beforeeach-task-hardening

Conversation

@juan-fernandez

@juan-fernandez juan-fernandez commented Jun 29, 2026

Copy link
Copy Markdown
Collaborator

What does this PR do?

Adds a defensive retry around the Cypress dd:beforeEach task result before destructuring it. If Cypress yields null or undefined, the support hook now warns once and retries dd:beforeEach; if the retry also has no result, it warns once more and continues with an empty result instead of failing the run with a destructuring error.

Also makes the Node-side Cypress task handler idempotent for repeated ITR-skipped dd:beforeEach calls. When the missing-result edge happens after the task handler already ran, the retry no longer appends the same skipped test twice or inflates test.itr.tests_skipping.count. The de-dupe key is scoped by spec path so Cypress runnable ids reused across spec files do not under-count distinct skipped tests.

Integration coverage lives in the existing Cypress specs. The fixture now calls the real dd:beforeEach handler and then returns null on the first call, which simulates the sharper transport edge where task side effects already happened but Cypress yielded no result. The reporting test verifies the retry reaches the real task result, and the ITR test verifies two skipped specs are counted separately while the retried skipped test is counted once.

Motivation

A user reported a rare Cypress failure where cy.task("dd:beforeEach") yielded undefined, causing the support hook to crash while destructuring the task result. The Datadog task handlers normally return an object, including noop fallback handlers, so this appears to be a rare Cypress/plugin task transport or lifecycle edge rather than an expected Datadog configuration path.

Fixes #9084.

@dd-octo-sts

dd-octo-sts Bot commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Overall package size

Self size: 6.4 MB
Deduped: 7.46 MB
No deduping: 7.46 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

@datadog-prod-us1-5

datadog-prod-us1-5 Bot commented Jun 29, 2026

Copy link
Copy Markdown

Tests

🎉 All green!

🧪 All tests passed
❄️ No new flaky tests detected

🎯 Code Coverage (details)
Patch Coverage: 85.71%
Overall Coverage: 87.98% (-0.01%)

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

@codecov

codecov Bot commented Jun 29, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.69%. Comparing base (791b77c) to head (c07a671).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #9129      +/-   ##
==========================================
- Coverage   93.69%   93.69%   -0.01%     
==========================================
  Files         889      889              
  Lines       50856    50861       +5     
  Branches    11830    11832       +2     
==========================================
+ Hits        47649    47652       +3     
- Misses       3207     3209       +2     
Flag Coverage Δ
aiguard 34.88% <ø> (-0.08%) ⬇️
aiguard-integration 41.79% <ø> (ø)
apm-bucket-0 34.85% <ø> (-0.08%) ⬇️
apm-bucket-1 40.34% <ø> (-0.07%) ⬇️
apm-bucket-2 37.35% <ø> (-0.07%) ⬇️
apm-capabilities-tracing 48.29% <ø> (ø)
apm-integrations-aerospike 33.13% <ø> (-0.08%) ⬇️
apm-integrations-confluentinc-kafka-javascript 40.04% <ø> (-0.08%) ⬇️
apm-integrations-couchbase 33.25% <ø> (-0.35%) ⬇️
apm-integrations-http 42.04% <ø> (-0.07%) ⬇️
apm-integrations-kafkajs 40.27% <ø> (-0.08%) ⬇️
apm-integrations-next 29.51% <ø> (-0.04%) ⬇️
apm-integrations-prisma 35.04% <ø> (-0.07%) ⬇️
apm-integrations-tedious 33.90% <ø> (-0.08%) ⬇️
appsec 57.38% <ø> (-0.07%) ⬇️
appsec-express_fastify_graphql 53.78% <ø> (-0.06%) ⬇️
appsec-integration 36.25% <ø> (ø)
appsec-kafka_ldapjs_lodash 43.60% <ø> (-0.07%) ⬇️
appsec-mongodb-core_mongoose_mysql 48.82% <ø> (-0.07%) ⬇️
appsec-next 28.01% <ø> (-0.07%) ⬇️
appsec-node-serialize_passport_postgres 48.01% <ø> (-0.06%) ⬇️
appsec-sourcing_stripe_template 45.56% <ø> (-0.06%) ⬇️
debugger 44.37% <ø> (-0.05%) ⬇️
instrumentations-bucket-0 28.16% <ø> (-0.08%) ⬇️
instrumentations-bucket-1 37.41% <ø> (-0.07%) ⬇️
instrumentations-bucket-10 40.44% <ø> (-0.07%) ⬇️
instrumentations-bucket-11 27.96% <ø> (-0.08%) ⬇️
instrumentations-bucket-12 28.67% <ø> (-0.08%) ⬇️
instrumentations-bucket-13 27.79% <ø> (-0.08%) ⬇️
instrumentations-bucket-2 30.24% <ø> (-0.07%) ⬇️
instrumentations-bucket-3 35.91% <ø> (-0.07%) ⬇️
instrumentations-bucket-4 28.07% <ø> (-0.08%) ⬇️
instrumentations-bucket-5 36.28% <ø> (-0.07%) ⬇️
instrumentations-bucket-6 38.26% <ø> (-0.08%) ⬇️
instrumentations-bucket-7 36.01% <ø> (-0.07%) ⬇️
instrumentations-bucket-8 36.96% <ø> (-0.07%) ⬇️
instrumentations-bucket-9 39.53% <ø> (-0.07%) ⬇️
instrumentations-instrumentation-couchbase 46.54% <ø> (ø)
instrumentations-integration-esbuild 24.87% <ø> (ø)
llmobs-ai_anthropic_bedrock 39.54% <ø> (-0.07%) ⬇️
llmobs-google-genai_langchain_vertex-ai 36.98% <ø> (-0.06%) ⬇️
llmobs-openai 39.59% <ø> (-0.07%) ⬇️
llmobs-sdk 43.60% <ø> (-0.08%) ⬇️
master-coverage 93.69% <100.00%> (?)
openfeature 37.76% <ø> (ø)
openfeature-unit 50.39% <ø> (ø)
platform-core_esbuild_instrumentations-misc 23.36% <ø> (ø)
platform-integration 47.44% <ø> (+0.01%) ⬆️
platform-shimmer_unit-guardrails_webpack 18.89% <ø> (ø)
plugins-bucket-0 36.34% <ø> (-0.07%) ⬇️
plugins-bucket-1 39.61% <ø> (ø)
plugins-bucket-11 38.47% <ø> (-0.08%) ⬇️
plugins-bucket-17 39.01% <ø> (-0.23%) ⬇️
plugins-bucket-18 42.01% <ø> (-0.07%) ⬇️
plugins-bucket-19 39.57% <ø> (-0.07%) ⬇️
plugins-bucket-20 43.21% <ø> (-0.16%) ⬇️
plugins-bucket-4 37.72% <ø> (-0.07%) ⬇️
plugins-bullmq_cassandra_cookie 39.77% <ø> (-0.07%) ⬇️
plugins-cookie-parser_crypto_dd-trace-api 33.23% <ø> (-0.08%) ⬇️
plugins-fetch_fs_generic-pool 36.06% <ø> (-0.07%) ⬇️
plugins-google-cloud-pubsub_grpc_handlebars 43.11% <ø> (-0.07%) ⬇️
plugins-hapi_hono_ioredis 37.79% <ø> (-0.07%) ⬇️
plugins-jest_knex_langgraph 32.61% <ø> (-0.08%) ⬇️
plugins-ldapjs_light-my-request_limitd-client 27.85% <ø> (-0.08%) ⬇️
plugins-lodash_mariadb_memcached 35.18% <ø> (-0.08%) ⬇️
plugins-mongodb_mongodb-core_mongoose 36.32% <ø> (-0.07%) ⬇️
plugins-multer_mysql_mysql2 35.15% <ø> (-0.08%) ⬇️
plugins-nats_node-serialize_opensearch 37.16% <ø> (-0.08%) ⬇️
plugins-passport-http_pino_postgres 35.54% <ø> (-0.08%) ⬇️
plugins-process_pug_redis 34.27% <ø> (-0.08%) ⬇️
plugins-undici_url_valkey 35.88% <ø> (-0.08%) ⬇️
plugins-vm_winston_ws 37.56% <ø> (-0.29%) ⬇️
profiling 43.62% <ø> (-0.07%) ⬇️
serverless-aws-sdk-aws-sdk 33.30% <ø> (-0.07%) ⬇️
serverless-aws-sdk-bedrockruntime 32.17% <ø> (-0.07%) ⬇️
serverless-aws-sdk-client 37.21% <ø> (ø)
serverless-aws-sdk-dynamodb 34.10% <ø> (-0.07%) ⬇️
serverless-aws-sdk-eventbridge 27.25% <ø> (-0.07%) ⬇️
serverless-aws-sdk-kinesis 37.41% <ø> (-0.07%) ⬇️
serverless-aws-sdk-lambda 34.60% <ø> (-0.07%) ⬇️
serverless-aws-sdk-s3 32.60% <ø> (-0.07%) ⬇️
serverless-aws-sdk-serverless-peer-service 39.47% <ø> (-0.08%) ⬇️
serverless-aws-sdk-sns 38.26% <ø> (-0.07%) ⬇️
serverless-aws-sdk-sqs 38.01% <ø> (-0.07%) ⬇️
serverless-aws-sdk-stepfunctions 33.19% <ø> (-0.07%) ⬇️
serverless-aws-sdk-util 47.95% <ø> (ø)
serverless-bucket-0 39.47% <ø> (ø)
serverless-lambda 34.33% <ø> (-0.09%) ⬇️
test-optimization-cucumber 52.57% <ø> (+0.11%) ⬆️
test-optimization-cypress 49.64% <100.00%> (+0.08%) ⬆️
test-optimization-jest 55.67% <ø> (+0.11%) ⬆️
test-optimization-mocha 53.66% <ø> (+0.08%) ⬆️
test-optimization-playwright-playwright-atr 43.59% <ø> (+0.08%) ⬆️
test-optimization-playwright-playwright-efd 43.87% <ø> (+0.08%) ⬆️
test-optimization-playwright-playwright-final-status 43.93% <ø> (+0.11%) ⬆️
test-optimization-playwright-playwright-impacted-tests 43.41% <ø> (ø)
test-optimization-playwright-playwright-reporting 43.50% <ø> (+0.08%) ⬆️
test-optimization-playwright-playwright-test-management 44.93% <ø> (+0.08%) ⬆️
test-optimization-playwright-playwright-test-span 44.78% <ø> (+0.07%) ⬆️
test-optimization-selenium 45.52% <ø> (+0.06%) ⬆️
test-optimization-testopt 48.28% <ø> (+0.08%) ⬆️
test-optimization-vitest 50.93% <ø> (+0.10%) ⬆️

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
juan-fernandez force-pushed the juan-fernandez/cypress-beforeeach-task-hardening branch from 1f38dbc to f8e612b Compare June 29, 2026 08:36
@pr-commenter

pr-commenter Bot commented Jun 29, 2026

Copy link
Copy Markdown

Benchmarks

Benchmark execution time: 2026-06-29 10:04:33

Comparing candidate commit c07a671 in PR branch juan-fernandez/cypress-beforeeach-task-hardening with baseline commit 791b77c 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-20

  • unstable execution_time [-198.948ms; +186.167ms] or [-5.362%; +5.018%]

scenario:appsec-appsec-enabled-24

  • unstable execution_time [-182795.786µs; +181021.219µs] or [-6.924%; +6.857%]

scenario:appsec-appsec-enabled-26

  • unstable execution_time [-208.394ms; +210.898ms] or [-8.297%; +8.397%]

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

  • unstable execution_time [-155.422ms; +147.821ms] or [-5.394%; +5.130%]

scenario:appsec-control-20

  • unstable execution_time [-156.529ms; +146.687ms] or [-9.019%; +8.452%]

scenario:appsec-control-24

  • unstable execution_time [-104.363ms; +101.098ms] or [-8.617%; +8.347%]

scenario:appsec-control-26

  • unstable execution_time [-99.829ms; +123.040ms] or [-8.318%; +10.253%]

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

  • unstable cpu_user_time [-2653.890ms; +2720.330ms] or [-31.255%; +32.038%]
  • unstable execution_time [-2667.603ms; +2730.276ms] or [-29.014%; +29.696%]
  • unstable instructions [-22778.0M instructions; +23234.8M instructions] or [-32.894%; +33.553%]
  • unstable max_rss_usage [-10109.779KB; +10359.379KB] or [-6.308%; +6.464%]
  • unstable throughput [-790.942op/s; +778.617op/s] or [-21.620%; +21.283%]

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

  • unstable cpu_user_time [-2.170s; +4.611s] or [-21.787%; +46.303%]
  • unstable execution_time [-2.187s; +4.652s] or [-20.507%; +43.621%]
  • unstable instructions [-19.4G instructions; +41.2G instructions] or [-23.334%; +49.570%]
  • unstable max_rss_usage [-6.661MB; +14.522MB] or [-4.143%; +9.033%]
  • unstable throughput [-1019.363op/s; +485.959op/s] or [-32.491%; +15.490%]

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

  • unstable cpu_user_time [-1674.009ms; +532.374ms] or [-21.145%; +6.725%]
  • unstable execution_time [-1691.740ms; +548.571ms] or [-19.691%; +6.385%]
  • unstable instructions [-14.2G instructions; +4.6G instructions] or [-21.975%; +7.153%]
  • unstable throughput [-161.458op/s; +497.313op/s] or [-4.200%; +12.937%]

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

  • unstable cpu_user_time [-2106.428ms; +3336.922ms] or [-22.448%; +35.562%]
  • unstable execution_time [-2128.706ms; +3365.331ms] or [-21.118%; +33.387%]
  • unstable instructions [-18.6G instructions; +29.4G instructions] or [-23.832%; +37.594%]
  • unstable max_rss_usage [-6.679MB; +10.934MB] or [-4.228%; +6.922%]
  • unstable throughput [-728.253op/s; +462.982op/s] or [-22.355%; +14.212%]

scenario:dogstatsd-with-tags-20

  • unstable cpu_user_time [-400.501ms; +322.674ms] or [-8.258%; +6.653%]
  • unstable execution_time [-397.807ms; +321.742ms] or [-8.083%; +6.538%]
  • unstable throughput [-110079.708op/s; +135826.428op/s] or [-6.448%; +7.956%]

scenario:plugin-graphql-long-with-depth-and-collapse-off-20

  • unstable max_rss_usage [-31.928MB; +9.471MB] or [-8.384%; +2.487%]

scenario:plugin-graphql-long-with-depth-off-20

  • unstable max_rss_usage [-6711.365KB; +7584.508KB] or [-5.149%; +5.818%]

scenario:plugin-graphql-long-with-depth-on-max-20

  • unstable max_rss_usage [-34.168MB; +54.411MB] or [-18.616%; +29.645%]

@juan-fernandez
juan-fernandez force-pushed the juan-fernandez/cypress-beforeeach-task-hardening branch from f8e612b to df3860b Compare June 29, 2026 08:50
@juan-fernandez
juan-fernandez marked this pull request as ready for review June 29, 2026 08:56
@juan-fernandez
juan-fernandez requested a review from a team as a code owner June 29, 2026 08:56

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: df3860b440

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

Comment thread packages/datadog-plugin-cypress/src/support.js

@datadog-prod-us1-5 datadog-prod-us1-5 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

Cypress dd:beforeEach task now safely handles rare null/undefined returns with automatic retry and empty-object fallback. All downstream field destructuring uses defensive checks, eliminating the crash from the reported issue. The integration test correctly validates the retry path and successful test reporting. No regressions or defects identified.

Was this helpful? React 👍 or 👎

📊 Validated against 8 scenarios · Open Bits AI session

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

@juan-fernandez
juan-fernandez force-pushed the juan-fernandez/cypress-beforeeach-task-hardening branch from df3860b to 0a0817a Compare June 29, 2026 09:08
@juan-fernandez

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0a0817ab5f

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

Comment thread integration-tests/cypress/cypress-itr.spec.js Outdated
@juan-fernandez
juan-fernandez force-pushed the juan-fernandez/cypress-beforeeach-task-hardening branch from 0a0817a to 3ce8a2a Compare June 29, 2026 09:25
@juan-fernandez

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3ce8a2a716

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

Comment thread packages/datadog-plugin-cypress/src/cypress-plugin.js Outdated
@juan-fernandez
juan-fernandez force-pushed the juan-fernandez/cypress-beforeeach-task-hardening branch from 3ce8a2a to c07a671 Compare June 29, 2026 09:52
@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. Keep it up!

Reviewed commit: c07a67179e

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

@juan-fernandez
juan-fernandez merged commit 243c792 into master Jun 29, 2026
1078 of 1079 checks passed
@juan-fernandez
juan-fernandez deleted the juan-fernandez/cypress-beforeeach-task-hardening branch June 29, 2026 10:17
This was referenced Jun 30, 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.

[BUG]: error destructing property

2 participants