How to ignore files when using karma-coverage-istanbul-reporter to count test coverage

recently, when I learned to use Karma but counted the test coverage, I found that the coverage was very low. Looking at the results, I found that because he also counted a tool class I introduced (such as the following figure), how to set up to ignore the files in the lib folder when doing statistics

clipboard.png

Karma is configured as follows:

  https://github.com/mattlewis9.

Jul.31,2021

see if this is the answer you want. https://cloud.tencent.com/dev.


found the problem, because I thought that the istanbul plug-in effect of webpack loader and babel was different, so the istanbul plug-in was set in webpack loader and babel at the same time, so the exclude configured in istanbul-instrumenter-loader did not take effect. Because babel has counted it once before him, and if one of them is removed, it will be ok. However, the statistics of webpack's loader and babel plug-ins seem to be different, so let's compare the gap later.


if you use @ vue/cli3, it already has one for you, just connect to babel-plugin-istanbul . ides/-sharp%E7%94%A8-karma-%E6%B5%8B%E8%AF%95%E5%8D%95%E6%96%87%E4%BB%B6%E7%BB%84%E4%BB%B6" rel=" nofollow noreferrer "> refer to the whole operation on the official website

this is actually configured by babel in cross-env. back to your question, if you are based on a configuration above @ vue/cli3, you only need to modify the configuration of the babelrc or babel.config.js file:

usually looks like this:

  'env': {
    'test': {
      'plugins': ['istanbul']
    }
  }

replace it with:

  'env': {
    'test': {
      'plugins': [
        [
          'istanbul',
          { 'exclude': [ 'tests/**' ] }
        ]
      ]
    }
  }

is actually matching the exclude option.

PS:

the advantage of this change is that it actually modifies the configuration of npm run script's cross-env, rather than modifying webpack to change the configuration of the entire project.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b30e0c-2bd31.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b30e0c-2bd31.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?