好吧,我的package.json中有这些脚本来测试NodeJS中的一些代码。
"scripts": {
"pretest": "env NODE_ENV=test sequelize db:migrate",
"test": "jest",
"posttest": "env NODE_ENV=test sequelize db:migrate:undo:all"
}当测试清除时,“后置测试”将运行,但当测试失败时,我将收到一个
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.在VS代码中。关于这个问题的链接没有任何用处,在互联网上也是如此。
所以我找到了这个关于国家预防机制的链接:
https://github.com/npm/npm/issues/5493
那家伙说:
在绝大多数情况下,如果测试失败后运行,用户会感到不快(例如,如果有测试失败,您不希望清理测试环境或发布新版本)。因此,这种行为不会改变。将类似于“测试”的内容:“npm运行脚本测试-脚本测试
这并没有解决我的问题。经过更多的研究,我发现:
npm posttest doesn't trigger if npm test fails
这些解决办法对我也没有用。
那么,即使测试失败,我如何运行"posttest“脚本呢?
发布于 2020-07-18 19:37:01
好吧,通过上面的对话,我找到了一个解决方案:
这是我在package.json中的脚本
"scripts": {
"dev": "nodemon src/server.js",
"pretest": "env NODE_ENV=test sequelize db:migrate",
"run-tests": "jest",
"run-after-tests": "env NODE_ENV=test sequelize db:migrate:undo:all",
"test": "npm-run-all run-tests run-after-tests --continue-on-error"
},我安装了npm-run-all包,即使测试失败,它也运行run-after-test脚本。现在我明白了错误
error Command failed with exit code 1.
来自test脚本,以及
ERROR: "test" exited with 1.
error Command failed with exit code 1.但是最终我的问题解决了。如果有人有一个更好的解决方案,没有错误在脚本的末尾,请与我们分享。
https://stackoverflow.com/questions/62964960
复制相似问题