Skip to content

Commit

Permalink
add memory leak test (#2487)
Browse files Browse the repository at this point in the history
  • Loading branch information
dai-shi committed Apr 7, 2024
1 parent 2abd51c commit 88303ac
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
14 changes: 14 additions & 0 deletions tests/vanilla/memoryleaks.test.ts
Original file line number Diff line number Diff line change
@@ -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)
})
13 changes: 13 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 88303ac

Please sign in to comment.