I have an Nx powered angular project and am facing an issue where values supplied in a cypress.env.json file do not override corresponding entries in the env object of the cypress.json configuration file
This is the first time I have attempted this with an Nx powered project, in a non Nx angular project this behaviour works out of the box with Cypress.
Steps to Reproduce
In an e2e application's cypress.json file, add an env object property with an empty value assigned to a some variable name property:
// cypress.json
"env": {
"MY_VAR": "abc"
}
Create a cypress.env.json file at the same location as cypress.json with a key matching the env variable name just added to cypress.json:
// cypress.env.json
{
"MY_VAR": "xyz"
}
Now create a simple test suite to assert that the env variable is equal to the value in the cypress.env.json
// create a test spec containing this
describe('When reading the MY_VAR env variable', () => {
it('should match the value in our cypress.env.json file', () => {
cy.log('MY_VAR = ' + Cypress.env('MY_VAR'))
expect(Cypress.env('MY_VAR')).to.eq('xyz');
});
});
When running this suite via the nx e2e runner (nx run app-name:e2e) an assertion error will be thrown:
AssertionError: expected 'abc' to equal 'xyz'
+ expected - actual
-'abc'
+'xyz'
I have verified the behaviour works as expected with a non Nx angular\cypress project of mine - its worth noting the cypress.env.json in my other project is at the root of the project along with the cypress.json file.
I tried locating the cypress.env.json file in my Nx project at the root, instead of inside apps/my-app-e2e/src next to the cypress.json, but this made no difference.
Am I misunderstanding how to achieve this via Nx?
Project dependencies are as follows:
Node : 12.16.3
OS : darwin x64
npm : 6.14.5
nx : 12.9.0
@nrwl/angular : 12.9.0
@nrwl/cli : 12.9.0
@nrwl/cypress : 12.9.0
@nrwl/devkit : 12.9.0
@nrwl/eslint-plugin-nx : 12.9.0
@nrwl/express : Not Found
@nrwl/jest : 12.9.0
@nrwl/linter : 12.9.0
@nrwl/nest : 12.9.0
@nrwl/next : Not Found
@nrwl/node : 12.9.0
@nrwl/nx-cloud : 12.3.13
@nrwl/react : Not Found
@nrwl/schematics : Not Found
@nrwl/tao : 12.9.0
@nrwl/web : Not Found
@nrwl/workspace : 12.9.0
@nrwl/storybook : 12.9.0
@nrwl/gatsby : Not Found
typescript : 4.3.5
