diff --git a/.github/workflows/test-multiple-builds.yml b/.github/workflows/test-multiple-builds.yml index 75cb191d..050fa118 100644 --- a/.github/workflows/test-multiple-builds.yml +++ b/.github/workflows/test-multiple-builds.yml @@ -37,7 +37,6 @@ jobs: run: | sed -i~ "s/it[.a-zA-Z]*('\[PRD-ONLY\]/it('/" tests/*.ts tests/*.tsx sed -i~ "s/it[.a-zA-Z]*('\[DEV-ONLY\]/it.skip('/" tests/*.ts tests/*.tsx - sed -i~ "s/describe(/describe.skip(/" tests/memoryleaks.test.ts # FIXME why it doesn't work in production mode? - name: Patch for CJS if: ${{ matrix.build == 'cjs' }} run: | diff --git a/.github/workflows/test-old-typescript.yml b/.github/workflows/test-old-typescript.yml index 6d8e0ab4..63b33488 100644 --- a/.github/workflows/test-old-typescript.yml +++ b/.github/workflows/test-old-typescript.yml @@ -13,7 +13,8 @@ jobs: fail-fast: false matrix: typescript: - - 5.3.2 + - 5.4.4 + - 5.3.3 - 5.2.2 - 5.1.6 - 5.0.4 diff --git a/package.json b/package.json index 261691c8..db568c10 100644 --- a/package.json +++ b/package.json @@ -104,8 +104,8 @@ }, "homepage": "https://github.com/pmndrs/valtio", "dependencies": { - "proxy-compare": "2.6.0", "derive-valtio": "0.1.0", + "proxy-compare": "2.6.0", "use-sync-external-store": "1.2.0" }, "devDependencies": { @@ -146,6 +146,7 @@ "eslint-plugin-react": "^7.33.2", "eslint-plugin-react-hooks": "^4.6.0", "eslint-plugin-vitest": "^0.3.22", + "jest-leak-detector": "^29.7.0", "jsdom": "^24.0.0", "json": "^11.0.0", "postinstall-postinstall": "^2.1.0", diff --git a/tests/memoryleaks.test.ts b/tests/memoryleaks.test.ts index db6f4d6e..8f79d8d6 100644 --- a/tests/memoryleaks.test.ts +++ b/tests/memoryleaks.test.ts @@ -1,51 +1,43 @@ -import { exec } from 'child_process' +import LeakDetector from 'jest-leak-detector' import { describe, expect, it } from 'vitest' +import { proxy } from 'valtio' describe('no memory leaks with proxy', () => { - const runTest = async (code: string) => { - const testCode = ` - const { proxy } = require("./dist/vanilla.js"); - ${code} - const registry = new FinalizationRegistry(() => { - console.log("state is garbage collected"); - }); - registry.register(state, undefined); - state = null; - setImmediate(() => { - global.gc(); - }); - ` - const output = await new Promise((resolve) => { - exec(`node --expose-gc --eval '${testCode}'`, (err, stdout) => { - resolve(err || stdout) - }) - }) - expect(output).toMatch('state is garbage collected') - } - it('empty object', async () => { - await runTest(` - let state = proxy({}); - `) + let detector: LeakDetector + ;(() => { + const state = proxy({}) + detector = new LeakDetector(state) + })() + expect(await detector.isLeaking()).toBe(false) }) it('child object', async () => { - await runTest(` - let state = proxy({ child: {} }); - `) + let detector: LeakDetector + ;(() => { + const state = proxy({ child: {} }) + detector = new LeakDetector(state) + })() + expect(await detector.isLeaking()).toBe(false) }) it('global child object', async () => { - await runTest(` - const child = {}; - let state = proxy({ child }); - `) + let detector: LeakDetector + ;(() => { + const child = {} + const state = proxy({ child }) + detector = new LeakDetector(state) + })() + expect(await detector.isLeaking()).toBe(false) }) it('global child proxy', async () => { - await runTest(` - const child = proxy({}); - let state = proxy({ child }); - `) + let detector: LeakDetector + ;(() => { + const child = proxy({}) + const state = proxy({ child }) + detector = new LeakDetector(state) + })() + expect(await detector.isLeaking()).toBe(false) }) }) diff --git a/yarn.lock b/yarn.lock index df216606..d501d046 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3697,6 +3697,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"