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

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

Open
jehon opened this issue Jan 16, 2017 · 3 comments
Open

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

jehon opened this issue Jan 16, 2017 · 3 comments

Comments

@jehon
Copy link

jehon commented Jan 16, 2017

Hello,

I am working with lots of html files, each of them containing <script> tags.

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 <script>this</script> tags?

@jehon jehon changed the title Code coverage: what about <script> in html files? Code coverage: is code in <script> tag in html files covered? Jan 16, 2017
@jehon jehon changed the title Code coverage: is code in <script> tag in html files covered? Code coverage: how to cover code in <script> tag in html files? Jan 16, 2017
@jscharett
Copy link

+1

@stsvilik
Copy link

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).

@jehon
Copy link
Author

jehon commented Mar 14, 2017

Some news of upstream work...

Istanbul does not include html in code coverage upto now. A bug is open here: gotwarlost/istanbul#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?

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

3 participants