Karma代码覆盖率与Webpack不正确

我目前正在使用Karma作为我的Webpacktesting运行者。 我注意到,没有testing的简单testing文件给我92.86%的报表覆盖率,50%的分支覆盖率,100%的function覆盖率和92.86%的线路覆盖率。

describe('tests.js', function () { }); 

当我检查我缺less覆盖范围时,我看到这个代码(第10行),这个代码被Webpack注入到我的模块中,因为没有被testing覆盖:

 if(installedModules[moduleId]) return installedModules[moduleId].exports; 

我不能testing这个,因为Webpack是注入这个代码到模块中。 那么如何阻止这类信息被纳入覆盖报告呢?

覆盖报告给我的整个呈现文件如下:

 /******/ (function(modules) { // webpackBootstrap /******/ // The module cache /******/ var installedModules = {}; /******/ // The require function /******/ function __webpack_require__(moduleId) { /******/ // Check if module is in cache /******/ Iif(installedModules[moduleId]) /******/ return installedModules[moduleId].exports; /******/ // Create a new module (and put it into the cache) /******/ var module = installedModules[moduleId] = { /******/ exports: {}, /******/ id: moduleId, /******/ loaded: false /******/ }; /******/ // Execute the module function /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); /******/ // Flag the module as loaded /******/ module.loaded = true; /******/ // Return the exports of the module /******/ return module.exports; /******/ } /******/ // expose the modules object (__webpack_modules__) /******/ __webpack_require__.m = modules; /******/ // expose the module cache /******/ __webpack_require__.c = installedModules; /******/ // __webpack_public_path__ /******/ __webpack_require__.p = "/_karma_webpack_//"; /******/ // Load entry module and return exports /******/ return __webpack_require__(0); /******/ }) /************************************************************************/ /******/ ([ /* 0 */ /***/ function(module, exports) { 'use strict'; describe('tests.js', function () {}); /***/ } /******/ ]); 

我不希望像jQuery和Webpack这样的东西包含在代码覆盖率报告中。 我如何排除上述代码之类的东西被排除在我的testing之外? 因为没有testing和没有import/要求的testing文件应该是100%的覆盖率。

Interesting Posts