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

Error on html report generation #94

Closed
evil-shrike opened this issue Aug 29, 2013 · 8 comments
Closed

Error on html report generation #94

evil-shrike opened this issue Aug 29, 2013 · 8 comments

Comments

@evil-shrike
Copy link

I have a coverage.json file with coverage info extracted from within browser after qunit tests completed (as value of window.coverage). No I'm trying to generate a html report:

Then I execute:

istanbul report html coverage.json 

and get the following error:

C:\...\Client\node_modules\istanbul\lib\report\html.js:156
        structuredText[lineNumber].covered = count > 0 ? 'yes' : 'no';
                                                 ^
TypeError: Cannot set property 'covered' of undefined
    at C:\...\Client\node_modules\istanbul\lib\report\html.js:156:66
    at Array.forEach (native)
    at annotateLines (C:\...\Client\node_modules\istanbul\lib\report\html.js:154:28)
    at HtmlReport.Report.mix.writeDetailPage (C:\...\Client\node_modules\istanbul\lib\report\html.js:370:9)
    at C:\...\Client\node_modules\istanbul\lib\report\html.js:435:26
    at AsyncFileWriter.extend.processFile (C:\...\Client\node_modules\istanbul\lib\util\file-writer.js:93:9)
    at Object.q.process [as _onImmediate] (C:\...\Client\node_modules\istanbul\node_modules\async\lib\async.js:728:21)
    at processImmediate [as _immediateCallback] (timers.js:317:15)

"text" report generation works.

@gotwarlost
Copy link
Owner

Only the HTML report uses the actual sources of your files for annotating the uncovered lines and branches.

If for any reason your source files have changed between the time they were instrumented and the reporting, you will see this error. So, is it possible that your source files may have changed in the interim?

@evil-shrike
Copy link
Author

It's absolutely impossible. I have a grunt build workflow which :

  • copy sources into temp dir
  • run istanbul to instrument files in this dir:
grunt.file.write(filepath, instrumenter.instrumentSync(String(fs.readFileSync(filepath)), filepath));
  • start connect local server with instrumented sources folder mounted
  • run qunit tests against local server via phantomjs
  • catch window.coverage inside browser and return it to the host (grunt task)
  • save reported coverage info into a file (coverage.json)
  • run 'istanbul report html'

I added some logging into report/html.js:

Object.keys(lineStats):
1,3,8,22,24,25,26,27,28,29,30,31,33,34,35,36,37,38,39,40,41,42,43,44,45,46,48,49,55,56,57,68,70,72,74,75,77,80,81,83,94,104,106,107,108,109,110,111,114,117,119,124,128,130,131,134
Object.keys(structuredText): 0,1,2,3,4,5,6,7

So structuredText array really doesn't contain values from lineStats.
What did I miss?

@gotwarlost
Copy link
Owner

Thanks for the details. I think I know what is happening. Basically structured text contains the source code of the instrumented file and not the original source code. It needs the original source code.

The fix is to not instrument files in place. Structure your grunt task so that the file is instrumented from the original path and written to the tmp/ directory. That way the instrumented file in the tmp/ directory correctly refers to the original source code. As it stands now, it is referring to the same file which now contains the instrumented code.

@evil-shrike
Copy link
Author

@gotwarlost Thanks a lot. I've done as you described and everything works fine. Cool.

Is it possible to flatten files in html report?
I'd like to have a flatten list of files sorted by coverage percentage.

@gotwarlost
Copy link
Owner

No, not right now. The HTML report was designed to be 100% compatible with the genhtml program in the lcov package.

That said people have asked for different things:

  1. Truly hierarchical reports right now if you have lib/foo and lib/bar directories they appear at the top level as 2 entries rather than a lib/ entry with subdirectories under it.
  2. Your ask of a flattened list of all files so that coverage can be inspected for all of them together and sorted

These are good requirements and will need changes to the html report to support additional flags. I'll see what I can do once I get some time to work on this.

@evil-shrike
Copy link
Author

Thanks. I'm looking forward for the lib progress, it's awesome!

btw: I published my grunt taks in grunt-croc-qunit plugin (I know it's a yet another grunt plugin for Istanbul/qunit/phantomjs but anyway)

@jnikles
Copy link

jnikles commented Oct 29, 2014

I also had that error. However, I was using the hbsfy transform for browserify at that time, ignoring the templates folder fixed that issue as well.

@SarahFowler73
Copy link

SarahFowler73 commented May 2, 2016

Using mochify-istanbul, I found that anything that I was using transform for would mess up the source mapping. Adding exclude['**/*.html', '**/*.css', and '**.*.json'] completely cleared up the problem for me.

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

4 participants