Closed pke closed 4 years ago
I'm not sure if this plugin supports Cypress 4.9.0. I have .env
files in the root directory of my site, under cypress
, under cypress/integration
, and they're not read in. console.log(Cypress.env())
produces an empty object.
I'll get to this over the weekend.
@dandv I haven't tested with 4.9.0 but I'll look in to your issue as well
This didn't work for me either - I tested on version 4.8.0 and nothing.
Is the documentation missing anything?
As I gathered:
module.exports = (on, config) => {
// `on` is used to hook into various events Cypress emits
// `config` is the resolved Cypress config
config = dotenvPlugin(config)
return config
}
- Use Cypress.env('ENV_VAR1') anywhere is required.
Anything I'm missing?
I was able to get it to work with passing in the path for the optional dotenvConfigObject
and setting the optional boolean to true in the plugins/index.js:
const dotenvPlugin = require('cypress-dotenv');
/**
* @type {Cypress.PluginConfig}
*/
module.exports = (on, config) => {
config = dotenvPlugin(
config,
{path: process.env.PWD + '/.env'},
true
)
console.log(config.env)
return config
}
My .env file is in the root directory of my project
I tried your suggestion @AZimdahl but didn't make a difference here - the config.env looks correct though, I feel like something else is missing. I'll dig deeper later today. Thanks.
OK, got it working. I realised what I was doing wrong. env variables have prefix CYPRESS_ and when calling them we shouldn't use the prefix. CYPRESS_AUTH_USERNAME
would be called Cypress.env('AUTH_USERNAME')
@pke everything seems to be working as expected when using Cypress 4.9.0, so I'll be changing the peerDependencies
to be >= 3.x
@ivanji and @AZimdahl -- glad to hear you guys got stuff figured out. quick pro tip: if you need to pass in the 3rd option argument don't have any custom dotEnv config to pass in, you can just pass in an empty object or null as the 2nd argument
config = dotenvPlugin(config, {}, true)
// or
config = dotenvPlugin(config, null, true)
@dandv are you still having issues with this plugin and cypress 4.9.0? I just gave things a spin and wasn't able to find any problems.
@dandv if you are still having problems getting stuff to work, feel free to open another issue
This plugin seems to work with 4.x too, maybe we should update the peerDepedency directive?