2016-09-27 54 views
12

更新:我的用例主要是在CI上运行测试,但覆盖默认CRA Jest参数是我一般想知道的。在非交互模式下运行CRA Jest


我使用Jest,配置与Create React App来运行测试。它始终启动到交互模式:

› 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. 

但我不希望它等待我的输入。我希望它运行一次然后终止。我尝试使用--bail--no-watchman交换机,但仍以交互模式启动。

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

更新:我也在CRA上提交了一个问题。

回答

14

CRA查找CI环境变量,如果它存在,它不会在watch模式下运行。

CI=true npm test应该做你在找什么

这在ReadmeContinuous Integration部分记录。

+0

你可以看到它的确认[这里](https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/scripts/test.js#L25) – wgcrouch

+0

yes ,就这个问题而言,没有更简单的方法:https://github.com/facebookincubator/create-react-app/issues/784 – AlexStack