jest-community / vscode-jest

The optimal flow for Jest based testing in VS Code
MIT License
2.83k stars 290 forks source link

Code coverage not shown even though `runAllTestsFirst` is set without uncommited changes #213

Open stephtr opened 6 years ago

stephtr commented 6 years ago

Environment

  1. node -v: 9.3.0

  2. npm -v: 5.5.1

  3. npm ls react-scripts (if you haven’t ejected): -

  4. Operating system: Windows 10

Steps to Reproduce

  1. Create a git project and setup jest to collect code coverage
  2. Keep vscode's "jest.runAllTestsFirst": true
  3. Commit all changes
  4. Reload jest runner (which starts the initial full test run)

Expected Behavior

Code coverage overlay should be available for the whole time and the whole project.

Actual Behavior

Code coverage overlay works during the initial full test run, but disappears as soon as jest shows No tests found related to files changed since last commit..

As soon as one saves an edit in a covered file code coverage reappears for all tested files (not just the edited one).


If necessary, I could provide a sample repository and further instructions.

seanpoulter commented 6 years ago

Good timing @stephtr, I've been working on this issue this morning.

When we handle new JSON results from Jest with the updateWithData method, most of the updates are performed by iterating over the empty testResults array (which causes no action). Unlike the test results, the coverage map is empty and causes (or at least should cause) the overlay to be removed. To prevent this, we need to bypass the coverage overlay update when the JSON update was preceeded by "No tests found" is on stderr.

@orta, are you OK with a PR to fix this in jest-editor-support? I'm just cleaning up the tests that add an argument when we emit the JSON data:

this.emit('executableJSON', JSON.parse(data), {noTestsFound});
orta commented 6 years ago

Yep, makes sense to me