首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >咕哝“引用错误”和“找不到任务”

咕哝“引用错误”和“找不到任务”
EN

Stack Overflow用户
提问于 2016-08-30 15:32:35
回答 2查看 1K关注 0票数 0

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

ReferenceError: gruntConfig未定义警告:未找到任务"qunit_junit“。继续使用武力。

由于警告而中止。

我的devDependencies:

代码语言:javascript
复制
  "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:

代码语言:javascript
复制
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/'
    }
    };
}

有人遇到了这个错误,或者对如何修复它有想法?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2016-08-30 15:37:24

正如ReferenceError中所述:您还没有定义gruntConfig对象。添加var gruntConfig = {};来定义对象。

代码语言:javascript
复制
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 ...
}
票数 1
EN

Stack Overflow用户

发布于 2016-08-30 15:36:23

查看示例Gruntfile:

代码语言:javascript
复制
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. 注册任务
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39231659

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档