在非交互模式下运行CRA Jest [英] Running CRA Jest in non-interactive mode

查看:123
本文介绍了在非交互模式下运行CRA Jest的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

更新:我的用例主要是在CI上运行测试,但是我通常想覆盖默认的CRA Jest参数.

我正在使用 Jest 进行测试://github.com/facebookincubator/create-react-app"rel =" noreferrer>创建React App .它总是启动为交互模式:

I'm running tests using the Jest, config that came with Create React App. It always launches into the interactive mode:

 › 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开关,但它仍以交互模式启动.

But I don't want it to wait for my input. I want it to run once and then terminate. I tried using the --bail or --no-watchman switches but it still launches in interactive mode.

如果我全局安装了jest,并在我的项目的根目录中运行它,它将执行一次并完成(如我所愿).但是当我运行npm test而又运行react-scripts test时,即使我没有通过--watch,它也会进入监视模式.

If I globally install jest, and run it in the root of my project, it executes once and finish (just as I want). But when I run npm test which runs react-scripts test, it goes into the watch mode even when I'm not passing --watch.

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

Update: I've also filed an issue on CRA.

推荐答案

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

CRA looks for a CI environment variable, if its present it doesn't run in watch mode.

CI=true npm test应该可以满足您的需求

CI=true npm test should do what you are looking for

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

更新 对于非CI,例如在本地运行测试,可以从react-scripts@2.1.4传递--no-watch标志:

UPDATE For non-ci, eg running tests locally, from react-scripts@2.1.4 you can pass a --no-watch flag:

npm test --no-watch

这篇关于在非交互模式下运行CRA Jest的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆