-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix memory leaks of jest-worker (#11187)
Co-authored-by: Tim Seckinger <seckinger.tim@gmail.com>
- Loading branch information
Showing
7 changed files
with
67 additions
and
6 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
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
40 changes: 40 additions & 0 deletions
40
packages/jest-worker/src/__tests__/leak-integration.test.ts
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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
import {tmpdir} from 'os'; | ||
import {join} from 'path'; | ||
import {writeFileSync} from 'graceful-fs'; | ||
import LeakDetector from 'jest-leak-detector'; | ||
import {Worker} from '../..'; | ||
|
||
let workerFile!: string; | ||
beforeAll(() => { | ||
workerFile = join(tmpdir(), 'baz.js'); | ||
writeFileSync(workerFile, `module.exports.fn = () => {};`); | ||
}); | ||
|
||
let worker!: Worker; | ||
beforeEach(() => { | ||
worker = new Worker(workerFile, { | ||
enableWorkerThreads: true, | ||
exposedMethods: ['fn'], | ||
}); | ||
}); | ||
afterEach(async () => { | ||
await worker.end(); | ||
}); | ||
|
||
it('does not retain arguments after a task finished', async () => { | ||
let leakDetector!: LeakDetector; | ||
await new Promise(resolve => { | ||
const obj = {}; | ||
leakDetector = new LeakDetector(obj); | ||
(worker as any).fn(obj).then(resolve); | ||
}); | ||
|
||
expect(await leakDetector.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
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 |
---|---|---|
|
@@ -3,5 +3,6 @@ | |
"compilerOptions": { | ||
"rootDir": "src", | ||
"outDir": "build" | ||
} | ||
}, | ||
"references": [{"path": "../jest-leak-detector"}] | ||
} |
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