Skip to content

Commit

Permalink
Replace require/import paths with new ones and small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
pavel-pythagora committed Jul 5, 2023
1 parent 1f3ddbe commit 6927542
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
16 changes: 10 additions & 6 deletions src/helpers/unitTestsExpand.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const { expandUnitTests, checkForAPIKey} = require('./api');
const {PYTHAGORA_UNIT_DIR} = require("../const/common");
const {checkDirectoryExists} = require("../utils/common");
const {
replaceRequirePaths,
getAstFromFilePath,
getRelatedTestImports,
getSourceCodeFromAst,
Expand Down Expand Up @@ -80,16 +81,19 @@ async function createAdditionalTests(filePath, prefix) {
const ast = await getAstFromFilePath(filePath);
let syntaxType = await getModuleTypeFromFilePath(ast);

const importRegex = /^(.*import.*|.*require.*)$/gm;
let testCode = getSourceCodeFromAst(ast);
testCode = testCode.replace(importRegex, '');

const relatedTestCode = getRelatedTestImports(ast, filePath, functionList);
const testPath = path.join(
path.resolve(PYTHAGORA_UNIT_DIR),
filePath.replace(rootPath, '')
);

let testCode = getSourceCodeFromAst(ast);
testCode = replaceRequirePaths(
testCode,
filePath,
testPath.substring(0, testPath.lastIndexOf('/'))
);

const relatedTestCode = getRelatedTestImports(ast, filePath, functionList);
const formattedData = reformatDataForPythagoraAPI(filePath, testCode, relatedTestCode, syntaxType)
const fileIndex = folderStructureTree.findIndex(item => item.absolutePath === filePath);
spinner.start(folderStructureTree, fileIndex);
Expand Down Expand Up @@ -153,7 +157,7 @@ async function traverseDirectoryTests(directory, prefix = '') {
}

async function expandTestsForDirectory(args) {
let pathToProcess = args.expand_path;
let pathToProcess = args.path;
force = args.force;

checkForAPIKey();
Expand Down
2 changes: 1 addition & 1 deletion src/scripts/unitExpand.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ const {expandTestsForDirectory} = require("../helpers/unitTestsExpand.js");
let args = require('../utils/getArgs.js');
const {setUpPythagoraDirs} = require("../helpers/starting.js");

if (!args.expand_path) args.expand_path = process.cwd();
if (!args.path) args.path = process.cwd();
setUpPythagoraDirs();
expandTestsForDirectory(args);
4 changes: 2 additions & 2 deletions src/utils/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ function getRelativePath(filePath, referenceFolderPath) {


function getFolderTreeItem(prefix, isLast, name, absolutePath) {
const stat = fsSync.statSync(absolutePath);
const isDirectory = absolutePath.includes(':') ? false : fsSync.statSync(absolutePath).isDirectory();
return {
line: `${prefix}${isLast ? '└───' : '├───'}${name}`,
absolutePath,
isDirectory: stat.isDirectory()
isDirectory
};
}

Expand Down

0 comments on commit 6927542

Please sign in to comment.