-
-
Notifications
You must be signed in to change notification settings - Fork 263
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* refactor: memory leak test * simplify a bit * does it run on prd? * add ts versions
- Loading branch information
Showing
5 changed files
with
45 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters