From eab1994fb8739807c48995733fa77ce31ffdd527 Mon Sep 17 00:00:00 2001
From: alexm <alexm@verdnatura.es>
Date: Wed, 9 Apr 2025 11:21:00 +0200
Subject: [PATCH] fix(find-imports): remove the specific one if the module is
 there

---
 test/cypress/docker/find/find-imports.js |  2 +-
 test/cypress/docker/find/find.js         | 19 ++++++++++++++++++-
 2 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/test/cypress/docker/find/find-imports.js b/test/cypress/docker/find/find-imports.js
index 39c3ac3eb..622049c9f 100644
--- a/test/cypress/docker/find/find-imports.js
+++ b/test/cypress/docker/find/find-imports.js
@@ -44,7 +44,7 @@ export async function findImports(targetFile, visited = new Set(), identation =
         ];
     }
 
-    return getUniques(fullTree); // Remove duplicates
+    return getUniques([...fullTree, targetFile]); // Remove duplicates
 }
 
 function getUniques(array) {
diff --git a/test/cypress/docker/find/find.js b/test/cypress/docker/find/find.js
index b89aab230..4f8063c86 100644
--- a/test/cypress/docker/find/find.js
+++ b/test/cypress/docker/find/find.js
@@ -25,7 +25,7 @@ async function getChangedModules() {
         if (change.startsWith(E2E_PATH)) changedArray.push(change);
         changedModules = new Set(changedArray);
     }
-    return [...changedModules].join('\n');
+    return cleanSpecs(changedModules).join('\n');
 }
 
 getChangedModules()
@@ -34,3 +34,20 @@ getChangedModules()
         console.error(e);
         process.exit(1);
     });
+
+function cleanSpecs(changedModules) {
+    let specifics = [];
+    const modules = [];
+    for (const changed of changedModules) {
+        if (changed.endsWith('*.spec.js')) {
+            modules.push(changed);
+            continue;
+        }
+        specifics.push(changed);
+    }
+    specifics = specifics.filter(
+        (spec) => !modules.some((module) => spec.startsWith(module.split('**')[0])),
+    );
+
+    return [...modules, ...specifics];
+}