我使用本指南http://karma-runner.github.io/0.8/config/coverage.html来设置我的 Karma-coverage 插件。此外,它通过 package.json 文件在本地安装,如下所示:
{
"name": "myApp",
"version": "0.1.0",
"devDependencies": {
"karma-jasmine": "latest",
"karma-coverage": "latest",
"karma-coffee-preprocessor": "latest",
"karma-chrome-launcher": "latest",
"coffee-script": "latest"
}
}
我的 Karma.conf 看起来像这样:
// Karma configuration
// Generated on Sun Dec 07 2014 15:51:07 GMT+0100 (CET)
module.exports = function(config) {
config.set({
// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: '',
// frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: ['jasmine'],
// list of files / patterns to load in the browser
files: [
'javascripts/vendor/jquery_211.js',
'javascripts/vendor/angular.js',
'javascripts/vendor/angular-route.js',
'javascripts/vendor/angular-mocks.js',
'../app/assets/javascripts/app.coffee',
'javascripts/*.js',
'test/controllers/*.js'
],
// list of files to exclude
exclude: [
],
// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
'../app/assets/javascripts/app.coffee' : ['coffee'],
'**/javascripts/*.js': 'coverage'
//'**/*.coffee': ['coffee']
},
// test results reporter to use
// possible values: 'dots', 'progress'
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
reporters: ['progress', 'coverage'],
// web server port
port: 9876,
// enable / disable colors in the output (reporters and logs)
colors: true,
// level of logging
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: config.LOG_INFO,
// enable / disable watching file and executing tests whenever any file changes
autoWatch: true,
// start these browsers
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
browsers: ['Chrome'],
// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
singleRun: false
});
};
现在,在运行业力时,我收到错误
WARN [reporter]: Can not load "coverage", it is not registered!
Perhaps you are missing some plugin?
INFO [karma]: Karma v0.12.28 server started at http://localhost:9876/
INFO [launcher]: Starting browser Chrome
WARN [preprocess]: Can not load "coverage", it is not registered!
Perhaps you are missing some plugin?
没关系,如果我在 karma.conf 文件的插件部分中包含 karma-coverage,问题仍然存在(因为插件是在本地加载的,所以无论如何我都不应该需要插件部分......)。我希望你们中的某个人有一个想法......谢谢!