'Running a command cy.exec('npm run sfdx:latest-leads') will change the json file format

Current behavior

I'm currently working on a project where I set up a command in my package.json. As soon as I run that command through a cypress file, it seems that we are getting a malformatted json file inside of my Fixture files.

json file before we run the command:

{
  "status": 0,
  "result": {
    "totalSize": 1,
    "done": true,
    "records": [
      {
        "attributes": {
          "type": "Lead",
          "url": "/services/data/v51.0/sobjects/Lead/00QL000000U0fV2MAJ"
        },
        "Id": "111111111111111111",
        "Name": "Andres Test Test"
      }
    ]
  }
}

json file after we run the command:

�[97m{�[39m
  �[94m"status"�[39m�[93m:�[39m �[34m0�[39m�[32m,�[39m
  �[94m"result"�[39m�[93m:�[39m �[97m{�[39m
    �[94m"totalSize"�[39m�[93m:�[39m �[34m1�[39m�[32m,�[39m
    �[94m"done"�[39m�[93m:�[39m �[91mtrue�[39m�[32m,�[39m
    �[94m"records"�[39m�[93m:�[39m �[97m[�[39m
      �[97m{�[39m
        �[94m"attributes"�[39m�[93m:�[39m �[97m{�[39m
          �[94m"type"�[39m�[93m:�[39m �[92m"Lead"�[39m�[32m,�[39m
          �[94m"url"�[39m�[93m:�[39m �[92m"/services/data/v51.0/sobjects/Lead/00QL000000U0fV2MAJ"�[39m
        �[97m}�[39m�[32m,�[39m
        �[94m"Id"�[39m�[93m:�[39m �[92m"00QL000000U0fV2MAJ"�[39m�[32m,�[39m
        �[94m"Name"�[39m�[93m:�[39m �[92m"Andres Latest Test"�[39m
      �[97m}�[39m
    �[97m]�[39m
  �[97m}�[39m
�[97m}�[39m

Desired behavior

We should be able to see a well-formatted json file inside of the Fixture file without any weird syntax.

Test code to reproduce You will need to set up the following command inside of your package.json "sfdx:latest-leads": "sfdx force:data:soql:query -q \" SELECT Id, Name FROM Lead WHERE IsConverted=false ORDER BY CreatedDate DESC LIMIT 1\" --json > ./cypress/fixtures/latestLead.json", You will have to set up your cy.exec inside of your cypress fie

 it('Convert Lead to an Opportunity', function () {

        cy.exec('npm run sfdx:latest-leads')

        cy.wait(10000)

    })

Versions cypress version = 7.5.0



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source