pugjs / pug

Pug – robust, elegant, feature rich template engine for Node.js
https://pugjs.org
21.68k stars 1.95k forks source link

Code coverage for templates #2188

Open rafis opened 8 years ago

rafis commented 8 years ago

istanbul is most popular code coverage tool for JavaScript. It cannot test coverage of views, but it is possible and I think not so much hard to implement code coverage for views. It will allow to check if some code branches or entire views (dead views) are not used in project. I have checked code generated by jade. For integration with istanbul this part will need to be changed (to make lines in .jade and .js matching) or additional code will need to be written if (options.instrumentForIstanbul) { ... }, then we save instrumented code in .jade -> .js files, then we load all instrumented js-views to jade's views cache, then run tests with generating coverage, then in lcov report replace .js -> .jade (cheat).

TimothyGu commented 8 years ago

Without doubt, this is very difficult. The nature of Jade/Pug demands two levels of code mapping: jade to js, and jade to html. So far we have mostly focused on the latter.

To achieve the former which is necessary for this ticket, pugjs/jade-code-gen#21 will surely help.