Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

154
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda