現在、Webpack のテスト ランナーとして Karma を使用しています。テストを含まない単純なテスト ファイルでは、92.86% のステートメント カバレッジ、50% の分岐カバレッジ、100% の関数カバレッジ、92.86% の行カバレッジが得られることに気付きました。
describe('tests.js', function () {
});
カバレッジが不足している場所を確認すると、テストでカバーされていないため、Webpack によってモジュールに挿入されたこのコード (10 行目) が表示されます。
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% のカバレッジである必要があるためです。