Skip to content

Commit 34bf8b1

Browse files
Fix calls of sortFolderTree and rootPath variable
1 parent addf9fc commit 34bf8b1

File tree

2 files changed

+22
-15
lines changed

2 files changed

+22
-15
lines changed

src/helpers/unitTests.js

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ async function createTests(filePath, funcToTest, processingFunction = 'getUnitTe
186186
))
187187
);
188188

189-
sortFolderTree();
189+
sortFolderTree(folderStructureTree);
190190

191191
for (const [i, funcData] of uniqueFoundFunctions.entries()) {
192192
let indexToPush = fileIndex + 1 + i;
@@ -328,9 +328,9 @@ function updateFolderTree(absolutePath) {
328328
}
329329
}
330330

331-
function sortFolderTree() {
331+
function sortFolderTree(tree) {
332332
// 1. Sort the folderStructureTree
333-
folderStructureTree.sort((a, b) => {
333+
tree.sort((a, b) => {
334334
if (a.absolutePath < b.absolutePath) {
335335
return -1;
336336
}
@@ -341,25 +341,28 @@ function sortFolderTree() {
341341
});
342342

343343
// 2. Set prefix according to the position in the directory
344-
for (let i = 0; i < folderStructureTree.length; i++) {
344+
for (let i = 0; i < tree.length; i++) {
345345
// Get the current directory path
346-
const currentDirPath = path.dirname(folderStructureTree[i].absolutePath);
346+
const currentDirPath = path.dirname(tree[i].absolutePath);
347347
// Check if it's the last file in the directory
348-
if (i === folderStructureTree.length - 1 || path.dirname(folderStructureTree[i + 1].absolutePath) !== currentDirPath) {
348+
if (i === tree.length - 1 || path.dirname(tree[i + 1].absolutePath) !== currentDirPath) {
349349
// Update the prefix for the last file in the directory
350-
folderStructureTree[i].line = folderStructureTree[i].line.replace("├───", "└───");
350+
tree[i].line = tree[i].line.replace("├───", "└───");
351351
}
352352
}
353353
}
354354

355-
async function getFunctionsForExport(dirPath, ignoreFilesRewrite) {
355+
async function getFunctionsForExport(path, pythagoraRoot, ignoreFilesRewrite) {
356356
if (ignoreFilesRewrite) {
357357
isFileToIgnore = ignoreFilesRewrite;
358358
}
359-
rootPath = dirPath;
360-
await traverseDirectory(rootPath, true);
359+
queriedPath = path;
360+
rootPath = pythagoraRoot;
361+
362+
await traverseDirectory(queriedPath, true);
363+
processedFiles = [];
364+
await traverseDirectory(queriedPath, true);
361365
processedFiles = [];
362-
await traverseDirectory(rootPath, true);
363366
return {functionList, folderStructureTree};
364367
}
365368

@@ -400,5 +403,6 @@ async function generateTestsForDirectory(args, processingFunction = 'getUnitTest
400403

401404
module.exports = {
402405
getFunctionsForExport,
403-
generateTestsForDirectory
406+
generateTestsForDirectory,
407+
sortFolderTree
404408
}

src/helpers/unitTestsExpand.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const {
1313
getModuleTypeFromFilePath,
1414
replaceRequirePaths
1515
} = require("../utils/code");
16-
const { getFunctionsForExport } = require("./unitTests");
16+
const { getFunctionsForExport, sortFolderTree } = require("./unitTests");
1717
const { checkPathType, getRelativePath, getTestFolderPath } = require("../utils/files");
1818
const { initScreenForUnitTests } = require("./cmdGUI");
1919
const { green, red, blue, bold, reset } = require("../utils/cmdPrint").colors;
@@ -98,6 +98,8 @@ async function createAdditionalTests(filePath, prefix) {
9898
testPath.substring(0, testPath.lastIndexOf("/"))
9999
);
100100

101+
sortFolderTree(folderStructureTree);
102+
101103
const relatedTestCode = getRelatedTestImports(ast, filePath, functionList);
102104
const formattedData = reformatDataForPythagoraAPI(
103105
filePath,
@@ -195,11 +197,12 @@ async function expandTestsForDirectory(args) {
195197

196198
checkForAPIKey();
197199
queriedPath = path.resolve(pathToProcess);
198-
rootPath = process.cwd();
200+
rootPath = args.pythagora_root;
199201
console.log("Processing folder structure...");
200202

201203
const exportData = await getFunctionsForExport(
202-
pathToProcess || rootPath,
204+
queriedPath,
205+
rootPath,
203206
(fileName) => {
204207
return !filesEndingWith.some((ending) => fileName.endsWith(ending));
205208
}

0 commit comments

Comments
 (0)