实际上,我正在使用qunit配置grunt,以便使用jenkins运行单元测试(遵循本教程:http://shashikantjagtap.net/javascript-continuous-integration-jenkins-qunit-grunt/),但实际上我被此错误所阻止:
ReferenceError: gruntConfig未定义警告:未找到任务"qunit_junit“。继续使用武力。
由于警告而中止。
我的devDependencies:
"devDependencies": {
"grunt": "^1.0.0",
"grunt-cli": "0.1.6",
"grunt-contrib-clean": "~0.4.0",
"grunt-contrib-connect": "~0.6.0",
"grunt-contrib-csslint": "*",
"grunt-contrib-jshint": "~0.7.0",
"grunt-contrib-qunit": "~0.3.0",
"grunt-parallel-behat": "*",
"grunt-qunit-cov": "~0.3.2",
"grunt-qunit-istanbul": "*",
"grunt-qunit-junit": "^0.1.1",
"grunt-cli": "0.1.6",
"gulp": "github:gulpjs/gulp#4.0",
"gulp-apidoc": "^0.2.3",
"gulp-documentation": "^2.2.0",
"gulp-eslint": "^2.0.0",
"gulp-istanbul": "^0.10.3",
"gulp-jscs": "^4.0.0",
"gulp-mocha": "^2.2.0",
"gulp-nodemon": "^2.0.6",
"istanbul": "^0.4.4",
"mocha": "^3.0.2",
"require-dir": "^0.3.0",
"should": "^8.3.0",
"supertest": "^1.2.0"
}我的Gruntfile.js:
module.exports = function (grunt) {
grunt.registerTask('default', ['qunit_junit', 'qunit']);
grunt.loadNpmTasks('grunt-contrib-qunit');
grunt.loadNpmTasks('grunt-qunit-istanbul');
gruntConfig.qunit = {
src: ['static/test/index.html'],
options: {
coverage: {
src: ['static/js/**/*.js'],
instrumentedFiles: 'temp/',
htmlReport: 'report/coverage',
coberturaReport: 'report/',
linesThresholdPct: 20
}
}
};
grunt.loadNpmTasks('grunt-qunit-junit');
gruntConfig.qunit_junit = {
options: {
dest: 'report/'
}
};
}有人遇到了这个错误,或者对如何修复它有想法?
发布于 2016-08-30 15:37:24
正如ReferenceError中所述:您还没有定义gruntConfig对象。添加var gruntConfig = {};来定义对象。
module.exports = function (grunt) {
grunt.registerTask('default', ['qunit_junit', 'qunit']);
grunt.loadNpmTasks('grunt-contrib-qunit');
grunt.loadNpmTasks('grunt-qunit-istanbul');
//Add the below line to defined the object.
var gruntConfig = {};
gruntConfig.qunit = { ... }
//code ...
}发布于 2016-08-30 15:36:23
查看示例Gruntfile:
module.exports = function(grunt) {
grunt.initConfig({
jshint: {
files: ['Gruntfile.js', 'src/**/*.js', 'test/**/*.js'],
options: {
globals: {
jQuery: true
}
}
},
watch: {
files: ['<%= jshint.files %>'],
tasks: ['jshint']
}
});
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.registerTask('default', ['jshint']);
};https://stackoverflow.com/questions/39231659
复制相似问题