2017-03-03 183 views
3

我想从我的代码覆盖率输出忽略几个文件。在阅读文档coveragePathIgnorePatterns时,它看起来像我可以忽略文件夹。Jest覆盖忽略

我试图忽视虚拟助手从我的报道文件夹,但他们似乎总是包含:

玩笑配置:

{ 
    "browser": true, 
    "collectCoverageFrom": ["<rootDir>/src/**/*.{js,jsx}", "!<rootDir>/__tests__/__dummy__/test.js"], 
    "coveragePathIgnorePatterns": ["<rootDir>/node_modules/", "<rootDir>/__tests__/__helpers__/", "<rootDir>/__tests__/__dummy__/"], 
    "roots": [ 
    "<rootDir>/__tests__/", 
    "<rootDir>/src/" 
    ], 
    "modulePaths": [ 
    "<rootDir>/src/" 
    ], 
    "modulePathIgnorePatterns": [ 
    "<rootDir>/lib/", 
    "<rootDir>/node_modules/", 
    "<rootDir>/__tests__/__helpers__/", 
    "<rootDir>/__tests__/__dummy__/" 
    ], 
    "setupTestFrameworkScriptFile": "@djforth/jest-matchers", 
    "testPathIgnorePatterns": [ 
    "<rootDir>/__tests__/__dummy__", 
    "<rootDir>/__tests__/__dummy__", 
    "<rootDir>/lib", 
    "<rootDir>/node_modules", 
    "<rootDir>/bower_components" 
    ], 
    "verbose": true 
} 

我得到如下报告:

-----------------------|----------|----------|----------|----------|----------------| 
File     | % Stmts | % Branch | % Funcs | % Lines |Uncovered Lines | 
-----------------------|----------|----------|----------|----------|----------------| 
All files    | 98.87 | 96.48 |  92.5 | 99.55 |    | 
__helpers__   | 84.21 |  100 | 54.55 | 90.91 |    | 
    test.js    | 84.21 |  100 | 54.55 | 90.91 |    6 | 
__tests__/__helpers__ |  100 |  100 |  100 |  100 |    | 
    create_spy_obj.js |  100 |  100 |  100 |  100 |    | 
src     |  100 |  80 |  87.5 |  100 |    | 
    index.js    |  100 |  80 |  87.5 |  100 |    | 
src/utils    |  100 | 97.73 |  100 |  100 |    | 
    compile_spies.js  |  100 | 81.82 |  100 |  100 |    | 
    create_callbacks.js |  100 |  100 |  100 |  100 |    | 
    create_spies.js  |  100 | 97.44 |  100 |  100 |    | 
    create_stubs.js  |  100 |  100 |  100 |  100 |    | 
    get_spy.js   |  100 |  100 |  100 |  100 |    | 
    merger.js   |  100 |  100 |  100 |  100 |    | 
    reset_spies.js  |  100 |  100 |  100 |  100 |    | 
    title_keys.js  |  100 |  100 |  100 |  100 |    | 
-----------------------|----------|----------|----------|----------|----------------| 

回答

0

我终于想出了什么是解决我的问题。

Jest在hod下使用伊斯坦布尔。当我设置项目时,我复制了我的.babelrc配置文件,忽略了我已经离开了旧的茉莉花配置。我已改变成笑话加入测试的约定,以测试 /**/*.test.js,但是在babelrc配置我:

"plugins": [ 
    [ 
     "istanbul", 
     { 
     "exclude": [ 
      "spec/**/*.spec.js" 
     ] 
     } 
    ], 
    "rewire" 
    ] 

所以一旦我已经删除了正确排除覆盖范围显示。它看起来像是你在babelrc中指定它覆盖了jest配置。

0

不知道为什么这不适合你,但我们以另一种方式做大约:

"collectCoverageFrom": ["src/**/*.js"],