Skip to content

Conversation

acelaya
Copy link
Contributor

@acelaya acelaya commented Sep 26, 2025

Fixes #7033

Add a call to sinon.restore() in our tests bootstrap's beforeEach, so that all mocks are restored after each test.

This is necessary because sinon keeps track of all mocks created via sinon.stub(), and you need to either call restore() on the mock itself, or do it "globally" to ensure memory can be released.

If more than 10,000 stubs are created, then sinon prints a warning message.

Since having to remember to call restore() every time is error prone, this PR adds a global call that makes it unnecessary.

Before this PR, the tests output would include a line like this:

image

With these changese, that warning is no longer reported:

image

Considerations

This PR makes individual restore calls no longer needed, but I decided to not remove them here to reduce the noise.


afterAll(() => {
window.requestAnimationFrame.restore();
});
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since we are calling sinon.restore() after each test now, mocks need to be created before each test, not before all.

Also, the window.requestAnimationFrame.restore() call fails because this afterAll callback is invoked after the sinon.restore() call in the bootstrap's afterEach.

So I have moved the mock initialization to afterEach, and removed the restore call entirely, as it's no longer needed.

Copy link

codecov bot commented Sep 26, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.47%. Comparing base (b0fb2d6) to head (22f4ad1).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #7338   +/-   ##
=======================================
  Coverage   99.47%   99.47%           
=======================================
  Files         271      271           
  Lines       10968    10968           
  Branches     2620     2620           
=======================================
  Hits        10910    10910           
  Misses         58       58           

☔ 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.

@acelaya acelaya force-pushed the tests-mem-leak-warning branch from 8a43d37 to 32e3dae Compare September 26, 2025 08:38
@acelaya acelaya force-pushed the tests-mem-leak-warning branch from 32e3dae to 22f4ad1 Compare September 26, 2025 09:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Address report of potential memory leak in tests
1 participant