Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jest runs out of memory when producing coverage for a large file #8557

Closed
sandersn opened this issue Jun 12, 2019 · 5 comments · Fixed by #8596
Closed

Jest runs out of memory when producing coverage for a large file #8557

sandersn opened this issue Jun 12, 2019 · 5 comments · Fixed by #8596

Comments

@sandersn
Copy link

🐛 Bug Report

Jest runs out of memory when producing coverage for a test file that is supposed to exercise the typescript compiler, which is 7.2 MB.

Background: I'm experimenting with switching Typescript to jest in order to get coverage-based testing. My first attempt is to create a small prototype that imitates our current tests in mocha. But it fails when I request a coverage report.

To Reproduce

Clone this repo: https://github.com/sandersn/jest-typescript-oomemory

  1. npm install
  2. npx jest --coverage

There are only two files that matter, though:

// @Filename: jest.config.js
module.exports = {}
// @Filename: x.test.js
var ts = require('./typescript.js')

Expected behavior

A coverage report. In my original code, I wanted to see how well Typescript's tests covered the typescript compiler.

Link to repl or repo (highly encouraged)

https://github.com/sandersn/jest-typescript-oomemory

Run npx envinfo --preset jest

Paste the results here:

✔ jest-typescript-oomemory  [master|…1]$ npx envinfo --preset jest
npx: installed 1 in 0.725s

  System:
    OS: Linux 4.15 Ubuntu 18.04.2 LTS (Bionic Beaver)
    CPU: (8) x64 Intel(R) Core(TM) i7-6700 CPU @ 3.40GHz
  Binaries:
    Node: 11.14.0 - ~/.nvm/versions/node/v11.14.0/bin/node
    Yarn: 1.16.0 - ~/.nvm/versions/node/v11.14.0/bin/yarn
    npm: 6.7.0 - ~/.nvm/versions/node/v11.14.0/bin/npm
  npmPackages:
    jest: ^24.8.0 => 24.8.0 
@thymikee
Copy link
Collaborator

We use Istanbul to generate coverege, which works as a Babel plugin so I suppose it's mostly because of that. Not sure how much we can do currently to mitigate that.

But, there's an open issue on migrating our coverage system to built-in V8 coverage: #7062 which should speed it up significantly.

We'd love some help in the area. cc @bcoe

@SimenB
Copy link
Member

SimenB commented Jun 15, 2019

Could we maybe write coverage data to disk as we go to free up memory, and load it back up when we're done running tests to write the reports?

EDIT: Oh, it's one gigantic file. hmmm

EDIT2: And I see now running it that it fails in @babel/traverse and not from keeping actual coverage in memory, so using v8 coverage could indeed help

@SimenB
Copy link
Member

SimenB commented Jun 22, 2019

I'm getting somewhere with v8 coverage, btw. Horribly, horribly hacky, but a sneak peak:

image

(this is just requiring the file, like in your reproduction)

@SimenB
Copy link
Member

SimenB commented Jan 22, 2020

@sandersn v8 coverage is out with jest 25, would love it if you could give it a whirl

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 11, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants