question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cypress.env() state is not reset on rerun of test

See original GitHub issue

Current behavior:

Cypress.env() state is only read in once when the runner starts. This causes any changes to Cypress.env() to not reset when you rerun a test.

Desired behavior:

Clean, fresh Cypress.env() for each rerun of a test.

Steps to reproduce: (app code and test code)

{
  "env": {
    "num": 2
  }
}
it('should set ENV var num', () => {
  cy.log(`${Cypress.env('num')}`) // logs 2, but 3 on rerun
  Cypress.env('num', 3)
  cy.log(`${Cypress.env('num')}`) // logs 3
})
Screen Shot 2021-02-05 at 3 15 22 PM

But if I rerun the test, the log is already 3 at the beginning.

Screen Shot 2021-02-05 at 3 15 05 PM

Versions

3.8.0

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:1
  • Comments:10 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
varshanharshankcommented, Jan 13, 2022

yes . still this issue persists in 9.2 version

1reaction
wejendorpcommented, Apr 23, 2020

Nice writeup, I’m hitting the same issue, with both Cypress.config and Cypress.env. This is still occuring in cypress@4.4.1.

The docs state that both env and config resets between both runs and test suites, neither of which is currently true.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Test Retries - Cypress Documentation
If the test fails a third time, Cypress will mark the test as failed and then move on to run any remaining tests....
Read more >
Run Just The Failed Tests In Cypress - Gleb Bahmutov
Then I reset the failed tests filter by running the Cypress.grep() from the console, and Cypress starts running all tests again.
Read more >
reset cypress config on rerunning tests - Stack Overflow
I have the problem. when i pass body instead of fixture in the interceptor , cypress forces the header to application/json . no...
Read more >
Configuring Vitest
To configure vitest itself, add test property in your Vite config. ... setup return { teardown() { // called after all tests with...
Read more >
End-to-end tests with Cypress - Metabase
You can also call restore() inside beforeEach() to reset before every test, or inside specific tests. Snapshots are created with a separate set...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found