Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

156
Vistas
Add env variable in package.json brefore cypress runs in headless mode

I want to find out if cypress runs or doesn't run in the NextJS application. My idea is prevent a some http requests in the NextJS application if the Cypress tests are running.

I am able to catch if cypress is running when I run "npx cypress open" for a browser like this:

if(window.Cypress){
 // prevent http request or do something
}

But I am not able to check if the cypress is running or not in headless mode with "npx cypress run" command.

I tried to add extra env variable in the package.json file like in below:

...
"cy:run": "cross-env CY_MODE=true cypress run",
...

But it doesn't set the CY_MODE env variable when I try to log process.env.CY_MODE.

How can I set a custom environment variable before cypress tests start with headless mode?

Thanks

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

You can set env.variables inside package.json:

  • create parent command where you define env.variable and contain your command for running tests 'parentCommand': 'cross-env CY_MODE=true npx cypress run'
  • launch the command and env variable will be shared between files and applications
about 4 years ago · Juan Pablo Isaza Denunciar

0

From Exposing Environment Variables to the Browser

By default environment variables are only available in the Node.js environment, meaning they won't be exposed to the browser.

In order to expose a variable to the browser you have to prefix the variable with NEXT_PUBLIC_.

"cy:run": "cross-env NEXT_PUBLIC_CY_MODE=true cypress run",

Alternatively, you can control the NextJs server from Cypress plugins - see Mock Network When Using Next.js getServerSideProps Call

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda