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

Exception while collecting coverage metrics #207

Closed
holgergp opened this issue Jul 27, 2018 · 6 comments
Closed

Exception while collecting coverage metrics #207

holgergp opened this issue Jul 27, 2018 · 6 comments

Comments

@holgergp
Copy link

holgergp commented Jul 27, 2018

Hi,

I am encountering a crash of nyc when collecting code coverage (looking at coverage from Jest and Cucumberjs) when executing $ nyc report --reporter=lcov
I am using "nyc": "12.0.2",
The following exception is raised

TypeError: Cannot read property 'decl' of undefined
    at /myProject/node_modules/nyc/node_modules/istanbul-reports/lib/lcovonly/index.js:32:38
    at Array.forEach (<anonymous>)
    at LcovOnlyReport.onDetail (/myProject/node_modules/nyc/node_modules/istanbul-reports/lib/lcovonly/index.js:30:28)
...

This only occurs when executing this in an Gitlab CI environment based on an node:8 Docker image.
If I run this locally everything is fine.
I doublechecked the source mentioned in the stacktrace, but I am afraid I cannot get my head around it: Somehow the meta object is undefined where it shouldn't be.

Any idea what I could be doing wrong here?
Thanks for your help!

@mindriven
Copy link

same here

@ReuDa
Copy link

ReuDa commented Aug 1, 2018

+1 :-(

@sveg-pl
Copy link

sveg-pl commented Aug 1, 2018

Hi Guys,

I stumbled across this error in my project last week. What is interesting, is the intermittent nature of this issue - it affected my copy of the code base and some other guys' in my team, yet there were people not experiencing this bug at all. Moreover, when I purged all node_modules directories, all lock files, build and coverage folders, after npm i the bug was still present. However, when the project was cloned to a new directory the coverage report was generated without any problems...

These are my observations:

  • it's connected to the lcov report type, so when I changed it to 'text', everything was working well;
  • this variable which is undefined when istanbul is trying to read the decl property is related to the number of function's hits in a certain test file. When this number is 0 (so no code was covered in the whole file), we are getting undefined.

So why no functions were hit by coverage? In my case, it was caused by an ES6 arrow notation of function in the file's export. It was basically something like:

export default prop => (/*some expression using the prop*/)

when I changed it to the export default function (prop) { return (/*code*/) } the coverage was being counted properly.

Temporary solutions I tried:

  • exclude test file(s) which are causing this issue in jest's collectCoverageFrom option (our project is based on create-react-app);
  • change the arrow notation in export.

Hope it helps.

@holgergp
Copy link
Author

holgergp commented Sep 7, 2018

Thanks for your hints and sorry for not answering for quite some time.

In the light of the new version of nyc, I gave another shot at fixing that crash.

Things I tried in the meantime, that were unsuccessful:

  • pinpoint a single test as culprit,
  • different report types made no difference,
  • the --all option

While the new version did not solve our issue, I dug into the docs of Babel-Plugin-Istanbul and this seemed to do the trick.

Until the point nyc stopped working in our setup, we didn't need to bybass Babel instrumentation in the context of istanbul. Now that seems to be necessary.
I added babel-register and introduced a .nycrc:

{
    "require": ["babel-register"],
    "sourceMap": false,
    "instrument": false
}

Now the coverage generation works again!

Your temporary solution of using ES5 functions instead of arrow functions, may point in that direction as well. How do you deal with babel instrumentation?

@holgergp
Copy link
Author

holgergp commented Sep 7, 2018

Closing as it works for me now.

@holgergp holgergp closed this as completed Sep 7, 2018
@alexandermckay
Copy link

Coming to this in 2020:

{
  "require": ["@babel/register"]
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants