Skip to content

Commit 6927542

Browse files
Replace require/import paths with new ones and small fixes
1 parent 1f3ddbe commit 6927542

File tree

3 files changed

+13
-9
lines changed

3 files changed

+13
-9
lines changed

src/helpers/unitTestsExpand.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const { expandUnitTests, checkForAPIKey} = require('./api');
55
const {PYTHAGORA_UNIT_DIR} = require("../const/common");
66
const {checkDirectoryExists} = require("../utils/common");
77
const {
8+
replaceRequirePaths,
89
getAstFromFilePath,
910
getRelatedTestImports,
1011
getSourceCodeFromAst,
@@ -80,16 +81,19 @@ async function createAdditionalTests(filePath, prefix) {
8081
const ast = await getAstFromFilePath(filePath);
8182
let syntaxType = await getModuleTypeFromFilePath(ast);
8283

83-
const importRegex = /^(.*import.*|.*require.*)$/gm;
84-
let testCode = getSourceCodeFromAst(ast);
85-
testCode = testCode.replace(importRegex, '');
86-
87-
const relatedTestCode = getRelatedTestImports(ast, filePath, functionList);
8884
const testPath = path.join(
8985
path.resolve(PYTHAGORA_UNIT_DIR),
9086
filePath.replace(rootPath, '')
9187
);
9288

89+
let testCode = getSourceCodeFromAst(ast);
90+
testCode = replaceRequirePaths(
91+
testCode,
92+
filePath,
93+
testPath.substring(0, testPath.lastIndexOf('/'))
94+
);
95+
96+
const relatedTestCode = getRelatedTestImports(ast, filePath, functionList);
9397
const formattedData = reformatDataForPythagoraAPI(filePath, testCode, relatedTestCode, syntaxType)
9498
const fileIndex = folderStructureTree.findIndex(item => item.absolutePath === filePath);
9599
spinner.start(folderStructureTree, fileIndex);
@@ -153,7 +157,7 @@ async function traverseDirectoryTests(directory, prefix = '') {
153157
}
154158

155159
async function expandTestsForDirectory(args) {
156-
let pathToProcess = args.expand_path;
160+
let pathToProcess = args.path;
157161
force = args.force;
158162

159163
checkForAPIKey();

src/scripts/unitExpand.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ const {expandTestsForDirectory} = require("../helpers/unitTestsExpand.js");
22
let args = require('../utils/getArgs.js');
33
const {setUpPythagoraDirs} = require("../helpers/starting.js");
44

5-
if (!args.expand_path) args.expand_path = process.cwd();
5+
if (!args.path) args.path = process.cwd();
66
setUpPythagoraDirs();
77
expandTestsForDirectory(args);

src/utils/files.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ function getRelativePath(filePath, referenceFolderPath) {
1919

2020

2121
function getFolderTreeItem(prefix, isLast, name, absolutePath) {
22-
const stat = fsSync.statSync(absolutePath);
22+
const isDirectory = absolutePath.includes(':') ? false : fsSync.statSync(absolutePath).isDirectory();
2323
return {
2424
line: `${prefix}${isLast ? '└───' : '├───'}${name}`,
2525
absolutePath,
26-
isDirectory: stat.isDirectory()
26+
isDirectory
2727
};
2828
}
2929

0 commit comments

Comments
 (0)