What does everyone do for storing `baseUrl`? The d...
# best-practices
a
What does everyone do for storing
baseUrl
? The docs at https://docs.cypress.io/api/plugins/configuration-api#Switch-between-multiple-configuration-files indicate that this value can be set in
cypress/config/env.json
but it fails when I do that. I have to have it set in
cypress.json
or pass it in at runtime via my run scripts. I am thinking about using
/plugins/index.js
to set my
baseUrl
, but it would really be nice to just set it in my environmental config files. Anyone else been down this path before and know what I'm missing?
In my run scripts I pass in
--config baseUrl=https://env.domain.com"
g
Did you forget to read the env config file and return it from your plugin file?
Copy code
function getConfigurationByFile(file) {
  const pathToConfigFile = path.resolve('..', 'config', `${file}.json`)

  return fs.readJson(pathToConfigFile)
}

// plugins file
module.exports = (on, config) => {
  // accept a configFile value or use development by default
  const file = config.env.configFile || 'development'

  return getConfigurationByFile(file)
}
a
My code looks different but this must be happening because I can use other data in my
/config/env.json
files in tests.
Well now this is extra weird. It's looking for
/config/env.json
in the directory one up from the package I have
cypress
installed in.
Error: ENOENT: no such file or directory, open '/Users/user/Documents/src/project/parentFolder/config/env.json'
This error throws even when I remove the
".."
from the
path.resolve()
step.
16 Views