我正在尝试获取测试的覆盖率报告,但所有文件的覆盖率输出始终在一行上,显示带有文件路径的require.例如…
然而,测试运行良好.这是一个反应项目,因此我必须在文件和预处理器中包含一些额外的路径以使测试运行.
我不确定我的业力配置是否有问题?这就是我的配置目前的样子……
/* global module */ module.exports = function (config) { 'use strict'; config.set({ autoWatch: true,singleRun: true,frameworks: ['browserify','jasmine'],files: [ 'node_modules/karma-babel-preprocessor/node_modules/babel-core/browser-polyfill.js','node_modules/react/react.js','src/**/*.jsx','src/**/!(*spec).js' ],browsers: ['PhantomJS'],preprocessors: { 'node_modules/react/react.js': ['browserify','sourcemap'],'src/**/*.jsx': ['browserify','sourcemap','coverage'],'src/**/!(*spec).js': ['browserify',},browserify: { debug: true,transform: [ 'babelify' ] },reporters: ['progress',coverageReporter: { instrumenters: {isparta: require('isparta')},instrumenter: { 'src/**/*.js': 'isparta','src/**/*.jsx': 'isparta' },reporters: [ { type: 'text-summary',subdir: normalizationBrowserName },{ type: 'lcov',{ type: 'html',dir: 'coverage/',subdir: normalizationBrowserName } ] } }); function normalizationBrowserName(browser) { return browser.toLowerCase().split(/[ /-]/)[0]; } };
更新:
我也使用了一个commonjs变换,并且能够让事情变得更好,但测试不会运行,覆盖范围就是变换后的代码.
请确保包含该覆盖的所有源代码.例如,我有以下karma.conf.js :(检查预处理器部分)
原文链接:https://www.f2er.com/react/301007.html// Karma configuration // Generated on Mon Sep 07 2015 23:22:13 GMT-0400 (Eastern Daylight Time) module.exports = function(config) { var SourceCode = [ 'app/app.js','app/Modules/*.js',// Basic Path Files (Modules for Source,UnitTests to keep test files separate) 'app/Modules/**/_*.init.js',// Declarative functions needed for next line - Initialization Code 'app/Modules/**/*.js','app/UnitTests/**/*.mock.js',// Mock Declarations for Tests 'app/UnitTests/**/*.test.js' ]; var Libraries = [ 'app/bower_components/angular/angular.js','app/bower_components/angular-animate/angular-animate.js','app/bower_components/angular-aria/angular-aria.js','app/bower_components/angular-route/angular-route.js','app/bower_components/firebase/firebase.js',... // Testing 'app/bower_components/angular-mocks/angular-mocks.js','app/bower_components/angular-material/angular-material-mocks.js','app/bower_components/mockfirebase/browser/mockfirebase.js','node_modules/sinon/pkg/sinon.js',]; 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: ['mocha','chai'],// // list of files / patterns to load in the browser files: Libraries.concat(SourceCode),// 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/Modules/**/*.js': ['coverage'] // Ensure all files are in Code Coverage },// test results reporter to use // possible values: 'dots','progress' // available reporters: https://npmjs.org/browse/keyword/karma-reporter reporters: ['progress',coverageReporter: { type : 'html',dir : 'docs/coverage/' },logLevel: 'LOG_DEBUG',// 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: false,// start these browsers // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher browsers: ['PhantomJS'],// 'Chrome',// Continuous Integration mode // if true,Karma captures browsers,runs the tests and exits singleRun: true }) }