当使用karma和requirejs的coverage
记者时,我遇到了加载我的一个模块的问题。更具体地说,正在加载的模块正在抛出如下所示的相当神秘的错误消息:
经过一番挖掘后,我将问题分离到Karma / Istanbul生成的模块代码中的以下语句中:
如果我从覆盖率报告中删除App.Controller
模块,则所有模块都按预期工作。模块本身并没有什么特别之处,甚至返回一个空白对象,因为模块将导致错误被抛出并且测试失败。
我目前正在使用以下依赖项运行业力:
"karma-safari-launcher": "~> 0.1.1",
"karma-ievms": "~> 0.0.4",
"karma": "~> 0.12.16",
"karma-cli": "~> 0.0.4",
"karma-coverage": "~> 0.2.1",
"karma-requirejs": "~0.2.1",
"phantomjs": "~1.9.7-5",
"karma-phantomjs-launcher": "~0.1.4",
"karma-chrome-launcher": "~0.1.3",
"karma-firefox-launcher": "~0.1.3",
"karma-jasmine": "~> 0.1.0",
"karma-osx-reporter": "~> 0.1.0"
我的karma.conf看起来像这样:
(function () {
'use strict';
module.exports = function (config) {
config.set({
basePath: '',
frameworks: ['jasmine', 'requirejs'],
reporters: ['progress', 'coverage'],
browsers: ['Chrome'],
autoWatch: true,
logLevel: config.LOG_INFO,
colors: true,
captureTimeout: 60000,
singleRun: false,
runnerPort: 9100,
port: 9456,
hostname: 'localhost',
preprocessors: {
"src/Apps/Signup/Slim_Account/**/*.js": ['coverage'],
"src/Apps/Signup/Slim_Account/*.js": ['coverage']
},
coverageReporter: {
type: 'lcov',
dir: 'coverage/'
},
files: [
// Deps
{
pattern: 'libs/**/*.js',
included: false
}, {
pattern: 'bootstrap/**/*.js',
included: false
}, {
pattern: 'src/**/*.svg',
included: false
}, {
pattern: 'src/**/*.html',
included: false
}, {
pattern: 'test/**/*.html',
included: false
}, {
pattern: 'src/**/*.json',
included: false
}, {
pattern: 'test/**/*.json',
included: false
},
'test/libs/velesin-jasmine-jquery/lib/jasmine-jquery.js',
'test/helpers/lv-helpers.js',
'test/helpers/lv-matchers.js',
// src
{
pattern: 'src/**/*.js',
included: false
},
// Tests
{
pattern: 'test/src/unit/Apps/Signup/Slim_Account/**/*._SPEC.js',
included: false
},
'test/test-slim-account-signup-main.js'
],
exclude: [
'src/Apps/Signup/Slim_Account/App.Bootloader.js'
]
});
};
})();
现在试图解决这个问题几天,但无济于事。任何帮助或方向将不胜感激。