2015-06-18 29 views
0

我不明白为什么我无法在一个Gruntfile中注册这两个测试。当我运行grunt test时,它运行得非常好。当我运行grunt web时,它给我Warning: Task "webTest" not found。每个任务中的代码完全一样,为什么如果咕噜只允许一个任务注册?警告:找不到任务“webTest”

// Gruntfile.js 
module.exports = function(grunt){ 
    // Load grunt mocha task 
    grunt.loadNpmTasks('grunt-mocha'); 
    grunt.loadNpmTasks('grunt-mocha-test'); 
    grunt.loadNpmTasks('grunt-contrib'); 

    grunt.initConfig({ 
    pkg: grunt.file.readJSON('package.json'), 

    // webTest 
    webTest: { 
      test: { 
      options: { 
       reporter: 'list', 
       timeout: 2000 
      }, 
      src: ['all.js', 
         'test/groups.js', 
         'test/doctors.js', 
         'test/patients.js', 
         'test/diet.js'] 
      } 
     }, 

    // Mocha Test 
    mochaTest: { 
      test: { 
      options: { 
       reporter: 'list', 
       timeout: 2000 
      }, 
      src: ['all.js', 
         'test/groups.js', 
         'test/doctors.js', 
         'test/patients.js', 
         'test/diet.js'] 
      } 
     } 
    }); 

    grunt.registerTask('web', ['webTest']); 
    grunt.registerTask('test', ['mochaTest']); 
}; 

回答

0

想通了:

// Gruntfile.js 
module.exports = function(grunt){ 
    // Load grunt mocha task 
    grunt.loadNpmTasks('grunt-mocha'); 
    grunt.loadNpmTasks('grunt-mocha-test'); 
    grunt.loadNpmTasks('grunt-contrib'); 

    grunt.initConfig({ 
    pkg: grunt.file.readJSON('package.json'), 

    // Mocha Test 
    mochaTest: { 
      test: { 
      options: { 
       reporter: 'list', 
       timeout: 2000 
      }, 
      src: ['test/groups.js', 
         'test/doctors.js', 
         'test/patients.js', 
         'test/diet.js'] 
      }, 
      web_enter: { // fill database for website testing 
      options: { 
       reporter: 'list', 
       timeout: 2000 
      }, 
      src: ['test/web_testing_enter.js'] 
      }, 
      web_remove: { // remove data entered for website testing 
      options: { 
       reporter: 'list', 
       timeout: 2000 
      }, 
      src: ['test/web_testing_remove.js'] 
      } 
     } 
    }); 

    grunt.registerTask('we', ['mochaTest:web_enter']); 
    grunt.registerTask('wr', ['mochaTest:web_remove']); 
    grunt.registerTask('default', ['mochaTest:test']); 
}; 
相关问题