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("").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