Comments (4)
@mncharlton @bahmutov I confirm I encountered the same issue.
@mncharlton One question about your fix: if config
is the resolved config and baseConfig
the configuration JSON file, I'd expect that env variables defined via --env
and included in config.env
would be overwritten by variables already defined in baseConfig.env
. Shouldn't it be the opposite?
An example of the expected behavior:
// base.json
{
"env": {
"myVar": "one"
}
}
// extended.json
{
"extends": "./base.json",
"env": {
"myVar": "two"
}
}
cypress run --config-file extended.json
// myVar === "two"
cypress run --config-file extended.json --env myVar="three"
// myVar === "tree"
from cypress-extends.
if config is the resolved config and baseConfig the configuration JSON file, I'd expect that env variables defined via --env and included in config.env would be overwritten by variables already defined in baseConfig.env. Shouldn't it be the opposite?
I don't know what the correct answer is to be honest 😅
In my 'fix' it works that anything in the resolved config will be overwritten by anything in the baseConfig, and then in turn by anything in the specified config file. This works for my cases, but we don't use the --env
flag anywhere, in a case where you do use that this wouldn't work as you say.
from cypress-extends.
I had issues with this issue as well. In my particular case what was happening is that on my CI/CD settings I had a scheduled job that was passing a custom value for CYPRESS_baseUrl.
However, that value was getting overwritten by the merge plugin, and as well as other environment variables getting lost as mentioned in the comments above.
In the end I resolved it by doing the following:
const path = require('path');
const merge = require('deepmerge');
function extendConfig(config) {
// Parsing the config file to determine if the "extends" key is present
const configFile = require(config.configFile)
if (configFile.extends) {
// If the extends key is present, then parse parse it as an object
const extendedConfig = require(path.join(path.dirname(config.configFile), configFile.extends));
console.log('\nMerging config from %s with %s \n', config.configFile, configFile.extends)
// Merging the current config loaded by Cypress with the extended config
return merge(config, extendedConfig)
} else {
console.log('Could not find any extended config, hence returning the original config parsed by Cypress.');
return config
}
}
module.exports = (on, config) => {
// Extending config file if applicable
return extendConfig(config);
};
from cypress-extends.
If you only need to fix this issue for env
values and not for configuration used by Cypress itself (which was enough for our use case) then you can just merge the original env
back over the result of the plugin:
import cypressExtends from '@bahmutov/cypress-extends';
import merge from 'deepmerge';
...
module.exports = ((on, config) => {
const extended = cypressExtends(config.configFile);
return { ...extended, env: merge(extended.env, config.env) };
}) as Cypress.PluginConfig;
from cypress-extends.
Related Issues (11)
- Dependency Dashboard
- Order of precedence is "broken"
- Cannot extend from packages in node_modules HOT 2
- Variables from custom config files are not visible in test runners Settings > Configuration HOT 8
- Action Required: Fix Renovate Configuration
- Unable to Set pluginsFile Path In Base Json File HOT 1
- Can't override array values HOT 2
- Plugins is broken HOT 1
- Unable to set the projectId in a base config
- Extending configuration file with Cypress 10 HOT 8
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cypress-extends.