Running Cypress tests as a Gradle task yields non-ASCII characters

  Kiến thức lập trình

This topic has been discussed at length. I’ve read several posts on Github and SO, however I am unable to find a reliable solution. My question is specific to the Windows 11 environment, Java 17 and Gradle 7.6.1. Here are only a few resources I have read (there are many):

Github post1

Github post2

Most of these posts reference an environment variable NO_COLOR. However, since I’m running in Windows, I actually want the formatting. This application is a Spring Boot/Angular project. Here is what I’ve noticed:

If I run my cypress tests directly from the Windows 11 CMD terminal,

npx cypress run --spec cypress/e2e/app/* --config baseUrl=http://localhost:8080

I get nicely formatted output with colors. This is of course expected. In fact, if I run

npm run cy:run:win

The formatting also looks fine as well.

However if I run the above command within a Gradle task,

tasks.register('cypressTest', Exec) {
  workingDir "$projectDir"
  inputs.dir "$projectDir"
  group = "verification"
  if (System.getProperty("os.name").toUpperCase().contains("WINDOWS")) {
    commandLine "cmd.exe", "/c", "npm.cmd", "run", "cy:run:win"
  } else {
    commandLine "npm", "run", "cy:run:ci"
  }
}

I get unreadable output:

ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö?
Γöé Tests: 3
Γöé
Γöé Passing: 3
Γöé
Γöé Failing: 0
Γöé
Γöé Pending: 0
Γöé
Γöé Skipped: 0
Γöé
Γöé Screenshots: 0
Γöé
Γöé Video: false
Γöé
Γöé Duration: 30 seconds
Γöé
Γöé Spec Ran: smoke.spec.js
Γöé
ΓööΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÿ

More than just colors are at play here. There are other non-ascii characters used to format boxes and check marks. I have no problem with colors and formatting in Windows but I would like it to work the same way in Gradle that is does running directly from the Windows CMD window.

Here is the relevant scripts section of my package.json for reference:

"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"cy:open": "npx cypress open --e2e --browser electron",
"cy:run:win": "npx cypress run --spec cypress/e2e/app/* --config baseUrl=http://localhost:8080",
"cy:run:ci": "NO_COLOR=1&& npx cypress run --spec cypress/e2e/app/* --config baseUrl=http://cypress-container:8080"
}

This seems to be either a Gradle issue with the command window properties or a Java issue. I would like to get the same output as a Gradle task as I get when running tests manually.

Theme wordpress giá rẻ Theme wordpress giá rẻ Thiết kế website

LEAVE A COMMENT