我尝试使用 grunt-template-jasmine-istanbul 从 grunt 生成覆盖率报告。规范已正确执行,但未生成覆盖率报告。
下面是我在配置文件中的代码:
var name = 'SuperAccounts';
//*** Configure grunt
console.log(jasmine);
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
jshint: jshint,
durandal: durandal,
jasmine: {
coverage : {
src: [
'../../../Test.UnitTest.JS/UnitTests/' + name + '/**/*.js'
],
options: {
template: require('grunt-template-jasmine-istanbul'),
specs: [
//'../Test.UnitTest.JS/UnitTests/' + name + '/common/*.js',
//'../Test.UnitTest.JS/UnitTests/' + name + '/testdata',
'../Test.UnitTest.JS/UnitTests/' + name + '/**/*.js'
],
helpers: [
'Assets/scripts/ato/helperscript.js'
//'Legacy/Shared/common/constants.js'
],
vendor: jasmine.SuperAccounts,
templateOptions: {
//files: 'src/assets/js/app/**/*.js',
coverage: 'bin/coverage/coverage.json',
report: 'bin/coverage',
thresholds: {
lines: 75,
statements: 75,
branches: 75,
functions: 90
},
replace: false,
template: require('grunt-template-jasmine-requirejs'),
templateOptions: {
requireConfig: {
baseUrl: 'SinglePageApplications/' + name,
//waitSeconds: 30,
paths: mixIn({
'knockout-editables': '../../Assets/scripts/vendor/ko.editables-0.9.0',
'knockout-validation': '../../Assets/scripts/vendor/knockout.validation-1.0.2',
'bignumber': '../../Assets/scripts/vendor/bignumber-1.4.1',
'testutils': '../../../Test.UnitTest.JS/Utils',
'shared': '../../Legacy/Shared',
'testdata': '../../../Test.UnitTest.JS/UnitTests/' + name + '/testdata'
}, addConfigurationPaths(config.SuperAccounts))
}
},
helpers: [
'Assets/scripts/ato/helperscript.js'
//'Legacy/Shared/common/constants.js'
],
specs: [
//'../Test.UnitTest.JS/UnitTests/' + name + '/common/*.js',
//'../Test.UnitTest.JS/UnitTests/' + name + '/testdata',
'../Test.UnitTest.JS/UnitTests/' + name + '/**/*.js'
],
//junit: {
// path: 'build/junit/' + name + '/'
//},
timeout: 100000,
vendor: jasmine.SuperAccounts
}
}
,
//specs : 'src/test/js/unit-headless.html',
phantomjs: {
'ignore-ssl-errors': true
},
}
},
uglify: uglify,
cssmin: cssmin,
autoprefixer: {
options: {
diff: true,
map: true,
browsers: ['last 2 versions', 'ie 8', 'ie 9']
},
multiple_files: {
expand: true,
flatten: true,
src: 'ui/styles/ato/**/*.css',
dest: 'ui/styles/ato/autoprefix'
},
},
compress: {
main: {
options: {
archive: staticsZip,
level: 9
},
files: [
{ src: ['ui/**'], dest: '/', filter: 'isFile' }
]
}
}
});
//*** Loading plugins
grunt.loadNpmTasks('grunt-autoprefixer');
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-compress');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-cssmin');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-durandal');
grunt.loadNpmTasks('grunt-contrib-jasmine');
最佳答案
我意识到问题出在没有正确引用 Src 文件。像下面这样更改配置解决了问题:
jasmine: {
coverage : {
src: [
'SinglePageApplications/' + name + '/**/*.js'
],
options: {
template: require('grunt-template-jasmine-istanbul'),
specs: [
//'../Test.UnitTest.JS/UnitTests/' + name + '/common/*.js',
//'../Test.UnitTest.JS/UnitTests/' + name + '/testdata',
'../Test.UnitTest.JS/UnitTests/' + name + '/**/*.js'
],
helpers: [
'Assets/scripts/ato/helperscript.js'
//'Legacy/Shared/common/constants.js'
],
vendor: jasmine.SuperAccounts,
templateOptions: {
//files: 'src/assets/js/app/**/*.js',
coverage: 'bin/coverage/coverage.json',
report: 'bin/coverage',
thresholds: {
lines: 75,
statements: 75,
branches: 75,
functions: 90
},
replace: false,
template: require('grunt-template-jasmine-requirejs'),
templateOptions: {
requireConfig: {
baseUrl: 'SinglePageApplications/' + name,
//waitSeconds: 30,
paths: mixIn({
'knockout-editables': '../../Assets/scripts/vendor/ko.editables-0.9.0',
'knockout-validation': '../../Assets/scripts/vendor/knockout.validation-1.0.2',
'bignumber': '../../Assets/scripts/vendor/bignumber-1.4.1',
'testutils': '../../../Test.UnitTest.JS/Utils',
'shared': '../../Legacy/Shared',
'testdata': '../../../Test.UnitTest.JS/UnitTests/' + name + '/testdata'
}, addConfigurationPaths(config.SuperAccounts))
}
},
helpers: [
'Assets/scripts/ato/helperscript.js'
//'Legacy/Shared/common/constants.js'
],
specs: [
//'../Test.UnitTest.JS/UnitTests/' + name + '/common/*.js',
//'../Test.UnitTest.JS/UnitTests/' + name + '/testdata',
'../Test.UnitTest.JS/UnitTests/' + name + '/**/*.js'
],
//junit: {
// path: 'build/junit/' + name + '/'
//},
timeout: 100000,
vendor: jasmine.SuperAccounts
}
}
,
//specs : 'src/test/js/unit-headless.html',
phantomjs: {
'ignore-ssl-errors': true
},
}
}
关于javascript - Coverage.json 不是用 Jasmine RequireJS 和 Istanbul 生成的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36053992/