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

Fix a leak in coverage #5289

Merged
merged 7 commits into from
Jan 13, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/jest-runner/src/run_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ async function runTestInternal(

result.perfStats = {end: Date.now(), start};
result.testFilePath = path;
result.coverage = runtime.getAllCoverageInfo();
result.coverage = runtime.getAllCoverageInfoCopy();
result.sourceMaps = runtime.getSourceMapInfo();
result.console = testConsole.getBuffer();
result.skipped = testCount === result.numPendingTests;
Expand Down
4 changes: 2 additions & 2 deletions packages/jest-runtime/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -433,8 +433,8 @@ class Runtime {
}
}

getAllCoverageInfo() {
return this._environment.global.__coverage__;
getAllCoverageInfoCopy() {
return JSON.parse(JSON.stringify(this._environment.global.__coverage__));
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is probably the worst way to do this but I figured I would push and ask if there's a preferred way to deep copy objects in this project. I tried deepCyclicCopy from jest-utils but that did not work

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the curious, this is what the object looks like: https://gist.github.com/rickhanlonii/337bb5310f827cef35ec2d329edbfc3b

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rickhanlonii What was the issue with deepCyclicCopy? It's true it's too basic to copy RegExp, Dates and such, but being JSON copy-able, it should work out of the box 😔

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checking at the code, what can be happening is that we create the copied object using the prototype of the original one, so the instanceof operator still works for the copied one (this becomes especially important when creating copies of objects like process).

But, in turn, it can be preventing the memory to release, which I guess it's why it did not work for you.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that makes sense, that is what's happening

}

getSourceMapInfo() {
Expand Down