-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Setting per-test environment variables does not merge with per-suite envs & leaks to next test #8005
Comments
Second problemI think it might be caused by the above and the logic we use to merge env variables. The variable from one test can "leak" into the other test it('has its own variable 1', {
env: {
testOne: true,
},
}, () => {
expect(Cypress.env()).to.include({
testOne: true,
})
})
// NOTE: leaking variable from previous test
// https://github.com/cypress-io/cypress/issues/8005
it.skip('has its own variable 2', {
env: {
testTwo: true,
},
}, () => {
expect(Cypress.env(), 'has variable from this test').to.include({
testTwo: true,
})
cy.log(Object.keys(Cypress.env()).join(', '))
.then(() => {
expect(Cypress.env(), 'does not have variable from first test').to.not.have.property('testOne')
})
}) Here is the video how to get it to crash. First, run just the first test, then run both tests together and see variable from the first test in the second test |
Can we expect this can be resolved or using this way is wrong |
@bahmutov I was able to confirm the issues / scenarios included on this issue with Cypress 9.2.1. This is still an issue. |
Huzza, I mean ohhh
…Sent from my iPhone
On Jan 12, 2022, at 10:34, Emily Rohrbough ***@***.***> wrote:
@bahmutov I was able to confirm the issues / scenarios included on this issue with Cypress 9.2.1. This is still an issue.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you were mentioned.
|
@bahmutov I'm running into a problem on v.9.3.1 where I can override an env var but the leak happens on retry. I'd like to help resolve this or find a workaround. |
That’s unfortunate Mike, but I don’t have time to look into this
…Sent from my iPhone
On Feb 8, 2022, at 16:04, mike cataldo ***@***.***> wrote:
@bahmutov I'm running into a problem on v.9.3.1 where I can override an env var but the leak happens on retry. I'd like to help resolve this or find a workaround.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you were mentioned.
|
@bahmutov It's OK. For now. I just reset env variables in
|
Oh, hopefully, that's just a bug. I was going to apply some terrible workarounds to play around this limitation. I can see a test covering |
This issue has not had any activity in 180 days. Cypress evolves quickly and the reported behavior should be tested on the latest version of Cypress to verify the behavior is still occurring. It will be closed in 14 days if no updates are provided. |
Still a problem 🤷♂️ |
I think I found a workaround that I added to Cypress.on("test:before:run", (test) => {
const testLevelEnvironmentVariableOverrides =
test._testConfig.testConfigList.find(
(testConfig: { overrideLevel: string }) =>
testConfig.overrideLevel === "test"
).overrides?.env;
const suiteLevelEnvironmentVariableOverrides =
test._testConfig.testConfigList.find(
(testConfig: { overrideLevel: string }) =>
testConfig.overrideLevel === "suite"
).overrides?.env;
// use test level environment variabels if they exist, otherwise use suite level environment variables
Cypress.env({
...(suiteLevelEnvironmentVariableOverrides || {}),
...(testLevelEnvironmentVariableOverrides || {}),
});
}); |
Cypress v4.10.0
Reproduction https://github.com/cypress-io/cypress-example-recipes recipe examples/server-communication__env-variables spec file
The test sets per-suite environment variables and per-test environment variables.
I expect the final
Cypress.env
object to have the variables from both the suite and the test itselfBut it does not have suite variables
The text was updated successfully, but these errors were encountered: