Skip to content

Instantly share code, notes, and snippets.

@prodrammer
Last active April 7, 2021 18:41
Show Gist options
  • Save prodrammer/c586a080fa2a90c12328b762ba8266c5 to your computer and use it in GitHub Desktop.
Save prodrammer/c586a080fa2a90c12328b762ba8266c5 to your computer and use it in GitHub Desktop.
Configure cypress.io using dotenv-extended, and getenv
// ***********************************************************
// https://on.cypress.io/plugins-guide
// ***********************************************************
const dotenv = require('dotenv-extended')
const getenv = require('getenv')
dotenv.load()
const overrideBaseUrl = () => {
let baseUrl = getenv.string('CYPRESS_BASE_URL', '')
if (!baseUrl) {
const scheme = getenv.bool('DEV_HTTPS') ? 'https://' : 'http://'
const host = getenv.string('DEV_HOST')
const port = getenv.string('DEV_PORT')
baseUrl = `${scheme}${host}:${port}`
}
return baseUrl
}
// This function is called when a project is opened or re-opened (e.g. due to
// the project's config changing)
module.exports = (on, config) => {
config.baseUrl = overrideBaseUrl()
return config
}
@prodrammer
Copy link
Author

prodrammer commented Jun 14, 2018

Sorry, I just realized this in the docs (you MUST return config if you want modifications to be included)...realized you commented here as well. You are correct! Updated!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment