gotwarlost / istanbul

Yet another JS code coverage tool that computes statement, line, function and branch coverage with module loader hooks to transparently add coverage when running tests. Supports all JS coverage use cases including unit tests, server side functional tests and browser tests. Built for scale.
Other
8.7k stars 788 forks source link

Coverage of JS embedded in HTML? #432

Open apowers313 opened 9 years ago

apowers313 commented 9 years ago

New web component technologies, such as Polymer, advocate for embedding the majority of JavaScript inside the web components that they are attached to.

Is there a preprocessor or any other way to generate code coverage information for JavaScript that is embedded in HTML files?

See also: thedeeno/web-component-tester-istanbul#12

apowers313 commented 9 years ago

If coverage for JavaScript in HTML doesn't already exist, maybe one way of adding it would be to create a <tested-script> web component that could be used in place of <script> tags, where<tested-script> would instrument the code inside that tag.

I'm not sure if Istanbul can instrument code in the browser, or if the only instrumenting codes exist on the command line.

Any thoughts?

apowers313 commented 9 years ago

I just created my own package that provides the facilities for instrumenting the JavaScript in HTML: html-script-hook

For examples of how to use it with Istanbul, see the README or check out this example.

Hopefully it will be useful to others that find themselves in the same position.

rafalradomski commented 8 years ago

+1

jehon commented 7 years ago

+1