简体   繁体   English

开玩笑:`npm test` 未在 Windows Git Bash 中显示“Watch Usage”选项

[英]Jest: `npm test` not displaying "Watch Usage" options in Windows Git Bash

I am new to React and attempting to use npm test .我是 React 的新手,正在尝试使用npm test

From the docs , it is my understanding that every time npm test runs, it starts the watcher.文档中,我了解到每次npm test运行时,它都会启动观察器。 The watcher is supposed to display a list of commands titled "Watch Usage".观察者应该显示标题为“Watch Usage”的命令列表。 This includes commands such as a, f and q.这包括诸如 a、f 和 q 之类的命令。

When I run npm test , watcher appears to work because it runs the tests and reruns them if I save a file.当我运行npm test时,watcher 似乎可以工作,因为它运行测试并在我保存文件时重新运行它们。

However, it does not display the "Watch Usage" list and if I type any of the "Watch Usage" commands, nothing happens.但是,它不显示“Watch Usage”列表,如果我键入任何“Watch Usage”命令,什么也不会发生。

How can I enable the "Watch Usage" commands?如何启用“Watch Usage”命令?

I was attempting to run this command in Git Bash.我试图在 Git Bash 中运行这个命令。 I have not found a solution to make it work in Git Bash.我还没有找到使它在 Git Bash 中工作的解决方案。

However, you can instead run the command in cmd.exe and it will work properly.但是,您可以改为在 cmd.exe 中运行该命令,它会正常工作。

The Jest VSCode extension can also be helpful. Jest VSCode 扩展也很有帮助。

There is a problem with running Jest inside Git Bash on Windows.在 Windows 上的 Git Bash 中运行 Jest 存在问题。 The terminal codes for updating the screen are not correctly handled, and I've been unable to find a reason or fix for this searching Google.更新屏幕的终端代码未正确处理,我一直无法找到原因或修复此搜索 Google。

If you run npm test from a DOS prompt, then it seems to work fine, but if you run npm test from a Git Bash prompt the progress feedback from Jest is missing.如果您从 DOS 提示符运行npm test ,那么它似乎工作正常,但是如果您从 Git Bash 提示符运行npm test ,则缺少来自 Jest 的进度反馈。

You can enable colors by running npm run test -- --colors which gets Jest to output the color status for tests in Git Bash, but strangely the colors are working but the progress is still not shown.您可以通过运行npm run test -- --colors来启用颜色,这让 Jest 在 Git Bash 中输出测试的颜色状态,但奇怪的是颜色正在工作,但仍未显示进度。

The only successful work around that I've found is running Jest from inside winpty if you're using Git Bash.如果您使用的是 Git Bash,我发现唯一成功的解决方法是从winpty内部运行 Jest。

winpty npm.cmd test

So what I do is add an alternative npm script to my package.json file for running on Git Bash inside Windows.所以我要做的是在我的package.json文件中添加一个替代 npm 脚本,以便在 Windows 中的 Git Bash 上运行。

    "wintest": "winpty npm.cmd run test",

Then you can just run that instead.然后你可以运行它。

npm run wintest

It's not a perfect solution, but at least you can see the progress correctly.这不是一个完美的解决方案,但至少您可以正确地看到进度。

You can activate watch mode, modify your package.json:您可以激活手表模式,修改您的 package.json:

 "scripts": { "test": "jest --watch", }

run npm test运行npm test

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM