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

169
Views
Testcase to check if multiple files of specific pattern are present

Want to validate if multiple files with filenames in a specific pattern are created by a function. The test case I have written is

describe('Sitemap', () => {
       it('it should create XML sitemap', () => {
              let language='hindi'
              return sitemapContainer.createSitemap(language).then(() => {
                   expect(fs.existsSync(`sos/sos_${language}*.xml`)).to.be.true
              });       
        })
})

but it fails. Which function should I use in place of fs.existsSync so that pattern could be matched . Some example files are sos_hindi_1.xml , sos_hindi_2.xml , sos_hindi_3.xml .

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

existsSync looks for a single file, but you can think out of the box and come with a different approach.

You can instead read the entire folder so that you have a list of files, and then do your manipulations.

expect(fs.readdirSync('sos/').some(file => /* your condition */)).to.be.true

If at least one file matches your condition, it will return true

Possible solution

With a regex, you can do something like that

let lan = "hindi";
var reg = new RegExp(`sos_${lan}_\\S\.xml`, 'g');
expect(fs.readdirSync('sos/').some(file => file.match(reg))).to.be.true
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!