Skip to content

Commit

Permalink
Add and configure custom env files. (#181)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mohini Dahiya authored Mar 7, 2022
1 parent 632413d commit 1761c7f
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 5 deletions.
21 changes: 21 additions & 0 deletions cypress/config/cypress.development.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"baseUrl": "http://localhost:3000",
"testFiles": "**/*.spec.js",
"execTimeout": 1800000,
"defaultCommandTimeout": 10000,
"requestTimeout": 30000,
"pageLoadTimeout": 60000,
"responseTimeout": 10000,
"viewportWidth": 1200,
"viewportHeight": 1200,
"videoUploadOnPasses": true,
"screenshotsFolder": "cypress/artifacts/screenshots",
"videosFolder": "cypress/artifacts/videos",
"retries": {
"runMode": 2,
"openMode": 2
},
"env": {
"apiUrl": "http://localhost:3000"
}
}
21 changes: 21 additions & 0 deletions cypress/config/cypress.production.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"baseUrl": "",
"testFiles": "**/*.spec.js",
"execTimeout": 1800000,
"defaultCommandTimeout": 10000,
"requestTimeout": 30000,
"pageLoadTimeout": 60000,
"responseTimeout": 10000,
"viewportWidth": 1200,
"viewportHeight": 1200,
"videoUploadOnPasses": true,
"screenshotsFolder": "cypress/artifacts/screenshots",
"videosFolder": "cypress/artifacts/videos",
"retries": {
"runMode": 2,
"openMode": 2
},
"env": {
"apiUrl": ""
}
}
22 changes: 22 additions & 0 deletions cypress/config/cypress.staging.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"baseUrl": "https://miru-web-staging.herokuapp.com/",
"testFiles": "**/*.spec.js",
"execTimeout": 1800000,
"defaultCommandTimeout": 10000,
"requestTimeout": 30000,
"pageLoadTimeout": 120000,
"responseTimeout": 10000,
"viewportWidth": 1200,
"viewportHeight": 1200,
"videoUploadOnPasses": true,
"screenshotsFolder": "cypress/artifacts/screenshots",
"videosFolder": "cypress/artifacts/videos",
"trashAssetsBeforeRuns": false,
"retries": {
"runMode": 2,
"openMode": 2
},
"env": {
"apiUrl": ""
}
}
17 changes: 14 additions & 3 deletions cypress/plugins/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,18 @@
* @type {Cypress.PluginConfig}
*/
// eslint-disable-next-line no-unused-vars
const fs = require("fs-extra");
const path = require("path");

const getConfigurationByFile = file => {
const pathToConfigFile = `config/cypress.${file}.json`;

return file && fs.readJson(path.join(__dirname, "../", pathToConfigFile));
};

module.exports = (on, config) => {
// `on` is used to hook into various events Cypress emits
// `config` is the resolved Cypress config
}
const environment = config.env.configFile;
const configForEnvironment = getConfigurationByFile(environment);

return configForEnvironment || config;
};
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,11 @@
},
"scripts": {
"prepare": "husky install",
"cypress:open": "cypress open",
"cypress:run": "cypress run"
"cy:open:dev": "cypress open --env configFile=development",
"cy:run:dev": "cypress run --browser chrome --headless --record --env configFile=development",
"cy:run:staging": "cypress run --browser chrome --headless --record --env configFile=staging",
"cy:open:staging": "cypress open --env configFile=staging",
"lint": "eslint ./cypress",
"lint:fix": "eslint --fix ./cypress"
}
}

0 comments on commit 1761c7f

Please sign in to comment.