Hello, What are the best way to make different env...
# best-practices
e
Hello, What are the best way to make different environments , Dev and Release on Cypress 10, I am checking a few articles in google any suggestions for a good example so i could do it on my own.
s
e
Hi
So baisclly i will create two config files for example like this : the one i have defualt cypress.config.js and the other one cypress-rel.config.js
right ?
s
Yes, for example I have: * default config file at root:
cypress.config.ts
* then inside a new folder I have other config files:
/cypress/configs/cypress.mobile.config.ts
Then you can use a very helpful package like
defu
to handle inheritance inside the new config, to avoid key / value duplication. i.e.
Copy code
import { defineConfig } from 'cypress';
import defu from 'defu';

import defaultConfig from '../../cypress.config';

export default defineConfig(
  defu(
    {
      viewportWidth: 375,
      viewportHeight: 812,
      userAgent: 'Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) Mobile/15E148',
      env: {
        device: 'mobile',
      },
    },
    defaultConfig
  )
);
And finally here's the run command that specifies the new config file to use:
Copy code
cypress run --browser chrome --config-file cypress/configs/cypress.mobile.config.ts
e
alright seems good, i will see to install this Defu first and then try your version
s
Obviously just replace my
mobile
values example with your
environment
required values.
e
yea yea, for sure
thanks 🙂 take care enjoy your day
6 Views