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

Cannot read property 'loc' of undefined #184

Closed
Oloompa opened this issue Jan 3, 2020 · 16 comments
Closed

Cannot read property 'loc' of undefined #184

Oloompa opened this issue Jan 3, 2020 · 16 comments

Comments

@Oloompa
Copy link

Oloompa commented Jan 3, 2020

  • Version:V12.14.0
  • Platform:Linux 4.19.0-6-amd64 Detailed coverage #1 SMP Debian 4.19.67-2+deb10u2 (2019-11-11) x86_64 GNU/Linux

Hello, updating C8 to V7 i get the following error (in place of report)

TypeError: Cannot read property 'loc' of undefined
    at ~/my-project/node_modules/istanbul-reports/lib/lcovonly/index.js:53:35
    at Array.forEach (<anonymous>)
    at LcovOnlyReport.onDetail (~/my-project/node_modules/istanbul-reports/lib/lcovonly/index.js:51:34)
    at LcovReport.<computed> [as onDetail] (~/my-project/node_modules/istanbul-reports/lib/lcov/index.js:25:23)
    at Visitor.value (~/my-project/node_modules/istanbul-lib-report/lib/tree.js:38:38)
    at ReportNode.visit (~/my-project/node_modules/istanbul-lib-report/lib/tree.js:88:21)
    at ~/my-project/node_modules/istanbul-lib-report/lib/tree.js:92:19
    at Array.forEach (<anonymous>)
    at ReportNode.visit (~/my-project/node_modules/istanbul-lib-report/lib/tree.js:91:28)
    at ~/my-project/node_modules/istanbul-lib-report/lib/tree.js:92:19

the command i run npx c8 ava --fail-fast --verbose ./build/test/file.spec.js

I use the following .nycrc.json

{
    "extension": [".ts"],
    "include": ["build/server"],
    "exclude": [],
    "reporter": ["lcov", "text", "html", "text-summary"],
    "cache": false,
    "sourceMap": true,
    "instrument": true,
    "all": true,
    "check-coverage": true,
    "branches": 80,
    "lines": 80,
    "functions": 80,
    "statements": 80,
    "watermarks": {
        "lines": [80, 95],
        "functions": [80, 95],
        "branches": [80, 95],
        "statements": [80, 95]
    }
}
@bcoe
Copy link
Owner

bcoe commented Jan 3, 2020

@Oloompa could you provide a minimal reproduction of this issue in the form of a repository? I use lcov reports extensively and haven't bumped into this.

Could you also try running with the latest version of nyc, I'm curious if this is an issue with c8, or with the reporters which have also been updated recently.

@coreyfarrell
Copy link

Please try removing "all": true, let us know if you still get the error.

@Oloompa
Copy link
Author

Oloompa commented Jan 6, 2020

@coreyfarrell thanks, you found the way to fix it. It works now !

@Oloompa Oloompa closed this as completed Jan 6, 2020
@coreyfarrell
Copy link

I think this is still a valid bug, it shows that all: true (a new feature to c8) is failing for you. I'm sure @bcoe would still appreciate seeing a reproduction of the issue so it can be investigated further.

@bcoe bcoe reopened this Jan 6, 2020
@bcoe
Copy link
Owner

bcoe commented Jan 6, 2020

@j03m this is an odd one, first bug I've seen related to --all.

@Oloompa
Copy link
Author

Oloompa commented Jan 7, 2020

I finally removed .nycrc from all my projects but it's pretty easy to reproduce the bug. You need V7.0.0 of C8 and setup .nycrc file. I use typescript but as i transpile first (without tsnode) there is no impact.

@j03m j03m self-assigned this Jan 13, 2020
@j03m
Copy link
Collaborator

j03m commented Jan 13, 2020

I will take a look at this asap.

@j03m
Copy link
Collaborator

j03m commented Jan 18, 2020

@Oloompa I was wondering if you could possibly tell me more about your project or provide a sample replication? I spent some time on this today setting up a project based on what I could ascertain about your set up. I made some guesses as to your tsconfig etc but so far I've had no luck with replication. I may just need your tsconfig file and perhaps any ava configs, but a sample project that crashes would be ideal.

I will also attach the project I created. Running this with node and your nyc config works as expected for me. I'm going to try wiring up something with Ava now.

@j03m
Copy link
Collaborator

j03m commented Jan 18, 2020

My first replication attempts: c8-issue-184.zip

@j03m
Copy link
Collaborator

j03m commented Jan 18, 2020

Hmm added ava and still working. This is a tough one.

  ✔ foo
  ✔ bar

  2 tests passed

---------------|---------|----------|---------|---------|-------------------
File           | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s 
---------------|---------|----------|---------|---------|-------------------
All files      |   76.74 |       60 |   78.57 |   76.74 |                   
 src           |      80 |    72.73 |     100 |      80 |                   
  loaded.ts    |   73.68 |    71.43 |     100 |   73.68 | 4,5,16-18         
  main.ts      |     100 |       75 |     100 |     100 | 6                 
 src/dir       |       0 |        0 |       0 |       0 |                   
  unloaded.ts  |       0 |        0 |       0 |       0 | 1-5               
 src/test      |     100 |    58.33 |      80 |     100 |                   
  file.spec.ts |     100 |    58.33 |      80 |     100 | 1,13              
---------------|---------|----------|---------|---------|-------------------

=============================== Coverage summary ===============================
Statements   : 76.74% ( 33/43 )
Branches     : 60% ( 36/60 )
Functions    : 78.57% ( 11/14 )
Lines        : 76.74% ( 33/43 )
================================================================================
ERROR: Coverage for lines (76.74%) does not meet global threshold (80%)
ERROR: Coverage for functions (78.57%) does not meet global threshold (80%)
ERROR: Coverage for branches (60%) does not meet global threshold (80%)
ERROR: Coverage for statements (76.74%) does not meet global threshold (80%)

@coreyfarrell
Copy link

@j03m In nyc 14 I saw this sort of issue when source-map mismatches occurred. An example of this for nyc is if you ran nyc --all mocha --require ts-node/register. This caused --all to run without ts-node/register but then the actual tests ran with ts-node/register. So when lib/index.ts was imported by a test we would add coverage to the transpiled copy vs --all which would add coverage to the original source.

I'm unsure if/how this would apply to c8? In nyc the solution was to filter out known files from the --all coverage.

@coreyfarrell
Copy link

Additional note, if you set all: true to every file in the coverage object generated by c8 --all then istanbul-lib-coverage should handle this filtering for you.

@Oloompa
Copy link
Author

Oloompa commented Jan 20, 2020

@j03m Well i am confused.
I tried to set up a new project with same context (same dependency versions too). I am unable to reproduce it.

@bcoe
Copy link
Owner

bcoe commented Jan 20, 2020

@Oloompa fascinating, I wonder if there was something odd in the node_modules folder that was corrected? is all working for you, and we can close this as can't reproduce?

@Oloompa
Copy link
Author

Oloompa commented Jan 21, 2020

@bcoe it's very strange and frustrating. Yes we should close it until someone reproduce it.

@Oloompa Oloompa closed this as completed Jan 21, 2020
@shigma
Copy link

shigma commented Aug 15, 2020

I'm running into this issue too. I will try to provide a reproduction.

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

No branches or pull requests

5 participants