Vscode-jest: Coverage not shown on typescript

Created on 17 Sep 2019  ·  12Comments  ·  Source: jest-community/vscode-jest

Environment

  1. node -v: v10.16.0
  2. npm -v: 6.9.0 /yarn -v 1.17.3
  3. npm ls jest
    npm ls jest [email protected] /Users/jean/dev/startups/yupwego/src/vscode-jest-499 └── [email protected]
  4. yarn why jest
    yarn why jest yarn why v1.17.3 [1/4] 🤔 Why do we have the module "jest"...? [2/4] 🚚 Initialising dependency graph... [3/4] 🔍 Finding dependency... [4/4] 🚡 Calculating file sizes... => Found "[email protected]" info Has been hoisted to "jest" info This module exists because it's specified in "devDependencies". info Disk size without dependencies: "48KB" info Disk size with unique dependencies: "276KB" info Disk size with transitive dependencies: "51.21MB" info Number of shared dependencies: 43 ✨ Done in 0.57s.
  5. your vscode-jest settings if customized:

    • "jest.showCoverageOnLoad": true
  6. Operating system: OSX Mojave 10.14.6

  7. installed vscode extensions
    code --list-extensions AndrewRazumovsky.vscode-styled-jsx-languageserver andys8.jest-snippets Arjun.swagger-viewer blanu.vscode-styled-jsx christian-kohler.npm-intellisense dbaeumer.vscode-eslint DotJoshJohnson.xml eamodio.gitlens EditorConfig.EditorConfig eg2.vscode-npm-script eriklynd.json-tools esbenp.prettier-vscode file-icons.file-icons joaompinto.asciidoctor-vscode lightbend.vscode-sbt-scala mrorz.language-gettext ms-azuretools.vscode-docker Orta.vscode-jest PKief.material-icon-theme ryu1kn.partial-diff scala-lang.scala scalameta.metals skyran.js-jsx-snippets stkb.rewrap vscode-icons-team.vscode-icons wayou.vscode-todo-highlight xabikos.ReactSnippets

    Prerequisite

  • are you able to run jest test from command line?

    yarn jest
    yarn run v1.17.3
    $ /Users/jean/dev/startups/yupwego/src/vscode-jest-499/node_modules/.bin/jest
    PASS  src/capitalize/capitalize.test.ts
    capitalize
      ✓ should throw for null (4ms)
      ✓ should throw for things which aren't strings (1ms)
      ✓ should not change capitalized word (1ms)
      ✓ should capitalize the first letter of a lowercase word
      ✓ should lowercase the tail of an uppercase word (1ms)  
    
    ----------|----------|----------|----------|----------|-------------------|
    File      |  % Stmts | % Branch |  % Funcs |  % Lines | Uncovered Line #s |
    ----------|----------|----------|----------|----------|-------------------|
    All files |      100 |      100 |      100 |      100 |                   |
    index.ts |      100 |      100 |      100 |      100 |                   |
    ----------|----------|----------|----------|----------|-------------------|
    Test Suites: 1 passed, 1 total
    Tests:       5 passed, 5 total
    Snapshots:   0 total
    Time:        1.57s
    Ran all test suites.
    ✨  Done in 2.53s.
    

Steps to Reproduce

git clone https://github.com/jeantil/vscode-jest-499.git
cd vscode-jest-499
yarn install 
yarn jest
code .

Relevant Debug Info


I don't see any errors in self-diagnosis output :(

[Extension Host] spawning process with command=/Users/jean/dev/startups/yupwego/src/vscode-jest-499/node_modules/.bin/jest, args=--testLocationInResults,--json,--useStderr,--outputFile,/var/folders/gt/c0_8ryzj2m7fwmf07t68z0940000gn/T/jest_runner_vscode_jest_181.json,--watch,--no-color

Expected Behavior

overlay coverage on typescript code

Actual Behavior

No overlay appears. in some rare circumstances I can see the following code lens reporting coverage
Capture d’écran 2019-09-17 à 17 07 08
but it disapears as soon as anything changes

Most helpful comment

Changing --watch to --watchAll solved my problem.

All 12 comments

I have same issue but I can see the coverage for a few moment but it disappear as soon as I switch to another file

I have the exact same issue, both on windows and mac

The root cause for this issue is not in vscode-jest, but in Jest itself. Jest deletes the content of lcov.info when in watch mode and therefore code coverage doesn't work. There are multiple issues reported about this (for example; https://github.com/facebook/jest/issues/7331).

There is a workaround to restore the functionality in vscode-jest;

Add this to VS Code settings.json;

{
  "jest.pathToJest": "npm run jest:watchAll --",
  "jest.runAllTestsFirst": false,
  "jest.showCoverageOnLoad": true
}

Add this to package.json

"scripts": {
  "jest:watchAll": "jest --watchAll",
}

(if you don't have the coverage parameters in the Jest configuration file, then you need to add them to the CLI command; https://jestjs.io/docs/en/cli.html)

I haven't found this to be the case, I am able to see the content of Icov.info with every configuration I tried, but without being able to enable the coverage overlay consistently.

Changing --watch to --watchAll solved my problem.

On my machine I couldn't see the code lens, only after I tried the workaround I could see the code lens, but still no coverage overlay. I used the repro steps described in this issue.

PS I'm using WSL2 on Windows, distro: Ubuntu 18.04.2 LTS

PSS I can see the icov files and if I use another extension, I can see the coverage from it.

image

I still dont't reliably get coverage (either lens or overlay) over typescript code in my project.

As I was playing around with the commands i noticed an error popup saying 'invalid arguments' , using the debug mode I got:

Error: Invalid arguments
    at new f (/usr/lib/code/out/vs/workbench/services/extensions/node/extensionHostProcess.js:345)
    at new f (/usr/lib/code/out/vs/workbench/services/extensions/node/extensionHostProcess.js:343)
    at t.b.(/usr/lib/code/out/vs/code/electron-browser/workbench/anonymous function).forEach (/home/jean/.vscode-oss/extensions/orta.vscode-jest-3.0.2/out/extension.js:129:58318)
    at Array.forEach (<anonymous>)
    at Object.keys.forEach.e (/home/jean/.vscode-oss/extensions/orta.vscode-jest-3.0.2/out/extension.js:129)
    at Array.forEach (<anonymous>)
    at t.DefaultFormatter.formatBranches (/home/jean/.vscode-oss/extensions/orta.vscode-jest-3.0.2/out/extension.js:129)
    at t.DefaultFormatter.format (/home/jean/.vscode-oss/extensions/orta.vscode-jest-3.0.2/out/extension.js:129)
    at s.update (/home/jean/.vscode-oss/extensions/orta.vscode-jest-3.0.2/out/extension.js:75)
    at s.updateVisibleEditors (/home/jean/.vscode-oss/extensions/orta.vscode-jest-3.0.2/out/extension.js:75)
    at t.JestExt.triggerUpdateActiveEditor (/home/jean/.vscode-oss/extensions/orta.vscode-jest-3.0.2/out/extension.js:427)
    at t.JestExt.updateWithData (/home/jean/.vscode-oss/extensions/orta.vscode-jest-3.0.2/out/extension.js:427)
    at t.e.onJestEditorSupportEvent.e (/home/jean/.vscode-oss/extensions/orta.vscode-jest-3.0.2/out/extension.js:427)
    at t.emit (events.js:182)
    at t.EventEmitter.emit (/usr/lib/code/out/vs/code/electron-browser/workbench/domain.js:442)
    at /home/jean/.vscode-oss/extensions/orta.vscode-jest-3.0.2/out/extension.js:129
    at FSReqWrap.readFileAfterClose [as oncomplete] (internal/fs/read_file_context.js:53)
$onExtensionRuntimeError @ mainThreadExtensionService.ts:66
_doInvokeHandler @ rpcProtocol.ts:398
_invokeHandler @ rpcProtocol.ts:383
_receiveRequest @ rpcProtocol.ts:299
_receiveOneMessage @ rpcProtocol.ts:226
_protocol.onMessage.e @ rpcProtocol.ts:101
fire @ event.ts:580
fire @ ipc.net.ts:453
_receiveMessage @ ipc.net.ts:733
_socketDisposables.push._socketReader.onMessage.e @ ipc.net.ts:592
fire @ event.ts:580
acceptChunk @ ipc.net.ts:239
_register._socket.onData.e @ ipc.net.ts:200
t @ ipc.net.ts:28
emit @ events.js:182
addChunk @ _stream_readable.js:283
readableAddChunk @ _stream_readable.js:264
Readable.push @ _stream_readable.js:219
onStreamRead @ internal/stream_base_commons.js:94

I'm using v3.0.1 of the extension on

Version: 1.39.2
Commit: 6ab598523be7a800d7f3eb4d92d7ab9a66069390
Date: 2019-10-18T10:58:05.878Z
Electron: 4.2.12
Chrome: 69.0.3497.128
Node.js: 10.11.0
V8: 6.9.427.31-electron.0
OS: Linux x64 5.3.8-3-MANJARO

@jeantil I fixed the Invalid arguments bug in #519.

This got better, but there are still problems. In small files, the coverage works fine, but once the file starts getting better, nothing is shown.

For example, on this small file, the coverage is shown as expected:
image

But here, nothing is highlighted, even though there is 0% coverage:
image

To see this behavior please clone my repo:
git clone https://github.com/sinapis/vscode-jest-499
npm i

under src folder there are two files. evaporator.ts which shows coverage as expected, and brainluck.ts which does not.

P.S. using dev tools i see the following error. @garyking, is this the same issue you already fixed?
mainThreadExtensionService.ts:66 Error: Invalid arguments
at new f (/home/amir/.vscode-server/bin/9579eda04fdb3a9bba2750f15193e5fafe16b959/out/vs/server/remoteExtensionHostProcess.js:380)
at new f (/home/amir/.vscode-server/bin/9579eda04fdb3a9bba2750f15193e5fafe16b959/out/vs/server/remoteExtensionHostProcess.js:378)
at /home/amir/.vscode-server/extensions/orta.vscode-jest-3.0.2/out/extension.js:129
at Array.forEach ()
at /home/amir/.vscode-server/extensions/orta.vscode-jest-3.0.2/out/extension.js:129
at Array.forEach ()
at t.DefaultFormatter.formatBranches (/home/amir/.vscode-server/extensions/orta.vscode-jest-3.0.2/out/extension.js:129)
at t.DefaultFormatter.format (/home/amir/.vscode-server/extensions/orta.vscode-jest-3.0.2/out/extension.js:129)
at s.update (/home/amir/.vscode-server/extensions/orta.vscode-jest-3.0.2/out/extension.js:75)
at s.updateVisibleEditors (/home/amir/.vscode-server/extensions/orta.vscode-jest-3.0.2/out/extension.js:75)
at t.JestExt.triggerUpdateActiveEditor (/home/amir/.vscode-server/extensions/orta.vscode-jest-3.0.2/out/extension.js:427)
at t.JestExt.onDidChangeActiveTextEditor (/home/amir/.vscode-server/extensions/orta.vscode-jest-3.0.2/out/extension.js:427)
at t.ExtensionManager.onDidChangeActiveTextEditor (/home/amir/.vscode-server/extensions/orta.vscode-jest-3.0.2/out/extension.js:129)
at l.fire (/home/amir/.vscode-server/bin/9579eda04fdb3a9bba2750f15193e5fafe16b959/out/vs/server/remoteExtensionHostProcess.js:46)
at /home/amir/.vscode-server/bin/9579eda04fdb3a9bba2750f15193e5fafe16b959/out/vs/server/remoteExtensionHostProcess.js:659
at l.fire (/home/amir/.vscode-server/bin/9579eda04fdb3a9bba2750f15193e5fafe16b959/out/vs/server/remoteExtensionHostProcess.js:46)
at f.$acceptDocumentsAndEditorsDelta (/home/amir/.vscode-server/bin/9579eda04fdb3a9bba2750f15193e5fafe16b959/out/vs/server/remoteExtensionHostProcess.js:579)
at p._doInvokeHandler (/home/amir/.vscode-server/bin/9579eda04fdb3a9bba2750f15193e5fafe16b959/out/vs/server/remoteExtensionHostProcess.js:681)
at p._invokeHandler (/home/amir/.vscode-server/bin/9579eda04fdb3a9bba2750f15193e5fafe16b959/out/vs/server/remoteExtensionHostProcess.js:680)
at p._receiveRequest (/home/amir/.vscode-server/bin/9579eda04fdb3a9bba2750f15193e5fafe16b959/out/vs/server/remoteExtensionHostProcess.js:679)
at p._receiveOneMessage (/home/amir/.vscode-server/bin/9579eda04fdb3a9bba2750f15193e5fafe16b959/out/vs/server/remoteExtensionHostProcess.js:678)
at /home/amir/.vscode-server/bin/9579eda04fdb3a9bba2750f15193e5fafe16b959/out/vs/server/remoteExtensionHostProcess.js:676
at l.fire (/home/amir/.vscode-server/bin/9579eda04fdb3a9bba2750f15193e5fafe16b959/out/vs/server/remoteExtensionHostProcess.js:46)
at _.fire (/home/amir/.vscode-server/bin/9579eda04fdb3a9bba2750f15193e5fafe16b959/out/vs/server/remoteExtensionHostProcess.js:189)
at /home/amir/.vscode-server/bin/9579eda04fdb3a9bba2750f15193e5fafe16b959/out/vs/server/remoteExtensionHostProcess.js:838
at l.fire (/home/amir/.vscode-server/bin/9579eda04fdb3a9bba2750f15193e5fafe16b959/out/vs/server/remoteExtensionHostProcess.js:46)
at _.fire (/home/amir/.vscode-server/bin/9579eda04fdb3a9bba2750f15193e5fafe16b959/out/vs/server/remoteExtensionHostProcess.js:189)
at t.PersistentProtocol._receiveMessage (/home/amir/.vscode-server/bin/9579eda04fdb3a9bba2750f15193e5fafe16b959/out/vs/server/remoteExtensionHostProcess.js:193)
at /home/amir/.vscode-server/bin/9579eda04fdb3a9bba2750f15193e5fafe16b959/out/vs/server/remoteExtensionHostProcess.js:190
at l.fire (/home/amir/.vscode-server/bin/9579eda04fdb3a9bba2750f15193e5fafe16b959/out/vs/server/remoteExtensionHostProcess.js:46)
at p.acceptChunk (/home/amir/.vscode-server/bin/9579eda04fdb3a9bba2750f15193e5fafe16b959/out/vs/server/remoteExtensionHostProcess.js:186)
at /home/amir/.vscode-server/bin/9579eda04fdb3a9bba2750f15193e5fafe16b959/out/vs/server/remoteExtensionHostProcess.js:186
at Socket.t (/home/amir/.vscode-server/bin/9579eda04fdb3a9bba2750f15193e5fafe16b959/out/vs/server/remoteExtensionHostProcess.js:195)
at Socket.emit (events.js:200)
at addChunk (_stream_readable.js:294)
at readableAddChunk (_stream_readable.js:275)
at Socket.Readable.push (_stream_readable.js:210)
at TCP.onStreamRead (internal/stream_base_commons.js:166)

this should be addressed in v3.1.0, feel free to reopen if not...

3.10 solved the problem for me. Cheers!

Still seeing this on 3.2.0. @connectdotz can this be reopened?

package versions:

"jest": "26",
"ts-jest": "26.3.0",
"typescript": "4.0.2",

VS Code version:

Version: 1.49.0
Commit: e790b931385d72cf5669fcefc51cdf65990efa5d
Date: 2020-09-10T17:39:53.251Z
Electron: 9.2.1
Chrome: 83.0.4103.122
Node.js: 12.14.1
V8: 8.3.110.13-electron.0
OS: Darwin x64 19.5.0

jest.config.js:

module.exports = {
    testEnvironment: 'jsdom',
    preset: 'ts-jest/presets/js-with-ts',
    // transformIgnorePatterns: [ "/node_modules/(?!MODULE_NAME_HERE).+\\.js$"],
    clearMocks: true,
    collectCoverageFrom: ['src/**/*.{js,jsx,ts,tsx}'],
    setupFiles: ['<rootDir>/jest.shim.js', '<rootDir>/jest.setup.js'],
    moduleNameMapper: {
        '\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$':
            '<rootDir>/__mocks__/fileMock.js',
        '\\.(css|less)$': 'identity-obj-proxy'
    },
    coverageDirectory: 'coverage',
    coverageThreshold: {
        global: {
            statements: 54,
            branches: 50,
            functions: 47,
            lines: 54
        }
    }
};

error message is:

mainThreadExtensionService.ts:66 Error: Invalid arguments
    at new w (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:501)
    at new w (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:497)
    at /Users/tanderson9/.vscode/extensions/orta.vscode-jest-3.2.0/out/extension.js:129
    at Array.forEach (<anonymous>)
    at /Users/tanderson9/.vscode/extensions/orta.vscode-jest-3.2.0/out/extension.js:129
    at Array.forEach (<anonymous>)
    at t.GutterFormatter.computeFormatting (/Users/tanderson9/.vscode/extensions/orta.vscode-jest-3.2.0/out/extension.js:129)
    at t.GutterFormatter.format (/Users/tanderson9/.vscode/extensions/orta.vscode-jest-3.2.0/out/extension.js:129)
    at s.update (/Users/tanderson9/.vscode/extensions/orta.vscode-jest-3.2.0/out/extension.js:75)
    at s.updateVisibleEditors (/Users/tanderson9/.vscode/extensions/orta.vscode-jest-3.2.0/out/extension.js:75)
    at t.JestExt.triggerUpdateActiveEditor (/Users/tanderson9/.vscode/extensions/orta.vscode-jest-3.2.0/out/extension.js:385)
    at t.JestExt.onDidChangeActiveTextEditor (/Users/tanderson9/.vscode/extensions/orta.vscode-jest-3.2.0/out/extension.js:385)
    at t.ExtensionManager.onDidChangeActiveTextEditor (/Users/tanderson9/.vscode/extensions/orta.vscode-jest-3.2.0/out/extension.js:129)
    at l.fire (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:46)
    at /Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:821
    at l.fire (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:46)
    at b.acceptDocumentsAndEditorsDelta (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:699)
    at b.$acceptDocumentsAndEditorsDelta (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:697)
    at g._doInvokeHandler (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:860)
    at g._invokeHandler (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:860)
    at g._receiveRequest (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:858)
    at g._receiveOneMessage (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:857)
    at /Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:855
    at l.fire (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:46)
    at v.fire (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:256)
    at /Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:1047
    at l.fire (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:46)
    at v.fire (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:256)
    at t.PersistentProtocol._receiveMessage (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:261)
    at /Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:258
    at l.fire (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:46)
    at p.acceptChunk (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:253)
    at /Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:253
    at Socket.t (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:263)
    at Socket.emit (events.js:223)
    at Socket.EventEmitter.emit (/Applications/Visual%20Studio%20Code.app/Contents/Resources/app/out/vs/code/electron-browser/workbench/domain.js:475)
    at addChunk (_stream_readable.js:309)
    at readableAddChunk (_stream_readable.js:290)
    at Socket.Readable.push (_stream_readable.js:224)
    at Pipe.onStreamRead (internal/stream_base_commons.js:181)
Was this page helpful?
0 / 5 - 0 ratings

Related issues

somewhatabstract picture somewhatabstract  ·  4Comments

skippednote picture skippednote  ·  3Comments

ryanlittle picture ryanlittle  ·  3Comments

exapsy picture exapsy  ·  3Comments

alloy picture alloy  ·  3Comments