2016-07-29 7 views
1

常に100%カバレッジを取得します。Aurelia-cli、babel-plugin-istanbul、Karmaコードカバレッジレポートは常に100%を返します

karma.conf.jsファイルは、aurelia-cliが生成するものと同じです。

私はbabel-plugin-istanbulを使用したいと思います。コードカバレッジレポートです。

"babel-plugin-istanbul": "^1.0.3", 
"jasmine-core": "^2.4.1", 
"karma": "^0.13.22", 
"karma-chrome-launcher": "^1.0.1", 
"karma-jasmine": "^1.0.2", 
"karma-babel-preprocessor": "^6.0.1", 
"karma-coverage": "^1.1.0", 
"karma-jasmine-html-reporter": "^0.2.0", 
"karma-sinon": "^1.0.5", 
"sinon": "^1.17.4" 

karma.conf.js(ミズクラゲ-CLIによって生成されるように、それは同じである)

"use strict"; 
const path = require('path'); 
const project = require('./aurelia_project/aurelia.json'); 

let testSrc = [ 
    { pattern: project.unitTestRunner.source, included: false }, 
    'test/aurelia-karma.js' 
]; 

let output = project.platform.output; 
let appSrc = project.build.bundles.map(x => path.join(output, x.name)); 
let entryIndex = appSrc.indexOf(path.join(output, project.build.loader.configTarget)); 
let entryBundle = appSrc.splice(entryIndex, 1)[0]; 
let files = [entryBundle].concat(testSrc).concat(appSrc); 

module.exports = function(config) { 
    config.set({ 
    basePath: '', 
    frameworks: [project.testFramework.id, 'sinon'], 
    files: files, 
    exclude: [], 
    preprocessors: { 
     [project.unitTestRunner.source]: [project.transpiler.id] 
    }, 
    'babelPreprocessor': { options: project.transpiler.options }, 
    reporters: ['progress', 'kjhtml'], 
    port: 9876, 
    colors: true, 
    logLevel: config.LOG_INFO, 
    autoWatch: true, 
    browsers: ['Chrome'], 
    singleRun: false 
    }); 
}; 

cover.jsファイル

使用

package.json ~~>ノードモジュールあなたが必要とする

export function cover(done) { 
    new Karma({ 
    configFile: __dirname + '/../../karma.conf.js', 
    singleRun: true, 
    reporters: ['coverage'], 
    preprocessors: { 
     'test/unit/**/*.js': ['babel'], 
     'src/**/*.js': ['babel'] 
    }, 
    coverageReporter: { 
     includeAllSources: true, 
     reporters: [ 
     {type: 'html', dir: 'coverage'}, 
     {type: 'text'} 
     ] 
    } 
    }, done).start(); 
} 

おかげ

答えて

1

プリプロセッサセクションにはテストは含まれません。したがって、最初の行を削除し、ソースコードのみを残しておきます。カバレッジは、テスト方法ではなくソースコードに関するものです。

preprocessors: { 

     'src/**/*.js': ['babel'] 
    }, 
1

私はあなたがカバーするための少なくともプリプロセッサ不足していることを参照してください。

preprocessors: { 
    'test/unit/**/*.js': ['babel'], 
    'src/**/*.js': ['babel', 'coverage'] 
}, 

私も場所でそれと同様の問題を抱えていた、と述べました。

主な問題は、カルマのデフォルトのaurelia-cliセットアップでは、テストバンドルのソースとしてアプリケーションバンドルを使用することです。この方法ではispartaを使用して計測されません。

私は次のように作業構成を有している。これにより

import gulp from 'gulp'; 
import {Server as Karma} from 'karma'; 
import {CLIOptions} from 'aurelia-cli'; 

let appBundle = "scripts/app-bundle.js"; 


export function cover(done) { 
    new Karma({ 
    configFile: __dirname + '/../../karma.conf.js', 
    singleRun: !CLIOptions.hasFlag('watch'), 
    reporters: ['coverage'], 
    logLevel: 'debug', 
    preprocessors: { 
     [project.unitTestRunner.source]: [project.transpiler.id], 
     [appBundle]: ['coverage'] 
    }, 
    coverageReporter: { 
     includeAllSources: true, 
     instrumenters: { 
     isparta: require('isparta') 
     }, 
     instrumenter: { 
     [appBundle]: 'isparta' 
     }, 
     reporters: [ 
     { type: 'html', dir: '.reports/coverage' }, 
     { type: 'text' } 
     ] 
    } 
    }, done).start(); 
} 

export default cover; 

を所定の位置に、私はカバレッジテストを実行することができます。ああ、カバレッジレポートは単一のapp-bundle.jsファイルに基づいていますが、各ソースファイルの項目別レポートは表示されません。しかし、カバレッジの重要なギャップを見つけ出すのに十分です。これは主に私が使用するものです。

+0

私はAureliaでコードカバレッジを取得するために複数のアプローチを見てきましたが、これが私のために働いたのはこれだけです。ありがとうございました! –

関連する問題