2015-06-18 52 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']); 
}; 
相關問題