Skip to content

Commit cd874e9

Browse files
author
Zvonimir Sabljic
committed
Fix for showing correct folder structure tree
1 parent 0fab512 commit cd874e9

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/helpers/unitTests.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,8 @@ async function saveTests(filePath, name, testData) {
176176
async function traverseDirectory(directory, onlyCollectFunctionData, prefix = '', funcName) {
177177
if (await checkPathType(directory) === 'file' && !onlyCollectFunctionData) {
178178
if (path.extname(directory) !== '.js') throw new Error('File is not a javascript file');
179-
return await createTests(directory, prefix, funcName);
179+
const newPrefix = `| ${prefix}| `;
180+
return await createTests(directory, newPrefix, funcName);
180181
}
181182
const files = await fs.readdir(directory);
182183
for (const file of files) {
@@ -187,7 +188,7 @@ async function traverseDirectory(directory, onlyCollectFunctionData, prefix = ''
187188
if (ignoreFolders.includes(path.basename(absolutePath)) || path.basename(absolutePath).charAt(0) === '.') continue;
188189

189190
if (onlyCollectFunctionData && isPathInside(path.dirname(queriedPath), absolutePath)) {
190-
folderStructureTree.push(getFolderTreeItem(prefix, isLast, path.basename(absolutePath), absolutePath));
191+
updateFolderTree(prefix, isLast, absolutePath)
191192
}
192193

193194
const newPrefix = isLast ? `${prefix} ` : `${prefix}| `;
@@ -196,7 +197,7 @@ async function traverseDirectory(directory, onlyCollectFunctionData, prefix = ''
196197
if (path.extname(absolutePath) !== '.js') continue;
197198
if (onlyCollectFunctionData) {
198199
if (isPathInside(path.dirname(queriedPath), absolutePath)) {
199-
folderStructureTree.push(getFolderTreeItem(prefix, isLast, path.basename(absolutePath), absolutePath));
200+
updateFolderTree(prefix, isLast, absolutePath);
200201
}
201202
await processFile(absolutePath);
202203
} else {
@@ -207,6 +208,12 @@ async function traverseDirectory(directory, onlyCollectFunctionData, prefix = ''
207208
}
208209
}
209210

211+
function updateFolderTree(prefix, isLast, absolutePath) {
212+
if (!folderStructureTree.find(fst => fst.absolutePath === absolutePath)) {
213+
folderStructureTree.push(getFolderTreeItem(prefix, isLast, path.basename(absolutePath), absolutePath));
214+
}
215+
}
216+
210217
async function getFunctionsForExport(dirPath) {
211218
rootPath = dirPath;
212219
await traverseDirectory(rootPath, true);

0 commit comments

Comments
 (0)