2017-05-05 7 views
0

나는 커버 마 리포트를 얻기 위해 카르마를 사용하여 JS 유닛 테스트 케이스와 이스탄불을 작성하고 있습니다. 내 karma.conf.js 파일은 다음과 같습니다 - I 형 'HTML'과 'lcov'를 사용하려면 여기 coverageReporter 내부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', 디렉토리 : '범위 /' }

가 그럼 난 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)에서 두 개의 브라우저에 대해 언급 했으므로 일반적으로 각 브라우저마다 보고서가 별도로 생성되지만 config를 초과하면 브라우저 구성이 무시됩니다. 이것에 대한 어떤 생각 ??? - –

0

시도의 예 :

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

Ohh has it .. 그래서 항상 각각의 리포터 유형에 중괄호 안에 유형과 dir을 조합하여 추가해야합니다. 그리고 만약 우리가 어떤 dir도 언급하지 않으면 기본적으로 그것은 'coverage'디렉토리를 생성하고 그 안에 모든 것을 채우는 한가지 더 주목했습니다. 고마워, @ Vlad !!! –

+0

@ArvindMaurya 당신은 오신 것을 환영합니다 :) –