Karma, coverage report combined with webpack

拜拜、爱过 提交于 2019-12-11 06:39:29

问题


I have karma set up along with the coverage tool which is working - but as I'm also using webpack, the coverage report is using the bundled code that webpack has created.

For example: I have a Typescript file that includes an external library, so in order for that file to run it needs webpack. Webpack then includes that file into the compiled JS. This means that when I get the coverage report its % is low as I'm not testing the external file which has now been included.

preprocessors: {
            './src/**/*.ts': ['webpack', 'coverage']
        },

If I either remove the webpack part or place the array the other way around ( ['coverage', 'webpack']) it fails.

So, I'm not sure if what I'm after is possible as without webpack and compiled TS -> JS file will fail the tests. Its a bit like I want the reporting done in two steps.

  1. Run the test against the bundled code and report back.
  2. Check the tests that were run and compare against the non bundled files to get an accurate coverage report.

If it makes a difference to any answer, I'm also using Jasmine as a framework.


回答1:


You can try to use https://github.com/deepsweet/istanbul-instrumenter-loader to resolve your problem, a webpack loader to generate coverage report from the non-bundled source js file.

But the plugin doesn't support es6, you can refer to the issue#33 to figure out appropriate solutions.




回答2:


Took a while - but I found a good example that worked with what I wanted and how I wanted it. https://github.com/AngularClass/angular2-webpack-starter This does Typescript, Karma, Coverage & Webpack.

Also - https://angularclass.github.io/angular2-webpack-starter/



来源:https://stackoverflow.com/questions/39570980/karma-coverage-report-combined-with-webpack

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!