我不明白为什么我不能在一个Gruntfile中注册这两个测试。当我运行grunt test时,它运行得非常好。当我运行grunt web时,它给出了Warning: Task "webTest" not found。每个任务中的代码是完全相同的,那么为什么grunt只允许一个任务注册呢?
// 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']);
};发布于 2015-06-19 06:52:02
弄清楚了:
// 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']);
};https://stackoverflow.com/questions/30922232
复制相似问题