gotwarlost / istanbul

Yet another JS code coverage tool that computes statement, line, function and branch coverage with module loader hooks to transparently add coverage when running tests. Supports all JS coverage use cases including unit tests, server side functional tests and browser tests. Built for scale.
Other
8.7k stars 786 forks source link

Code coverage 0% on file until I add a single line comment #837

Open duro opened 7 years ago

duro commented 7 years ago

I have a super bizarre issue where a very simple file that has no dynamic content (it's a very simple styled-components React component) and is imported by a parent class comes back 0% covered,

But, then I add a single line comment, and it comes back 100% (as I would have expected it.

Here is the code of the file when it comes back 0%:

import styled from 'styled-components'

export default styled.svg`
  display: inline-block;
  vertical-align: top;
`

And I make this very simple change, and it comes back 100%

import styled from 'styled-components'

// Code coverage needs this comment because... Aliens
export default styled.svg`
  display: inline-block;
  vertical-align: top;
`

I am using Instanbul with Jest via a non-ejected React Create App at the latest version (1.0.12)

dstudzinski commented 6 years ago

Same here.

I have 0% coverage for 2 files (I have >300 suites and > 1200 tests in total) until I add comment somewhere in the file. It doesn't matter if I comment with // comment or /* comment */ Text in the comment can be anything and comment can be placed anywhere in the file. I don't have ignore comments (https://github.com/gotwarlost/istanbul/blob/master/ignoring-code-for-coverage.md) in my files.

My config is based on CRA too. It's really strange and I really don't know what happens.