我需要grep结果
npm测试
以我的bash为条件。
所以我可以停止我的CI / CD环境
有一个suggestion to use grep like:
VALID="$(npm test | grep -o 'failing')"
但是当我这样做时,只是尝试“ npm测试”管道中的实际内容
VALID="$(npm test)"
我看到的是:
echo "$VALID"
> MyApp@0.0.1 test /Users/NE/ts/project
> jest
那么,那将如何工作? 我怎样才能真正验证npm测试的结果?
谢谢!
答案 0 :(得分:1)
诸如“失败”之类的词是针对人类的,而不是针对计算机的。他们应该改用退出代码:
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