Giter Club home page Giter Club logo

Comments (4)

dwightjack avatar dwightjack commented on September 5, 2024

@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.

mncharlton avatar mncharlton commented on September 5, 2024

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.

antonyfuentes avatar antonyfuentes commented on September 5, 2024

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.

conclavia avatar conclavia commented on September 5, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.