2

私はkarmaカバレッジで自分のタイプコピーソースファイルのカバレッジレポートを生成したいと思います。私の単体テストはjavascriptで書かれており、私はJasmine Testフレームワークを使用しています。Karma - typescriptカバレッジのソースマップを指す方法

マイフォルダ構造は次のようになります。

node_modules/ 
app/ 
    app.js 
    app.js.map 
    app.ts 
    components/ 
    controllers/ 
     SampleController.ts 
    directives/ 
    filters/ 
    services/ 

unittests/ 
    karma.conf.js 
    components/ 
    controllers/ 
     SampleControllerTest.js 
    directives/ 
    filters/ 
    services/ 

マイkarma.conf.js

module.exports = function(config) { 
    config.set({ 
    frameworks: ['jasmine'], 
    plugins: [ 
      'karma-jasmine', 
      'karma-ng-html2js-preprocessor', 
      'karma-coverage', 
      'karma-phantomjs-launcher', 
      'karma-sourcemap-loader' 

     ], 
    preprocessors: { 
     '../app/directives/controls/**/*Template.html' : [ 'ng-html2js' ], 

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

    }, 
    reporters: ['progress', 'coverage'], 

    // web server port 
    port: 9876, 

    coverageReporter: { 
      type : 'html', 
      dir : 'coverage/' 
     }, 
    // and some other stuff 
    }); 
}; 

現在、私のカバレッジレポートは十分な指標を提供するが、単一typescriptですファイルが、アプリとは関係ありません。 js。

私は、プリプロセッサの設定で何かを混乱させるか、ソースマップを指定する必要があると思います。

Annyのヒント?

答えて

6

karma-istanbul-remapを使用すると、私のためのトリックができます。

karma.conf.js:

module.exports = function(config) { 
    config.set({ 
    frameworks: ['jasmine'], 
    plugins: [ 
      'karma-jasmine', 
      'karma-ng-html2js-preprocessor', 
      'karma-coverage', 
      'karma-phantomjs-launcher', 
      'karma-remap-istanbul' 

     ], 
    preprocessors: { 
     '../app/directives/controls/**/*Template.html' : [ 'ng-html2js' ], 

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

    }, 
    reporters: ['progress', 'coverage', 'karma-remap-istanbul'], 

    // web server port 
    port: 9876, 

    coverageReporter: { 
     type : 'json', 
     subdir : '.', 
     dir : 'coverage/', 
     file : 'coverage.json' 
    }, 
    remapIstanbulReporter: { 
      src: 'coverage/coverage.json', 
      reports: { 
       lcovonly: 'coverage/lcov.info', 
       html: 'coverage/html/report' 
      }, 
      timeoutNotCreated: 5000, // default value 
      timeoutNoMoreFiles: 1000 // default value 
    }, 
    // and some other stuff 
    }); 
}; 
+0

それはソースを公開したり、カバレッジレポートでのみコンパイルされたファイルを表示することができますか? – finico

関連する問題