karma-coverage icon indicating copy to clipboard operation
karma-coverage copied to clipboard

Code coverage: how to cover code in <script> tag in html files?

Open jehon opened this issue 8 years ago • 3 comments

Hello,

I am working with lots of html files, each of them containing

I am testing these, and they are working correctly.

But, the code coverage is reporting nothing about theses files. And I would like them to do so.

Html files are about (they are polymerjs component):

<dom-module name="epc-catched-network-request">
  <script>
     .. code to be tested against code-coverage ..
  </script>
</dom-module>

In my karma.conf.js, I have this code:

   ...
    preprocessors: {
      'framework/*.js': [ 'coverage' ],
      'framework/*.html': [ 'coverage' ],
      'framework/!(bower_components)/**/*.js': [ 'coverage' ],
      'framework/!(bower_components)/**/*.html': [ 'coverage' ],
    },
   ...

Any clue on how to have some code coverage report taking code in tags?

jehon avatar Jan 16 '17 13:01 jehon

+1

jscharett avatar Jan 16 '17 17:01 jscharett

I hope you guys realize that coverage capability is not part of Karma. Whatever coverage you get is handled by a completely separate library - Istanbul (NYC).

stsvilik avatar Jan 16 '17 19:01 stsvilik

Some news of upstream work...

Istanbul does not include html in code coverage upto now. A bug is open here: https://github.com/gotwarlost/istanbul/issues/432

In the comments, we can see that there is a cool package targetted to that goal here: https://github.com/apowers313/html-script-hook

Multiple directions are possible from there:

  • Istanbul includes the package in its core functionnalities
  • Karma includes the package in its runtime
  • We publish a plugin to include the functionnalities of html-script-hook into karma

AFAIK, I think the third option (the plugin) would be the fastest way to include that in karma. But does anyone know how to make that?

jehon avatar Mar 14 '17 09:03 jehon