bash - bash 条件中 npm 测试的 grep 结果

标签 bash testing npm grep

我需要 grep 一个

的结果

npm test

来 self 的 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

那么,这将如何运作? 我怎样才能真正 grep 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

关于bash - bash 条件中 npm 测试的 grep 结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54916162/

相关文章:

linux - 猫有什么用,它在这里做什么?

linux - 获取linux中打开的应用程序窗口数

testing - 通用 JUnit 测试类

c# - Selenium WebDriver 偶尔抛出超时异常

bash - 寻求 Bash 脚本的帮助以检查 lubuntu 中是否有可用的更新

bash - awk 与空白文件不匹配

java - Mockito thenReturn() 返回空值

node.js - React 如何避免使用 require ("../../Path/To/Module"),而只使用 require ("Module")

javascript - 当我在 React 应用程序上执行 npm start 时,不断收到 "? Something is already running on port 3000"

typescript - 如何安装与旧版 TypeScript 兼容的@types?