Getting weird characters in Git for Windows bash when running cypress from command line

2.2k Views Asked by At

I'm using cypress for test automation and when running a test spec from the Git for Windows bash terminal I get weird characters in the results output:

cypress spec run in Git for Windows bash -

screenshot

If I run cypress from a Windows command prompt the output characters are correct:

cypress spec run in Windows Command Prompt -

screenshot

I'm using Windows 7, cypress 5.1.0, and Git for Windows 2.28.0 with mintty 3.2.0

Any thoughts on how to correct this?

2

There are 2 best solutions below

0
On BEST ANSWER

The issue is described in this GitHub issue.

The problem is that Cypress is sending UTF-8 encoded text through its stdout which is mangled by Windows before being received by Mintty (which is what hosts bash and runs git on Windows).

I understand that Mintty doesn't yet instruct Windows to not mangle the stdout it processes - (cmd.exe does, however, which is why it works there) - but we can do that ourselves by changing our Windows OEM Code Page setting using the chcp program (located at C:\Windows\System32\chcp.com and yes, that's a .com, not .exe). You can add a command to your .bashrc file so it will always run when you fire up Mintty:

  1. Open mintty on Windows - presumably this starts a bash shell.

  2. Go to your home directory (i.e. cd ~)

  3. Open or create a .bashrc file.

  4. Put this in the file (update the path to your chp.com program as appropriate):

    /c/Windows/System32/chcp.com 65001
    
  5. Then restart the terminal window and it should work.

0
On

As both @digijay and @Dai replied above the cause of the issue is described here https://github.com/git-for-windows/git/issues/2806

The issue was resolved with the next release of git-for-windows. Prior to the fix being released, I solved the issue for myself by simply running this at the bash command line before running my cypress run command:

> cmd //c chcp 65001