尝试对节点应用程序运行功能测试。 在package.json中,我有这些
"scripts": {
"web-server": "NODE_ENV=test node app.js &",
"test": "npm run web-server && mocha ./tests/functional/*.js --exit",
"posttest": "pkill -f node"
}
但是在运行它时,将在服务器完成启动之前运行测试。如何等待服务器请求?
答案 0 :(得分:2)
我今天发现wait-on并喜欢它的方法。它只会等待,而不是命令启动。
与concurrently
一起使用,就像这样:
"scripts": {
"xxx": "concurrently -n server,mocha \"npm run web-server" \"npx wait-on http://localhost:8080 && npx mocha ...\"",
想向新访客提及。我认为wait-on
是目前标题问题的最合适答案。