Karma代码覆盖率与Webpack不正确

时间:2016-06-03 19:47:35

标签: node.js webpack karma-coverage

我目前正在使用Karma作为我的Webpack测试运行器。我注意到,没有测试的简单测试文件给了我92.86%的声明覆盖率,50%的分支覆盖率,100%的功能覆盖率和92.86%的线覆盖率。

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

});

当我检查我丢失覆盖的地方时,我看到了这个代码(第10行),它被Webpack注入我的模块,因为没有被测试覆盖:

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

我无法测试,因为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项目包含在代码覆盖率报告中。如何将上述代码中的内容排除在我的测试之外?因为没有测试且没有导入/要求的测试文件应该是100%覆盖。

0 个答案:

没有答案