Product
Introducing License Enforcement in Socket
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
cypress-env
Advanced tools
Cypress Plugin | Easily manage and streamline your Cypress test scripts across multiple environments with the cypress-env npm library. This lightweight utility simplifies the process of handling different environments (such as test, staging, and productio
Easily manage and streamline your Cypress test scripts across multiple environments with the cypress-env npm library. This lightweight utility simplifies the process of handling different environments (such as test, staging, and production) by providing a environment-specific settings in your Cypress tests.
$ npm install cypress-env --save-dev
or as a global module
$ npm install -g cypress-env
In your cypress.config.js file:
module.exports = defineConfig({
e2e: {
setupNodeEvents(on, config) {
require('cypress-env')(on, config, __dirname)
},
},
})
Then configure a folder named `env.config' with your environments.json files:
├── cypress
│ ├── e2e
│ ├── fixtures
│ └── support
├── cypress.config.js
├── env.config
│ ├── test.json
│ ├── stage.json
│ └── prod.json
├── node_modules
├── README.md
├── package-lock.json
├── package.json
└── .gitignore
JSON files must respect this syntax:
//environment.json
{
"baseUrl": "https://www.google.com",
"specPattern": "cypress/e2e/**/**.js",
"excludeSpecPattern": "cypress/e2e/**/toExclude.js",
"supportFile": "cypress/support/customName.js",
"env": {
"var1": "value1",
"var2": "value2",
"var3": "value3",
"envName": "environment"
}
}
Parameter | Mandatory | Overwrites value in cypress.config.js | Notes |
---|---|---|---|
baseUrl | FALSE | TRUE | Overwrites value in cypress.config.js |
specPattern | FALSE | TRUE | Overwrites value in cypress.config.js |
excludeSpecPattern | FALSE | TRUE | Overwrites value in cypress.config.js |
supportFile | FALSE | TRUE | Needs the parameters "supportFile" in the main e2e or component object set to false |
env | FALSE | FALSE | OBJ added to values in cypress.config.js |
Open cypress and inject the envName variables:
npx cypress open -e envName=test
or run cypress and inject the envName variables:
npx cypress run -e envName=test
====================================================================================================
Starting plugin: cypress-env
Extracting local configurations from: "path/to/environment.json"
- baseUrl: "https://www.google.com"
- specPattern: "cypress/e2e/**/**.js"
- excludeSpecPattern: "cypress/e2e/**/toExclude.js",
- supportFile: "cypress/support/customName.js",
- env: "{
"var1": "value1",
"var2": "value2",
"var3": "value3",
"envName": "test"
}"
√ Configurations loaded correctly for the environment: < TEST >
====================================================================================================
====================================================================================================
Starting plugin: cypress-env
√ No environment configuration specified, using basic configuration!
====================================================================================================
====================================================================================================
Starting plugin: cypress-env
ConfigurationError!
You must specify the "__dirname" element in the config, change the require to:
require("cypress-env")(on, config, __dirname)
====================================================================================================
In your package.json file create a script like this:
//package.json
{
"scripts": {
"cy:test": "npx cypress open -e envName=test",
"cy:stage": "npx cypress open -e envName=stage",
"cy:prod": "npx cypress open -e envName=prod"
}
}
So you'll only have to type this command to open cypress in the correct environment:
npm run cy:test
"cypress-aws-secrets-manager" is a plugin that allows a secret stored in the AWS secret manager to be loaded into cypress as an environment variable. To make life easier I added a new key inside ENV: AWS_SECRET_MANAGER_CONFIG.
Parameter | Mandatory | Overwrites value in cypress.config.js | Notes |
---|---|---|---|
AWS_SECRET_MANAGER_CONFIG | FALSE | TRUE | OBJ used by cypress-aws-secrets-manager |
The secret manager plugin will automatically handle this obj to recover the secret archived on AWS secret manager.
//environment.json
{
"baseUrl": "https://www.google.com",
"specPattern": "cypress/e2e/**/**.js",
"excludeSpecPattern": "cypress/e2e/**/toExclude.js",
"supportFile": "cypress/support/customName.js",
"env": {
"var1": "value1",
"var2": "value2",
"var3": "value3",
"envName": "test",
"AWS_SECRET_MANAGER_CONFIG": {
"secretName": "...",
"profile": "...",
"region": "..."
}
}
}
Happy testing to everyone!
ALEC-JS
FAQs
Cypress Plugin | Easily manage and streamline your Cypress test scripts across multiple environments with the cypress-env npm library. This lightweight utility simplifies the process of handling different environments (such as test, staging, and productio
The npm package cypress-env receives a total of 437 weekly downloads. As such, cypress-env popularity was classified as not popular.
We found that cypress-env 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
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
Product
We're launching a new set of license analysis and compliance features for analyzing, managing, and complying with licenses across a range of supported languages and ecosystems.
Product
We're excited to introduce Socket Optimize, a powerful CLI command to secure open source dependencies with tested, optimized package overrides.