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.

Code coverage comments like `/* istanbul ignore file */` are ignored for jsx files

See original GitHub issue

Is this a bug report?

Yes

Did you try recovering your dependencies?

Yes - I have a minimum repo to reproduce.

Which terms did you search for in User Guide?

istanbul comment coverage comment

Environment

System: OS: Windows 10 CPU: x64 Intel® Core™ i7-8550U CPU @ 1.80GHz Binaries: Yarn: 1.12.3 - C:\Program Files (x86)\Yarn\bin\yarn.CMD npm: 6.4.1 - C:\Program Files\nodejs\npm.CMD Browsers: Edge: 42.17134.1.0 Internet Explorer: 11.0.17134.1 npmPackages: react: ^16.7.0 => 16.7.0 react-dom: ^16.7.0 => 16.7.0 react-scripts: 2.1.2 => 2.1.2 npmGlobalPackages: create-react-app: Not Found

Steps to Reproduce

Code coverage comments like /* istanbul ignore file */ are ignored for jsx files. When you set up a new app, adding this line to index.js doesn’t work. This seems to be related to the Babel config as pure JS files work fine.

Here’s an example repo:

  1. Clone https://github.com/dbartholomae/coverage-bug
  2. Run npm test (note that the command is modified in package.json and includes the coverage flag)

This could be related to #5756

Expected Behavior

Neither index.js nor index-no-jsx.js should show up in the coverage-report.

Actual Behavior

index.js shows up in the coverage-report.

Reproducible Demo

See “Steps to Reproduce”

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:9
  • Comments:13 (7 by maintainers)

github_iconTop GitHub Comments

110reactions
jensbodalcommented, Nov 5, 2019

FWIW, for me the file was was only ignored if I placed this comment at the top of the file and had a newline between it and the next block:

WORKS

/* istanbul ignore file */

import { Foo } from 'bar';

DOES NOT WORK

/* istanbul ignore file */
import { Foo } from 'bar';
12reactions
FezVrastacommented, Feb 13, 2019

@mrmckeb may you guys add some label to prevent this from getting auto-closed by the stale bot? This is a verified issue, there’s no reason to close it automatically just because you guys are busy working on other things.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Istanbul Ignore Syntax for Jest Code Coverage
Sometimes we need to exclude some code from the coverage calculations. This is done with special comments which are parsed by Istanbul. There ......
Read more >
How to exclude files from Istanbul nyc coverage report
My coverage report seems to be working fine other than it not ignoring the files in my exclude array. I have tried adding...
Read more >
Sonar doesn't respect istanbul ignore comments
Hi @ganncamp, in my case I am explicitly marking a file to be ignored, and jest (which is setup to cover files that...
Read more >
Istanbul
Code coverage tool that computes statement, line, function and branch coverage ... The nyc command-line-client for Istanbul works well with most JavaScript ...
Read more >
Jest ignore or exclude file/function/statement from test ...
As stated by the maintainers and authors of the istanbul coverage libary: Some branches in JS code are typically hard, if not impossible...
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