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

216
Vistas
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 Respuestas
Responde la pregunta

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