繁体   English   中英

发出严重的“参考错误”和“找不到任务”

[英]Grunt “reference error” and “task not found”

我实际上是使用qunit配置grunt以使用jenkins运行单元测试(在本教程之后: http ://shashikantjagtap.net/javascript-continuous-integration-jenkins-qunit-grunt/),但实际上我被此错误阻止:

ReferenceError:未定义gruntConfig警告:找不到任务“ qunit_junit”。 使用--force继续。

由于警告而中止。

我的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/'
    }
    };
}

任何人都遇到此错误或对如何解决有想法?

看一下示例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']);

};
  1. 配置任务
  2. 加载任务
  3. 注册任务

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 ...
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM