@@ -5,6 +5,7 @@ const { expandUnitTests, checkForAPIKey} = require('./api');
5
5
const { PYTHAGORA_UNIT_DIR } = require ( "../const/common" ) ;
6
6
const { checkDirectoryExists} = require ( "../utils/common" ) ;
7
7
const {
8
+ replaceRequirePaths,
8
9
getAstFromFilePath,
9
10
getRelatedTestImports,
10
11
getSourceCodeFromAst,
@@ -80,16 +81,19 @@ async function createAdditionalTests(filePath, prefix) {
80
81
const ast = await getAstFromFilePath ( filePath ) ;
81
82
let syntaxType = await getModuleTypeFromFilePath ( ast ) ;
82
83
83
- const importRegex = / ^ ( .* i m p o r t .* | .* r e q u i r e .* ) $ / gm;
84
- let testCode = getSourceCodeFromAst ( ast ) ;
85
- testCode = testCode . replace ( importRegex , '' ) ;
86
-
87
- const relatedTestCode = getRelatedTestImports ( ast , filePath , functionList ) ;
88
84
const testPath = path . join (
89
85
path . resolve ( PYTHAGORA_UNIT_DIR ) ,
90
86
filePath . replace ( rootPath , '' )
91
87
) ;
92
88
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 ) ;
93
97
const formattedData = reformatDataForPythagoraAPI ( filePath , testCode , relatedTestCode , syntaxType )
94
98
const fileIndex = folderStructureTree . findIndex ( item => item . absolutePath === filePath ) ;
95
99
spinner . start ( folderStructureTree , fileIndex ) ;
@@ -153,7 +157,7 @@ async function traverseDirectoryTests(directory, prefix = '') {
153
157
}
154
158
155
159
async function expandTestsForDirectory ( args ) {
156
- let pathToProcess = args . expand_path ;
160
+ let pathToProcess = args . path ;
157
161
force = args . force ;
158
162
159
163
checkForAPIKey ( ) ;
0 commit comments