morficus / cypress-dotenv

Cypress plugin that enables compatability with dotenv
53 stars 13 forks source link

Update peerDependency version for cypress #10

Closed pke closed 4 years ago

pke commented 4 years ago

This plugin seems to work with 4.x too, maybe we should update the peerDepedency directive?

dandv commented 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.

morficus commented 4 years ago

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

ivanji commented 4 years ago

This didn't work for me either - I tested on version 4.8.0 and nothing.

Is the documentation missing anything?

As I gathered:



- Use Cypress.env('ENV_VAR1') anywhere is required.

Anything I'm missing?
AZimdahl commented 4 years ago

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

ivanji commented 4 years ago

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.

ivanji commented 4 years ago

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')

morficus commented 4 years ago

@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)
morficus commented 4 years ago

@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.

morficus commented 4 years ago

@dandv if you are still having problems getting stuff to work, feel free to open another issue