карма-покрытие включает node_modules

У меня есть конфигурация кармы, которая для моего модульного теста и code-cov. Мой каталог проекта выглядит так, как показано ниже

RootFOlder
-karma.config.js
-webpack.test.config.js
-src/
--test.ts
--components
---ButonComponent
----Buttoncomponent.spec.ts

И мой karma.config ниже

// Karma configuration

module.exports = function (config) {
  config.set({

    // base path that will be used to resolve all patterns (eg. files, exclude)
    basePath: '',


    // frameworks to use
    // available frameworks: https://npmjs.org/browse/keyword/karma-adapter
    frameworks: ['jasmine'],


    // list of files / patterns to load in the browser
    files: [
      'src/test.ts',
      'src/components/**/*.component.ts',
    ],

    // list of files / patterns to exclude
    exclude: [
      'node_modules',
      './src/tsconfig.spec.json'
    ],
    plugins: [
      require('karma-jasmine'),
      require("karma-coverage"),
      require('karma-chrome-launcher'),
      require('karma-jasmine-html-reporter'),
      require('karma-webpack'),
      require('karma-sourcemap-loader'),
      require('ts-loader')
    ],


    // preprocess matching files before serving them to the browser
    // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
    preprocessors: {
      'src/components/**/*.ts': ['coverage'],
      'src/components/**/*.component.ts': ['webpack', 'sourcemap'],
      'src/test.ts': ['webpack', 'sourcemap'],

    },

    webpack: require('./webpack.test.config'),

    coverageReporter: {
      reporters: [
        { type: 'text', subdir: 'text' },
        { type: 'html', subdir: 'report-html' },
      ]
    },

    ...
    ...
  });
}

И мой веб-пакет. module.exports = {devtool: 'inline-source-map', режим: 'development', цель: 'node', разрешение: {extensions: ['.ts', '.js']},

  module: {
    rules: [
      {
        test: /\.ts$/,
        loaders: ['ts-loader', 'angular-router-loader', 'angular2-template-loader']
      }
     ....
     ....

    ]
  },

  plugins: [
    new webpack.DefinePlugin({
      'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV || 'test')
    }),
    // Removes warnings regarding Critical dependency
    new webpack.ContextReplacementPlugin(
      /\@angular(\\|\/)core(\\|\/)f?esm5/, path.join(__dirname, './src')
    )
  ],
  node: {
    console: false,
    global: true,
    process: true,
    Buffer: false,
    setImmediate: false
  }
}

Проблема в том, что после того, как я запустил свой тест, мое покрытие охватывает связанные модули node_modules. Конечное покрытие файловых файлов в мегабайтах и ​​мое покрытие низкое. Пожалуйста, как мне исключить node_modules из моего покрытия? Любая помощь приветствуется.


person Nuru Salihu    schedule 03.09.2018    source источник
comment
привет .. ответ помог?   -  person Ray    schedule 07.09.2018


Ответы (1)


По умолчанию вам даже не нужно упоминать node_modules в пути exclude. Попробуйте удалить его и посмотрите, исправлено ли покрытие?

Если не,

попробуйте добавить это в preprocessors:

'!node_modules/**/*.*': ['coverage']
person Ray    schedule 04.09.2018