以非交互模式运行CRA Jest

Ale*_*ack 37 reactjs jestjs redux create-react-app

更新:我的用例主要是在CI上运行测试,但是重写默认的CRA Jest参数是我一般想知道的.


我正在使用Create React App附带的Jest,config 运行测试.它始终启动到交互模式:

 › Press a to run all tests.
 › Press o to only run tests related to changed files.
 › Press p to filter by a filename regex pattern.
 › Press q to quit watch mode.
 › Press Enter to trigger a test run.
Run Code Online (Sandbox Code Playgroud)

但我不希望它等待我的意见.我希望它运行一次然后终止.我尝试使用--bail--no-watchman开关,但它仍然以交互模式启动.

如果我全局安装jest,并在我的项目的根目录中运行它,它执行一次并完成(就像我想要的那样).但是当我运行npm test哪个运行时react-scripts test,即使我没有通过,它也会进入监视模式--watch.

更新:我还在CRA上提出了一个问题.

Way*_*neC 54

CRA查找CI环境变量,如果它目前不在监视模式下运行.

CI=true npm test 应该做你想要的

请参阅用户指南 - >运行测试 - >在您自己的环境中

  • 现在看起来像 --watchAll=false (4认同)

thi*_*ign 17

在您的package.json脚本中:

"test": "react-scripts test --watchAll=false"

或者 npm test -- --watchAll=false

或者 yarn test --watchAll=false

注意:使用的标志被称为--no-watchreact-scripts < 3.0https://github.com/facebook/create-react-app/blob/3.x/CHANGELOG.md#remove---no-watch-flag