
Product
A New Overview in our Dashboard
We redesigned Socket's first logged-in page to display rich and insightful visualizations about your repositories protected against supply chain threats.
@commercetools-frontend/cypress-environments
Advanced tools
Cypress package to setup environment configuration using dotenv files
This package allows to load environment variables into a Cypress environment from dotenv files.
$ npm install --save @commercetools-frontend/cypress-environments
Inside of your cypress.config.js
import the package as follows:
const {
getConfigurationForEnvironment,
} = require('@commercetools-frontend/cypress-environments');
Then inside your e2e.setupNodeEvents
in Cypress v10.x load the configuration by calling await getConfigurationForEnvironment(environment)
.
This will return an object with the merged configuration based on the requested environment.
This module uses cosmiconfig to load a configuration file named cypress-environments
. As a result it supports many formats such as cypress-environments.config.cjs
or cypress-environments.rc.json
depending on your preference.
Within the configuration file an array environments
property should be defined containing a set of environments with name
, secrets
and config
globs.
The contents of the configuration file could look like:
const projectKeys = {
gcpEu: 'ctp_production_gcp_europe-west1_v1',
};
module.exports = {
environments: [
{
name: projectKeys.gcpEu,
secrets: `cypress/config/${projectKeys.gcpEu}/.env.secrets*`,
config: `cypress/config/${projectKeys.gcpEu}/.env.config*`,
},
],
};
From here the documentation assumes the above format and naming for further examples.
The package expects configurations for environments to be stored in cypress/config/<environment_name>
. For example this structure:
cypress/config
├── ctp_production_gcp_europe-west1_v1
|──── .env.config
|──── .env.secrets.ci (Decrypred from `*.enc`)
|──── .env.config.local.template
|──── .env.secrets.local.template
├── ctp_production_aws_eu-central-1_v1
└── vw_production_aws_eu-central-1_v1
Would load the values from .env.config
anytime the environment is ctp_production_gcp_europe-west1_v1
. Additionally on CI (when CI=true
) it would load the .env.secrets.ci
file, otherwise it would attempt to load values from .env.config.local
and .env.secrets.local
(assuming they have been properly configured - see *.template
files for reference).
Given multiple files can be loaded some values can be overwritten by a subsequently loaded file. First the .env.config
file will be loaded. After the secrets from .env.secrets
and then .env.secrets.ci
or .env.secrets.local
respectively. Any file loaded later can overwrite values of a file loaded before.
The module provides default values for ctp_production_aws_eu-central-1_v1
, ctp_production_gcp_europe-west1_v1
, ctp_production_gcp_us-central1_v1
and ctp_production_gcp_australia-southeast1_v1
. These values will be loaded first before any custom configuration. These default configurations contain the API_URL
, MC_API_URL
, MC_URL
and AUTH_URL
for the given environment.
Inspect the logs of the module to inspect which files match the globs. This output could be:
ℹ️ 'CI' environment variables are defined. Assuming operating from a CI system.
ℹ️ Found 1 secret file(s) and 1 config file(s) matching the defined globs.
✅ Found and loading environment variables from: 'cypress/config/ctp-gcp-production-eu/.env.config'
ℹ️ No environment variables at: 'cypress/config/ctp-gcp-production-eu/.env.config.ci'. If needed create it or duplicate the template file.
✅ Found and loading environment variables from: 'cypress/config/ctp-gcp-production-eu/.env.secrets.ci'
✅ Found and loading environment variables from: '/Users/<username>/merchant-center-frontend/packages-cypress/environments/src/config/.env.ctp-gcp-production-eu.config'
Verify that the files are loaded as expected and make sure they exist.
Make sure the secrets are decrypted on CI from the *.enc
or locally a *.template
file for the secrets has been duplicated and filled.
Ensure that the CI
environment variable is set. Most CI providers set it by default but you can also pass it to the command when running Cypress.
FAQs
Cypress package to setup environment configuration using dotenv files
We found that @commercetools-frontend/cypress-environments demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
We redesigned Socket's first logged-in page to display rich and insightful visualizations about your repositories protected against supply chain threats.
Product
Automatically fix and test dependency updates with socket fix—a new CLI tool that turns CVE alerts into safe, automated upgrades.
Security News
CISA denies CVE funding issues amid backlash over a new CVE foundation formed by board members, raising concerns about transparency and program governance.