Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Coverage in HTML view is broken #9388

Closed
adyz opened this issue Jan 10, 2020 · 24 comments
Closed

Coverage in HTML view is broken #9388

adyz opened this issue Jan 10, 2020 · 24 comments

Comments

@adyz
Copy link

adyz commented Jan 10, 2020

🐛 Bug Report

To Reproduce

Steps to reproduce the behavior: (same as: https://jestjs.io/docs/en/getting-started)

  • Create a new folder
  • Init a new npm project with npm init
  • Add Jest as a dependency npm install --save-dev jest
  • Created a src folder with a main.js file and a main.spec.js test file (one containing sum function and the other the tests as in the Jest docs)
  • Added a test script in package.json.
  • Run the script with npm test -- --coverage
  • When opening the coverage/lcov-report/index.html the HTML does not show the coverage report numbers.

Screenshot

GIT repo here: https://github.com/adyz/jest-coverage-bug-no-ts

Expected behavior

The coverage/lcov-report/index.html should show the actual report numbers

Link to repl or repo (highly encouraged)

https://github.com/adyz/jest-coverage-bug-no-ts

envinfo

npx: installed 1 in 1.36s

  System:
    OS: macOS 10.15.2
    CPU: (16) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
  Binaries:
    Node: 13.6.0 - /usr/local/bin/node
    Yarn: 1.12.3 - ~/.yarn/bin/yarn
    npm: 6.13.4 - /usr/local/bin/npm
  npmPackages:
    jest: ^24.9.0 => 24.9.0 

Let me know if I should send this to the istanbul.js as well or just there. Not sure where to go from here.
I've also noticed that on old projects the report is fine until I remove the node_modules and reinstall.

Thanks a ton!

@SimenB
Copy link
Member

SimenB commented Jan 10, 2020

This seems like a bug in istanbul somewhere, as the text reporter works correctly.

image

@coreyfarrell have you seen this before?

Note that it works correctly on Jest master (which is using the new major of istanbul deps)
image

@SimenB
Copy link
Member

SimenB commented Jan 10, 2020

#9389 (comment)

diff --git i/package-lock.json w/package-lock.json
index 4ae4388..9e5ba91 100644
--- i/package-lock.json
+++ w/package-lock.json
@@ -2186,9 +2186,9 @@
       "dev": true
     },
     "handlebars": {
-      "version": "4.6.0",
-      "resolved": "https://registry.npmjs.org/handlebars/-/handlebars-4.6.0.tgz",
-      "integrity": "sha512-i1ZUP7Qp2JdkMaFon2a+b0m5geE8Z4ZTLaGkgrObkEd+OkUKyRbRWw4KxuFCoHfdETSY1yf9/574eVoNSiK7pw==",
+      "version": "4.5.3",
+      "resolved": "https://registry.npmjs.org/handlebars/-/handlebars-4.5.3.tgz",
+      "integrity": "sha512-3yPecJoJHK/4c6aZhSvxOyG4vJKDshV36VHp0iVCDVh7o9w2vwi3NSnL2MMPj3YdduqaBcu7cGbggJQM0br9xA==",
       "dev": true,
       "requires": {
         "neo-async": "^2.6.0",
diff --git i/package.json w/package.json
index 901fec3..2971de5 100644
--- i/package.json
+++ w/package.json
@@ -9,6 +9,7 @@
   "author": "",
   "license": "ISC",
   "devDependencies": {
+    "handlebars": "~4.5.3",
     "jest": "^24.9.0"
   }
 }

@SimenB
Copy link
Member

SimenB commented Jan 10, 2020

I've quickly opened up handlebars-lang/handlebars.js#1636 upstream linking back to this issue for the reproduction

@coreyfarrell
Copy link
Contributor

I've pushed the latest-2.x branch to https://github.com/istanbuljs/istanbuljs with a cherry-pick of the handlebars removal patch.

Publishing this to npm is difficult for me as it's not possible to publish under the npm next tag, istanbul-reports@3.0.0 is already latest so any 2.x backport will automatically be available in production.

I'd appreciate anyone who has the time to manually test my patch. Due to istanbul-reports being in a monorepo it's not possible to have npm install directly from git, the following process must be followed:

  • git clone https:/github.com/istanbuljs/istanbuljs
  • git checkout latest-2.x
  • cd istanbuljs/packages/istanbul-reports
  • npm pack
  • add "istanbul-reports": "file:absolute/path/to/istanbul-reports-2.2.5.tgz" to the dependencies of your project
  • do what is necessary to ensure istanbul-reports from the tarball is the only version installed in your project (npm ls handlebars should not show it being installed by istanbul-reports)
  • test your project, verify that HTML reports work

I've done this already with the self-tests of nyc@14.1.1 and it seemed to work but I'd like to get some confirmation before I can publish this fix to npm.

@adyz
Copy link
Author

adyz commented Jan 10, 2020

Hi @coreyfarrell,

I've followed your steps it seems to work well with the repo posted on this issue: https://github.com/adyz/jest-coverage-bug-no-ts

  • added the generated tgz file (generated following your steps) in package.json"istanbul-reports": "file:../test-istanbul/istanbuljs/packages/istanbul-reports/istanbul-reports-2.2.5.tgz"
  • removed package-lock.json and node_modules
  • ran npm install again
  • ran npm npm test -- --coverage and the HTML looks fine now

Thanks a ton!

@adyz
Copy link
Author

adyz commented Jan 10, 2020

Actually, I've tried to add my changes on a separate branch on my repo and the HTML it's not working anymore... I'll try again this weekend alt will let you know... sorry for the false positive

@coreyfarrell
Copy link
Contributor

Thanks for testing, istanbul-reports gets 6+ million downloads per week so releasing a broken version would bombard me with reports (I suspect many people are not seeing this handlebars bug due to package-lock files). I'm going to give this a little time to hopefully get a couple more testers before I publish (I'm also still fighting with CI for the istanbuljs repo itself).

@coreyfarrell
Copy link
Contributor

BTW you'll want to remove package-lock.json, not package.json. I'm guessing that was just a typo here.

@adyz
Copy link
Author

adyz commented Jan 10, 2020

Yes, typo, sorry. Not sure what is happening with my machine that first time worked and the second time did not. Definitely wait a bit more before release and more tests.

@coreyfarrell
Copy link
Contributor

In the case where it fails what does npm ls handlebars show?

@adyz
Copy link
Author

adyz commented Jan 11, 2020

Sorry for the late response @coreyfarrell

└─┬ jest@24.9.0
  └─┬ jest-cli@24.9.0
    └─┬ @jest/core@24.9.0
      └─┬ @jest/reporters@24.9.0
        └─┬ istanbul-reports@2.2.6
          └── handlebars@4.7.0 

Not sure what was the desired version.

I've created a branch here with the changes:
https://github.com/adyz/jest-coverage-bug-no-ts/tree/test/local-istanbul

I hope it helps!

Thank you!

@coreyfarrell
Copy link
Contributor

Yes this helps, istanbul-reports@2.x already had a backport that didn't get merged into master and I forgot about, so my patched copy of istanbul-reports@2.2.5 wasn't being used by jest. I've pushed a couple more commits, please git pull, run npm pack again (this should create istanbul-reports-2.2.6.tgz), then update the tarball version in your repository and reinstall. Once this is done npm ls handlebars should not show any result.

@adyz
Copy link
Author

adyz commented Jan 11, 2020

Wuhu! Works! The HTML is generated 🥳
I'll be able to do more tests on other projects on Monday using this method if you wish.

@adyz
Copy link
Author

adyz commented Jan 11, 2020

Pushed the changes and the newly generated package here: https://github.com/adyz/jest-coverage-bug-no-ts/tree/test/local-istanbul

@SimenB
Copy link
Member

SimenB commented Jan 11, 2020

Let's keep this open for visibility until a new version of istanbul-reports@2 is published to npm

@SimenB SimenB reopened this Jan 11, 2020
@coreyfarrell
Copy link
Contributor

@adyz thanks for the update. No further testing is needed. I'm planning to release a new version of istanbul-reports@2 soon. Will comment again when that is complete.

@coreyfarrell
Copy link
Contributor

istanbul-reports 2.2.7 is now published to npm. Can anyone confirm this fixes the issue as experienced by jest users?

@SimenB
Copy link
Member

SimenB commented Jan 12, 2020

Deleting the existing istanbul-reports from your lockfile and re-running npm or yarn should fix the issue. It works in the project I tested, so I think we're good to go 👍

@SimenB SimenB closed this as completed Jan 12, 2020
@adyz
Copy link
Author

adyz commented Jan 13, 2020

I've posted this bug for a project that now is working perfectly!

I've removed the node_modules folder and the package-lock.json file.

Thank you!
🥳🥳🥳

@springfred
Copy link

Coverage in HTML view is broken.
npm ls handlebars
└─┬ istanbul@1.1.0-alpha.1
└─┬ istanbul-api@1.3.7
└─┬ istanbul-reports@1.5.1
└── handlebars@4.7.2

@coreyfarrell
Copy link
Contributor

@springfred istanbul-reports@1.5.1 is no longer maintained (current version is 3.0.0). The best fix is to upgrade your dependencies so istanbul-reports@2.2.7 or above is used. If this is not an option you will need to pin handlebars in your own package.json to 4.5.3 then perform a fresh npm install.

@SimenB
Copy link
Member

SimenB commented Jan 15, 2020

Jest upgraded to istanbul v2 as part of the Jest v24 release (in #7016, to be exact), so upgrading to v24 should fix your issue (as it'll pull in the fixed version of istanbul-reports@2)

@dpdahal
Copy link

dpdahal commented Mar 27, 2020

hello everyone's why not working this code.
{{#each posts}}

{{_id}}
{{title}}
{{status}}
{{description}}

                                    </tr>
                                {{/each}}

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 11, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants