【发布时间】:2016-12-21 13:21:48
【问题描述】:
我正在使用 karma-coverage + browserify + angular。我从覆盖中得到的结果是 100% 的被测文件都被覆盖了,这是不正确的。知道如何完成这项工作吗?
这是我的文件 karma.conf.js :
// Karma configuration
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: ['browserify', 'jasmine'],
// list of files / patterns to load in the browser
files: [
'karma.spec.js',
'node_modules/es6-shim/es6-shim.js',
'src/**/*.js',
'unitest/**/*.js',
'node_modules/karma-read-json/karma-read-json.js',
{ pattern: 'unitest/mocks/*.json', included: false }
],
// 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: {
'karma.spec.js': ['browserify'],
'src/**/*.js': ['browserify']
},
browserify: {
debug: true,
transform: ['babelify']
},
// test results reporter to use
// possible values: 'dots', 'progress'
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
// https://www.npmjs.com/package/karma-notify-reporter
// enable coverage module
reporters: ['progress', 'coverage'],
// generate coverage report in htm format
coverageReporter: {
type : 'json',
dir : 'report/',
subdir: './report',
file: 'coverage-final.json'
},
// 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
// Start these browsers, currently available:
// - Chrome
// - ChromeCanary
// - Firefox
// - Opera
// - Safari (only Mac)
// - PhantomJS
// - IE (only Windows)
browsers: ['Chrome', 'PhantomJS'],
// If browser does not capture in given timeout [ms], kill it
'captureTimeout': 60000,
// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
singleRun: true,
// Concurrency level
// how many browser should be started simultaneous
concurrency: Infinity
})
}
这是我的 package.json :
{
"name": "project-name",
"version": "1.0.0",
"description": "",
"main": "index.js",
"author": "name",
"devDependencies": {
"angular-mocks": "^1.5.0",
"babel": "^6.5.2",
"babel-preset-es2015": "^6.9.0",
"babelify": "^7.2.0",
"browserify": "^13.0.1",
"envify": "^3.4.0",
"glob": "^7.0.0",
"concurrently": "^2.0.0",
"lite-server": "^2.1.0",
"typescript": "^1.8.7",
"jasmine-core": "2.4.1",
"jasmine": "^2.4.1",
"jspm": "^0.16.29",
"karma": "^0.13.21",
"karma-babel-preprocessor": "^6.0.1",
"karma-browserify": "^5.0.1",
"karma-coverage": "^0.5.5",
"karma-chrome-launcher": "^0.2.2",
"karma-jasmine": "^0.3.7",
"karma-notify-reporter": "^0.1.1",
"karma-read-json": "^1.1.0",
"karma-sourcemap-loader": "^0.3.7",
"remap-istanbul": "^0.5.1"
},
"scripts": {
"remap-istanbul": "remap-istanbul -i ./report/coverage/coverage-final.json -o ./report/coverage/html-report -t html",
"test": "karma start && npm run remap-istanbul"
},
"dependencies": {
"angular": "^v1.5.0",
"angular-animate": "^1.5.7",
"angular-route": "^v1.5.0-rc.2",
"angular-translate": "^2.9.0",
"angular-ui-bootstrap": "^1.3.3",
"es6-promise": "^3.0.2",
"es6-shim": "^0.33.3",
"lodash": "^4.14.0",
"watchify": "^3.7.0"
},
"browserify": {
"transform": [
[
"babelify",
{
"presets": [
"es2015"
]
}
]
]
}
}
【问题讨论】:
-
感谢链接,但我使用了 babelify + browserify + angular,我不知道我可以在 karma.conf 文件中添加什么配置,因为它给了我 100% 的结果(覆盖率) .
-
您可能需要关注this question - 从您的标题来看,这似乎也是您所要求的。
-
但我使用了 babelify,我搜索了可以添加到 karam.conf 的配置以进行 browserify。
-
我喜欢它,browserify: { debug: true, transform: [ ['babelify',{ presets: ['es2015'] }] ] },但问题总是显示 100% ?? ?
标签: angularjs karma-runner code-coverage browserify