From f000291fff8fbec75c945a9bb3bbc0cac4147611 Mon Sep 17 00:00:00 2001
From: OZGCloud <ozgcloud@mgm-tp.com>
Date: Tue, 17 Oct 2023 16:15:57 +0200
Subject: [PATCH] added cypress-tasks

---
 .../goofy-e2e/src/support/cypress-tasks.ts    | 36 ++++++++++++++++++-
 1 file changed, 35 insertions(+), 1 deletion(-)

diff --git a/goofy-client/apps/goofy-e2e/src/support/cypress-tasks.ts b/goofy-client/apps/goofy-e2e/src/support/cypress-tasks.ts
index 6c6806b83b..d92b9e80d3 100644
--- a/goofy-client/apps/goofy-e2e/src/support/cypress-tasks.ts
+++ b/goofy-client/apps/goofy-e2e/src/support/cypress-tasks.ts
@@ -1,3 +1,4 @@
+import { rmdir } from 'fs';
 import { Long, MongoClient, ObjectId } from 'mongodb';
 
 const Binary = require('mongodb').Binary;
@@ -43,7 +44,16 @@ module.exports = (on: any, config: any) => {
 			console.log('dropUserManagerCollections: ', collections);
 			dropUserManagerCollectionsFromDatabase(config, collections);
 			return 0;
-		}
+		},
+		countFiles(folderName:string) {
+			console.log('counting files in folder %s', folderName);
+			return countFiles(folderName);					
+		},
+		deleteFolder(folderName:string) {
+			console.log('deleting folder %s', folderName);
+			deleteFolder(folderName);
+			return 0;
+		},
 	});
 
 	// Workaround für Angular 13 und Cypress mit Webpack 4,
@@ -295,4 +305,28 @@ 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 deleteFolder(folderName:string): void {
+	new Promise((resolve, reject) => {
+		rmdir(folderName, { maxRetries: 10, recursive: true }, (err) => {
+			if (err) {
+				console.error(err)
+				return reject(err)
+			}
+			resolve(null)
+		})
+	})
 }
\ No newline at end of file
-- 
GitLab