Jest has a --detectLeaks flag, which causes tests to fail if there is a memory leak. Importing @testing-library/jest-dom
causes a memory leak in NodeJS v20. However, in NodeJS v18 the memory leak does not occur.
- Clone this repository
- Switch to NodeJS v20
- Run
npm install
andnpm run test
- The test should fail with the message "Your test suite is leaking memory. Please ensure all references are cleaned."
- Remove
require("@testing-library/jest-dom");
from jest-setup.js - Rerun the test. It should pass, indicating that the memory leak is resolved.
- The memory leak does not occur in Node.js v18.
- When commenting out
require('aria-query');
var matchers = require('./matchers-5ae87d41.js');
andexpect.extend(matchers.extensions);
from./node_modules/@testing-library/jest-dom/dist/index.js
memory leak disappears. Bothvar matchers
andrequire('aria-query')
cause a memory leak.