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

220
Visualizações
Is there a better way to call a .env file exists check function in cypress?

I would like to check if there is a .env file exists in the root folder before running the test. I have added below function in the index.js but it is not checking if the file exists. Could someone please advise the issue here ?

cypress/ plugins/ index.js

const  filePath = "../../../.env";

module.exports = (on, config) => {
  on('file:preprocessor', cucumber()),
      on('before:browser:launch', (browser, launchOptions) => {
        console.log("Print browser name: "+browser.name);
        fileCheck(filePath);  // calling the function here
    
      });
};


function fileCheck(filePath) => {
        try {
            if (fs.existsSync(filePath)) {
                console.log("Awesome ! .env file exists in the root directory ! ");
            }
        } catch(err) {
            console.error(err)
            console.log("Oh !, .env file is missing, please add !");
        }
    }
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Maybe it's enough to check it in a before action, then you can do:

before(() => {
cy.on('fail', (error) => {
  error.message = 'Oh !, .env file is missing, please add !';
  throw error;
})
cy.readFile('.env', {timeout: 50}).should('exist');

});

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