Skip to content

[test optimization] Fix mocks on jest tests when retried with ATF, EFD or impacted tests#7352

Merged
juan-fernandez merged 2 commits intomasterfrom
juan-fernandez/fix-mocks-in-attempt-to-fix
Jan 28, 2026
Merged

[test optimization] Fix mocks on jest tests when retried with ATF, EFD or impacted tests#7352
juan-fernandez merged 2 commits intomasterfrom
juan-fernandez/fix-mocks-in-attempt-to-fix

Conversation

@juan-fernandez
Copy link
Copy Markdown
Collaborator

@juan-fernandez juan-fernandez commented Jan 27, 2026

What does this PR do?

Resets Jest mock state between test retries (attempt to fix, EFD, impacted tests) by calling jest.clearAllMocks() before each retry attempt.

Motivation

When a test uses mocks and is retried, the mock's internal state (call count, arguments, etc.) was not being reset. This caused assertions like toHaveBeenCalledTimes(1) to fail on retries because the call count accumulated across attempts.

Additional Notes

  • Stores the jest object reference when created by jest-runtime, then retrieves it in the test environment to call clearAllMocks()
  • Cleans up stored references when test suite finishes to avoid memory leaks
  • Added integration test to verify mock state is properly reset between retries

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Jan 27, 2026

Overall package size

Self size: 4.46 MB
Deduped: 5.29 MB
No deduping: 5.29 MB

Dependency sizes | name | version | self size | total size | |------|---------|-----------|------------| | import-in-the-middle | 2.0.3 | 76.87 kB | 808.03 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 Jan 27, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.16%. Comparing base (e6e966d) to head (d6e3f5b).
⚠️ Report is 16 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #7352      +/-   ##
==========================================
+ Coverage   84.91%   86.16%   +1.24%     
==========================================
  Files         515      515              
  Lines       22221    22234      +13     
==========================================
+ Hits        18870    19157     +287     
+ Misses       3351     3077     -274     
Flag Coverage Δ
aiguard-macos 99.09% <ø> (ø)
aiguard-ubuntu 99.09% <ø> (ø)
aiguard-windows 99.09% <ø> (ø)
apm-capabilities-tracing-macos 57.88% <ø> (+0.04%) ⬆️
apm-capabilities-tracing-ubuntu 57.88% <ø> (+0.04%) ⬆️
apm-capabilities-tracing-windows 57.42% <ø> (-0.04%) ⬇️
apm-integrations-child-process 99.19% <ø> (ø)
apm-integrations-couchbase-18 100.00% <ø> (ø)
apm-integrations-couchbase-eol 100.00% <ø> (ø)
appsec-express 62.46% <ø> (ø)
appsec-fastify 58.48% <ø> (ø)
appsec-graphql 53.41% <ø> (ø)
appsec-kafka 43.98% <ø> (ø)
appsec-ldapjs 46.04% <ø> (ø)
appsec-lodash 47.29% <ø> (ø)
appsec-macos 93.74% <ø> (ø)
appsec-mongodb-core 51.82% <ø> (ø)
appsec-mongoose 50.73% <ø> (ø)
appsec-mysql 54.20% <ø> (ø)
appsec-node-serialize 43.92% <ø> (ø)
appsec-passport 48.10% <ø> (ø)
appsec-postgres 54.55% <ø> (ø)
appsec-sourcing 33.80% <ø> (ø)
appsec-template 43.92% <ø> (ø)
appsec-ubuntu 93.74% <ø> (ø)
appsec-windows 93.74% <ø> (?)
llmobs-ai 52.09% <ø> (ø)
llmobs-anthropic 42.73% <ø> (ø)
llmobs-bedrock 40.06% <ø> (ø)
llmobs-google-genai 45.89% <ø> (ø)
llmobs-langchain 50.15% <ø> (ø)
llmobs-openai 55.62% <ø> (?)
llmobs-vertex-ai 44.48% <ø> (ø)
platform-core 87.23% <ø> (ø)
platform-instrumentations-misc 88.59% <ø> (+14.91%) ⬆️
platform-shimmer 98.82% <ø> (ø)
platform-unit-guardrails 89.47% <ø> (ø)
profiling-macos 70.74% <ø> (ø)
profiling-ubuntu 70.74% <ø> (ø)
profiling-windows 74.18% <ø> (ø)

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.

@datadog-official

This comment has been minimized.

@pr-commenter
Copy link
Copy Markdown

pr-commenter bot commented Jan 27, 2026

Benchmarks

Benchmark execution time: 2026-01-27 12:33:38

Comparing candidate commit d6e3f5b in PR branch juan-fernandez/fix-mocks-in-attempt-to-fix with baseline commit e6e966d in branch master.

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

@juan-fernandez juan-fernandez changed the title [test optimization] Fix mocks on jest tests with attempt to fix [test optimization] Fix mocks on jest tests when retried with ATF, EFD or impacted tests Jan 27, 2026
@juan-fernandez juan-fernandez marked this pull request as ready for review January 28, 2026 09:24
@juan-fernandez juan-fernandez requested a review from a team as a code owner January 28, 2026 09:24
@juan-fernandez juan-fernandez merged commit 2c57dcc into master Jan 28, 2026
786 checks passed
@juan-fernandez juan-fernandez deleted the juan-fernandez/fix-mocks-in-attempt-to-fix branch January 28, 2026 10:01
dd-octo-sts bot pushed a commit that referenced this pull request Jan 29, 2026
@dd-octo-sts dd-octo-sts bot mentioned this pull request Jan 29, 2026
BridgeAR pushed a commit that referenced this pull request Jan 30, 2026
BridgeAR pushed a commit that referenced this pull request Feb 22, 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