Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

212
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!