我发现这个关于如何使用 nodejs 测试 Rest API 的非常有用的教程:http: //thewayofcode.wordpress.com/2013/04/21/how-to-build-and-test-rest-api-with-nodejs-express -摩卡/
我仍在寻找一种使用“测试”数据库运行“测试”服务器的方法(每次测试开始时都会被清空)
目前我的 grunt js 设置是这样的:
//...
concurrent: {
nodemon_test: {
options: {
logConcurrentOutput: true,
},
tasks: [
'nodemon:dev',
'mochaTest'
]
},
},
nodemon: {
test: {
options: {
file: 'server.js',
args: ['test'],
watchedExtensions: ['js'],
watchedFolders: ['server'],
debug: false,
delayTime: 2,
env: {
NODE_ENV: 'test'
},
cwd: __dirname
}
}
}
//...
grunt.registerTask('test', [
'concurrent:nodemon_test',
]);
但是因为我不知道如何等到服务器运行并连接到数据库