我需要抓住
的结果NPM测试
从我的bash条件下。
所以我可以停止我的CI/CD环境
有一个建议使用GREP,例如:
VALID="$(npm test | grep -o 'failing')"
但是,当我这样做时,只是为了尝试" NPM测试"中实际是什么
VALID="$(npm test)"
我看到的是:
echo "$VALID"
> MyApp@0.0.1 test /Users/NE/ts/project
> jest
那么,这将如何工作?我该如何真正抓住NPM测试的结果?
谢谢!
诸如"失败"之类的单词是针对人类而不是计算机的。他们应该使用退出代码:
if ! npm test
then
# Tell the human about the failure, if the npm output wasn't enough
echo >&2 "Testing failed"
# Exit and tell computers about the failure (0 = success, 1+ = failure)
exit 1
fi
您可以更简洁地获得相同的效果:
npm test || exit