diff --git a/package.json b/package.json index 695ad47386..86148f77c8 100644 --- a/package.json +++ b/package.json @@ -150,6 +150,7 @@ "eslint-plugin-react": "^7.34.1", "eslint-plugin-react-hooks": "^4.6.0", "eslint-plugin-vitest": "^0.4.1", + "jest-leak-detector": "^29.7.0", "jsdom": "^24.0.0", "json": "^11.0.0", "prettier": "^3.2.5", diff --git a/tests/vanilla/memoryleaks.test.ts b/tests/vanilla/memoryleaks.test.ts new file mode 100644 index 0000000000..8ea9db249c --- /dev/null +++ b/tests/vanilla/memoryleaks.test.ts @@ -0,0 +1,14 @@ +import LeakDetector from 'jest-leak-detector' +import { expect, it } from 'vitest' +import { atom, createStore } from 'jotai/vanilla' + +it('should not have memory leaks with an atom', async () => { + const store = createStore() + let detector: LeakDetector + ;(() => { + const objAtom = atom({}) + detector = new LeakDetector(store.get(objAtom)) + })() + const isLeaking = await detector.isLeaking() + expect(isLeaking).toBe(false) +}) diff --git a/yarn.lock b/yarn.lock index b2d84a1b28..8e0a4fbb55 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3466,6 +3466,19 @@ iterator.prototype@^1.1.2: reflect.getprototypeof "^1.0.4" set-function-name "^2.0.1" +jest-get-type@^29.6.3: + version "29.6.3" + resolved "https://registry.yarnpkg.com/jest-get-type/-/jest-get-type-29.6.3.tgz#36f499fdcea197c1045a127319c0481723908fd1" + integrity sha512-zrteXnqYxfQh7l5FHyL38jL39di8H8rHoecLH3JNxH3BwOrBsNeabdap5e0I23lD4HHI8W5VFBZqG4Eaq5LNcw== + +jest-leak-detector@^29.7.0: + version "29.7.0" + resolved "https://registry.yarnpkg.com/jest-leak-detector/-/jest-leak-detector-29.7.0.tgz#5b7ec0dadfdfec0ca383dc9aa016d36b5ea4c728" + integrity sha512-kYA8IJcSYtST2BY9I+SMC32nDpBT3J2NvWJx8+JCuCdl/CR1I4EKUJROiP8XtCcxqgTTBGJNdbB1A8XRKbTetw== + dependencies: + jest-get-type "^29.6.3" + pretty-format "^29.7.0" + "js-tokens@^3.0.0 || ^4.0.0", js-tokens@^4.0.0: version "4.0.0" resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-4.0.0.tgz#19203fb59991df98e3a287050d4647cdeaf32499"