本文主要是介绍karma 自动化测试和覆盖率,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
karma.conf.js
module.exports = function (config) {config.set({// basePath: '',autoWatch: true,// available frameworks: https://npmjs.org/browse/keyword/karma-adapterframeworks: ['jasmine'],client: {captureConsole: false,jasmine: {random: false,},},// 更多设置可以查看 https://karma-runner.github.io/2.0/config/files.htmlfiles: [{ pattern: 'src/*.js', included: true, type: "module" },// 'test/*.js',{ pattern: 'test/*.js', included: true, type: "module" },],plugins: ['karma-coverage','karma-chrome-launcher','karma-jasmine','karma-longest-reporter','karma-spec-reporter'],browsers: ['Chrome'],port: 9876,captureTimeout: 120000,browserDisconnectTolerance: 3,browserDisconnectTimeout: 120000,browserNoActivityTimeout: 120000,autoWatch: false,colors: true,reporters: ["spec", "longest", 'coverage'],preprocessors: { 'src/*.js': ['coverage'] },exclude: ['./node_modules',],coverageReporter: {// 配置生成的代码覆盖率文件存放位置dir: './target',reporters: [// 生成 lcov.info 文件,该文件中包含了详细的每个文件,每行,每个函数的执行信息。{ type: 'lcov', subdir: '.' },// 在命令行输出简要覆盖率数据{ type: 'text-summary' }]},singleRun: true});
};
package.json
{"name": "coverage-jasmine-istanbul-karma","description": "Example of code coverage of Jasmine tests using Istanbul and Karma","main": "sqrt.js","version": "0.0.1","engines": {"node": ">=0.8.0"},"repository": {"type": "git","url": "http://github.com/ariya/coverage-jasmine-istanbul-karma.git"},"devDependencies": {"jasmine-core": "^5.0.1","karma": "^6.3.20","karma-chrome-launcher": "^3.2.0","karma-coverage": "^2.0.3","karma-jasmine": "^5.1.0","karma-longest-reporter": "^1.1.0","karma-spec-reporter": "^0.0.36"},"scripts": {"aa": "karma start karma.conf.js"}
}
这篇关于karma 自动化测试和覆盖率的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!