2017-05-05 78 views
0

我正在使用Karma编写JS单元测试用例和伊斯坦布尔以获取覆盖率报告。 我karma.conf.js文件如下 -我想在karma.conf.js中使用多个覆盖率报告类型

// karma.conf.js 
module.exports = function(config) { 
    config.set({ 
    files: [ 
     'test/**/*.js' 
    ], 

    // coverage reporter generates the coverage 
    reporters: ['progress', 'coverage'], 

    preprocessors: { 
     // source files, that you wanna generate coverage for 
     // do not include tests or libraries 
     // (these files will be instrumented by Istanbul) 
     'test/**/*.js': ['coverage'] 
    }, 

    // optionally, configure the reporter 
    coverageReporter: { 
     type : 'html', 
     dir : 'coverage/' 
    } 
    }); 
}; 

这里里面coverageReporter我想用型 'HTML' 和 'LCOV'。要做到这一点,我如下改变了它 -

coverageReporter:{ 类型: 'HTML', 'LCOV', DIR: '报道/' }

然后我执行karma start karma.conf.js但得到以下例外 - -

C:\abc\npm-1.4.9>karma start karma.conf.js 
05 05 2017 16:57:00.369:ERROR [config]: Invalid config file! 
    C:\abc\npm-1.4.9\karma.conf.js:45 
     type : 'html','lcov', 
         ^
SyntaxError: Unexpected token , 
    at createScript (vm.js:53:10) 
    at Object.runInThisContext (vm.js:95:10) 
    at Module._compile (module.js:543:28) 
    at Object.Module._extensions..js (module.js:580:10) 
    at Module.load (module.js:488:32) 
    at tryModuleLoad (module.js:447:12) 
    at Function.Module._load (module.js:439:3) 
    at Module.require (module.js:498:17) 
    at require (internal/module.js:20:19) 

任何帮助,非常感谢。

回答

0

你必须使用一种配置,这种结构为coverageReporter属性:

coverageReporter: { 
    // specify a common output directory 
    dir: 'coverage/', 
    reporters: [ 
    // reporters not supporting the `file` property 
    { type: 'html', subdir: '.' }, 
    { type: 'lcov', subdir: '.' }, 

    ] 
} 

这种因果报应覆盖的readme描述。

+0

这个工作,但是有一个副作用。我在karma.conf.js(Chrome和PhantomJs)中提到了两个浏览器,因此通常会分别为每个浏览器生成报告,但上面的配置会忽略浏览器配置。有关这个的任何想法? - –

0

试试下面例子:

coverageReporter: { 
    reporters: [ 
     {type: 'html', dir: 'html-coverage'}, 
     {type: 'lcov'} 
    ] 
} 
+0

哦,明白了..所以我总是需要在每个记者类型的花括号里加入类型和目录的组合。而且我还注意到一件事,如果我们没有提到任何dir,那么默认情况下它会创建'coverage'目录并在其中填充所有内容。谢谢,@Vlad !!! –

+0

@ArvindMaurya欢迎您:) –

相关问题