简体   繁体   中英

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

I am new to React and attempting to use npm test .

From the docs , it is my understanding that every time npm test runs, it starts the watcher. The watcher is supposed to display a list of commands titled "Watch Usage". This includes commands such as a, f and q.

When I run npm test , watcher appears to work because it runs the tests and reruns them if I save a file.

However, it does not display the "Watch Usage" list and if I type any of the "Watch Usage" commands, nothing happens.

How can I enable the "Watch Usage" commands?

I was attempting to run this command in Git Bash. I have not found a solution to make it work in Git Bash.

However, you can instead run the command in cmd.exe and it will work properly.

The Jest VSCode extension can also be helpful.

There is a problem with running Jest inside Git Bash on Windows. 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.

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.

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.

The only successful work around that I've found is running Jest from inside winpty if you're using Git Bash.

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.

    "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:

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

run npm test

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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