Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Values created as part of tests using cy.write are not taken by Cypress if we add {watchForFileChanges: false} in Cypres.json #22410

Closed
chaitanyarajugithub opened this issue Jun 21, 2022 · 2 comments

Comments

@chaitanyarajugithub
Copy link

chaitanyarajugithub commented Jun 21, 2022

Current behavior

As part of the tests, I am creating a test data JSON file in the features folder.

describe('Balance Measurement', () => {
    beforeEach(() => {
        cy.writeFile('cypress/fixtures/data/simulator.json', { "SAMPLEID": faker.random.alphaNumeric(5), "METHODSPECIES": faker.random.alpha(5), "STUDYNO": faker.random.numeric(8), "ANIMALID": faker.random.numeric(4) })
    })

    it('Start Dynamic weighing and add 2 protocols and export and complete', () => {
        cy.visit('/');
    });
});

What I am trying to do is, I am creating test data and using it as part of tests and validating output data with created data.

In cypress without adding these commands watchForFileChanges: false in cypress.json, the tests keep looping as there is a file change.
With adding the command watchForFileChanges: false in cypress.json it is not taking the latest created values of the file. it is taking old values.

Desired behavior

The file changes are values created as part of tests using cy.write should be able to get the latest values in tests. if we not adding {watchForFileChanges: false} is there any way to stop the re-run of tests for file changes.

Test code to reproduce

Test file:
`describe('Balance Measurement', () => {
beforeEach(() => {
cy.writeFile('cypress/fixtures/data/simulator.json', { "SAMPLEID": faker.random.alphaNumeric(5), "METHODSPECIES": faker.random.alpha(5), "STUDYNO": faker.random.numeric(8), "ANIMALID": faker.random.numeric(4) })
})

it('Start Dynamic weighing and add 2 protocols and export and complete', () => {
    cy.visit('/');
});

});
File created:{
"SAMPLEID": "blisp",
"METHODSPECIES": "ofiik",
"STUDYNO": "90077968",
"ANIMALID": "1314"
}ADDED below code in cypress.json{watchForFileChanges: false}`

Cypress Version

"cypress": "^9.5.1"

Other

No response

@tbiethman
Copy link
Contributor

@chaitanyarajugithub thank you for the report. Reading over your issue, I figured I knew why this was happening, and that we were detecting fixture changes as spec file changes incorrectly. I built a simple test case to verify, but as it turns out I don't see the same behavior that you are reporting.

describe('dynamic fixture testing', () => {
  let val1
  let val2
  beforeEach(() => {
      val1 = Math.random()
      val2 = Math.random()

      cy.writeFile('cypress/fixtures/data/simulator.json', { val1, val2 })
  })

  for (let i of Array(10)) {
    it('asserts fixture data', () => {
      cy.readFile('cypress/fixtures/data/simulator.json').then((file) => {
        expect(file.val1).to.eq(val1)
        expect(file.val2).to.eq(val2)  
      })
    })
  }
})

The above spec in my environment generates 10 sets of unique data, one for each it executed, and only runs them once, even with watchForFileChanges enabled. I tested this both with Cypress 9.5.3 and Cypress 10.3.0, and the behavior I'm seeing is the same for both versions.

Try giving the above test a shot in your project; if it triggers a loop, there's something else impacting this behavior. Providing your OS/version and your cypress config file would also help us investigate more granularly.

@cypress-bot cypress-bot bot added stage: awaiting response Potential fix was proposed; awaiting response and removed stage: investigating Someone from Cypress is looking into this labels Jun 30, 2022
@tbiethman
Copy link
Contributor

Unfortunately we have to close this issue due to inactivity. Right now there doesn't seem to be enough information to reproduce the problem on our end. We'll have to close this issue until we can reproduce it. This does not mean that your issue is not happening - it just means that we do not have a path to move forward.

Please open a new issue with a reproducible example and link to this issue. Here are some tips for providing a Short, Self Contained, Correct, Example and our own Troubleshooting Cypress guide.

@tbiethman tbiethman removed their assignment Jul 11, 2022
@tbiethman tbiethman removed the stage: awaiting response Potential fix was proposed; awaiting response label Jul 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants