create-react-app: Code coverage comments like `/* istanbul ignore file */` are ignored for jsx files

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”

About this issue

  • Original URL
  • State: open
  • Created 6 years ago
  • Reactions: 9
  • Comments: 16 (7 by maintainers)

Commits related to this issue

Most upvoted comments

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';

@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.

Hi @dbartholomae, you can actually use Jest here to ignore files. I know Istanbul comments work with Jest, but I’m not sure that specific comment does.

As an example, here I’m ignoring all tsx files (for no good reason):

  "jest": {
    "collectCoverageFrom": [
      "src/**/*.{js,jsx,ts}", 
      "!src/**/*.tsx"
    ],
  }

When using coverageProvider: "v8", the /* istanbul ignore file */ is totally ignored.

In my case, the file I add the comment to drops to 0% coverage even if it was higher without the comment (rather than ignoring it)