https://github.com/iansu/jest-runner-iansu
A patched version of the default jest-runner that prevents out of memory issues
https://github.com/iansu/jest-runner-iansu
Last synced: 3 months ago
JSON representation
A patched version of the default jest-runner that prevents out of memory issues
- Host: GitHub
- URL: https://github.com/iansu/jest-runner-iansu
- Owner: iansu
- Created: 2022-05-18T18:14:07.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2022-05-31T21:54:32.000Z (about 4 years ago)
- Last Synced: 2025-03-18T14:18:38.299Z (over 1 year ago)
- Language: JavaScript
- Size: 28.3 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# jest-runner-iansu
This is a patched version of [`jest-runner`](https://github.com/facebook/jest/tree/main/packages/jest-runner) that shuts down the worker when it has used more than 80% of the available heap memory. Jest will automatically spawn a new worker and continue running the tests. This prevents any out of memory errors.
## Usage
Install the runner with npm or Yarn. Make sure you install the version that corresponds to your Jest version. For example, if you are using Jest 28:
```sh
npm i -D jest-runner-iansu@28
```
```sh
yarn add --dev jest-runner-iansu@28
```
Add this line to your Jest config:
```js
runner: 'jest-runner-iansu'
```
## How it works
This patch only requires adding a few lines of code to the [`testWorker.js`](packages/jest-27/build/testWorker.js) file:
```js
const heap = v8.getHeapStatistics();
if (heap.total_heap_size / heap.heap_size_limit > 0.8) {
(0, _exit().default)(1);
}
```
When a test is dispatched to the worker we first check if the heap usage is above 80%. If it is, the worker just exits with a non-zero exit code. Jest will automatically detect this and spawn a new worker. If the heap usage is below 80% the worker runs the test as usual.
> **Note**
> I've opened an issue in Jest to see if it might be possible to build this into the default test runner and expose the threshold via a config setting/CLI argument: https://github.com/facebook/jest/issues/12893
## License
The original `jest-runner` is released under the MIT license as are all changes in the patched versions.