visual-studio-codetestingjestjsvscode-jest

jest code coverage overlay not showing up in vscode anymore


It had previously been working. All I had to do is: Ctrl + Shift + P and run Jest: Toggle Coverage. Sometimes I had to manually trigger the test run for the file I wanted to have a code coverage overlay.

I made sure I'm

enter image description here

I let all tests run, restarted vscode, enabled autorun, but it all did not help.

jest@29.3.1
vscode-jest v5.2.3

Solution

  • It turned out someone had manually disabled jest.autoRun.watch in .vscode/settings.json which is part of the git repo of our project:

    "jest.autoRun": { "watch": false, "onSave": "test-file" },
    

    changing it to

    "jest.autoRun": { "watch": true, "onSave": "test-file" },
    

    made the overlay reappear.

    Setting jest.autoRun.watch to false in the workspace, overwrites the global and user level settings, and without jest.autoRun.watch, jest does not seem to display the code coverage overlay, even if you run the test onSave.

    Also the UI of the vscode-jest extension is a bit misleading, as it lets you toggle on and off the autorun with a little button (see above screenshot), but it won't have an effect on the jest.autoRun.watch: false, if it is set in the workspace's .vscode/settings.json.

    But you can actually see the current active setting in the vscode-jest extensions UI:

    When you have turned it off with the toggle button: enter image description here

    Turned on with the toggle button, but jest.autoRun.watch: false: enter image description here

    Turned on with the toggle button, and jest.autoRun.watch: true enter image description here

    Only the last setting will work to display code coverage overlays as of vscode-jest v5.2.3!

    As I didn't find something about this in the documentation, I will probably not be the only one, who runs into this.