常に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();
}
おかげ
私はAureliaでコードカバレッジを取得するために複数のアプローチを見てきましたが、これが私のために働いたのはこれだけです。ありがとうございました! –