question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Coverage not shown on typescript

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:4
  • Comments:11 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
mdebruijnecommented, Oct 8, 2019

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)

2reactions
Acanguvencommented, Oct 14, 2019

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Code coverage is not showing on Sonarqube for Typescript
While I run the unit tests with jest, they are all passing and code coverage was about 80%. On Sonarqube it is still...
Read more >
Javascript/Typescript test coverage - SonarQube Documentation
SonarQube supports the reporting of test coverage information as part of the analysis of your JS/TS project. However, SonarQube does not generate the...
Read more >
coverage for some .ts files shown as zero coverage - SonarQube
This explain why you see 0% on some test files. Once these files will be correctly considered as test files, no coverage data...
Read more >
typescript-coverage-report - npm
Node command tool to generate TypeScript coverage report.. Latest version: 0.7.0, last published: a month ago.
Read more >
Configuring Code Coverage for TypeScript Files in Jest
The second one is going to be not with the exclamation points source/**/*.d.ts. We're telling it to collect coverage from all your typescript...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found