5

I am currently using Karma as my test runner with Webpack. I've noticed that simple test files which contain no tests give me 92.86% statement coverage, 50% branch coverage, 100% function coverage, and 92.86% line coverage.

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

});

When I check where I'm missing coverage I'm seeing this code (line 10), which is injected into my module by Webpack, as not being covered by tests:

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

I can't test for this because Webpack is injecting this code into the module. So how do I stop this type of information from being included in the coverage report?

The entire rendered file that the coverage report is giving me is the following:

/******/ (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 () {});

/***/ }
/******/ ]);

I don't want things like jQuery and Webpack items included as part of the code coverage report. How can I exclude things like the above code as being excluded from my tests? Because a test file with no tests and no imports/requires should be 100% coverage.

Brandon Parker
  • 762
  • 7
  • 18

0 Answers0