jest-community / vscode-jest

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

Coverage not shown on typescript #499

Closed jeantil closed 4 years ago

jeantil commented 5 years ago

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
    180@1.0.0 /Users/jean/dev/startups/yupwego/src/vscode-jest-499
    └── jest@24.9.0
  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 "jest@24.9.0"
    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

mikaoelitiana commented 4 years ago

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

Luca-Terrazzan commented 4 years ago

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

mdebruijne commented 4 years ago

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)

Luca-Terrazzan commented 4 years ago

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.

Acanguven commented 4 years ago

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

Gorthog commented 4 years ago

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

jeantil commented 4 years ago

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
garyking commented 4 years ago

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

Gorthog commented 4 years ago

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)

connectdotz commented 4 years ago

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

Gorthog commented 4 years ago

3.10 solved the problem for me. Cheers!