5

How to measure common coverage for Polymer components with all .js files in solution (for non-component tests QUnit is used)?

I tried karma-coverage, but it works only for .js files.

Julia Savinkova
  • 573
  • 8
  • 18

2 Answers2

2

For Polymer, you would normally use web-component-tester (WCT) to test your components, and the web-component-tester-istanbul plugin for code coverage. You'd configure wct.conf.json in the root of your project with something like this:

{
  "suites": [
    "test/components/my-view1/my-view1.html"
  ],
  "plugins": {
    "istanbul": {
      "dir": "./build/coverage",
      "reporters": [
        "text-summary",
        "lcov"
      ],
      "include": [
        "*.js",
        "*.html"
      ],
      "exclude": []
    }
  }
}

And then run wct, which outputs something like this:

enter image description here

Unfortunately, a recent upgrade in WCT has made the coverage plugin incompatible, such that the plugin never gets called, so coverage is always shown as 100% (0/0) (no lines covered, no lines seen).

tony19
  • 125,647
  • 18
  • 229
  • 307
  • Thanks, I know about wct and found this issue on GitHub https://github.com/thedeeno/web-component-tester-istanbul/issues/38, maybe I can use the previous version. But did you try to measure coverage with wct for all .js files in solution? (not only for Polymer components) – Julia Savinkova Jan 19 '17 at 19:35
  • 1
    Yep, that's the issue I linked to. :) I had no luck trying previous versions of WCT with `istanbul`. I'd be interested in hearing about your experience, especially if you get it working. Yeah, I tried to measure both `*.js` and `*.html`, as in script inside `html` files (see the config's `include` setting). – tony19 Jan 19 '17 at 23:53
  • For non-component tests I use QUnit but it's not supported in WCT, so the last option is splitting components to .js file and .html file like in answer below – Julia Savinkova Jan 31 '17 at 10:26
0

For Polymer components there is a solution to measure common coverage with karma-coverage: split to .js files and include it to components. Example is here

Julia Savinkova
  • 573
  • 8
  • 18