From 79cee4a7523325249d3f91aa46883ccd4418ee1b Mon Sep 17 00:00:00 2001 From: OZGCloud <ozgcloud@mgm-tp.com> Date: Thu, 16 May 2024 11:43:22 +0200 Subject: [PATCH] change countFiles method to also use fs-Extra --- .../apps/alfa-e2e/src/support/cypress-tasks.ts | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/alfa-client/apps/alfa-e2e/src/support/cypress-tasks.ts b/alfa-client/apps/alfa-e2e/src/support/cypress-tasks.ts index 027feaad95..83a9479778 100644 --- a/alfa-client/apps/alfa-e2e/src/support/cypress-tasks.ts +++ b/alfa-client/apps/alfa-e2e/src/support/cypress-tasks.ts @@ -1,5 +1,4 @@ import { Db, Long, MongoClient, ObjectId } from 'mongodb'; -const fs = require('fs'); const fsExtra = require('fs-extra'); const Binary = require('mongodb').Binary; @@ -317,16 +316,13 @@ function dropCollections(databaseUrl, databaseName, collections) { }); } -function countFiles(folderName: string): Promise<number> { - return new Promise((resolve, reject) => { - fs.readdir(folderName, (err, files) => { - if (err) { - console.error(err); - return reject(err); - } - resolve(files.length); +function countFiles(folderName) { + return fsExtra + .readdir(folderName) + .then((files) => files.length) + .catch((err) => { + throw new Error(`Counting files failed: ${err.message}`); }); - }); } function deleteFolder(folderName: string): void { -- GitLab