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

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

问题描述

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

我正在使用 Jest 运行测试,配置随 创建 React 应用程序.它总是以交互模式启动:

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,并在我的项目的根目录中运行它,它会执行一次并完成(就像我想要的那样).但是当我运行运行 react-scripts testnpm 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.

推荐答案

你应该使用 Jests--watchAll=false 标志.

You should use Jests --watchAll=false flag.

例如:

npm test -- --watchAll=false

注意:这是针对react-scripts >3.00

对于旧版本:

  • react-scripts >= 2.1.4 <3.00

对于非 ci,例如在本地运行测试,您可以传递一个 --no-watch 标志:

For non-ci, eg running tests locally, you can pass a --no-watch flag:

npm test --no-watch

  • 反应脚本<=2.1.3

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

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

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

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

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

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