Last active
April 7, 2021 18:41
-
-
Save prodrammer/c586a080fa2a90c12328b762ba8266c5 to your computer and use it in GitHub Desktop.
Configure cypress.io using dotenv-extended, and getenv
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// *********************************************************** | |
// 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 | |
} |
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
You might need to return
config
... I'm not sure what we do if returnundefined
. You're mutatingconfig
so it may just work, but ideally you make it clear thatconfig
is the return value.