@@ -138,6 +138,7 @@ function getRelatedFunctions(node, ast, filePath, functionList) {
138
138
}
139
139
140
140
let requiredPath = requiresFromFile . find ( require => require . includes ( funcName ) ) ;
141
+ const importPath = requiredPath ;
141
142
if ( ! requiredPath ) {
142
143
requiredPath = filePath ;
143
144
} else {
@@ -147,7 +148,8 @@ function getRelatedFunctions(node, ast, filePath, functionList) {
147
148
let functionFromList = functionList [ requiredPath + ':' + funcName ] ;
148
149
if ( functionFromList ) {
149
150
relatedFunctions . push ( _ . extend ( functionFromList , {
150
- fileName : requiredPath
151
+ fileName : requiredPath ,
152
+ importPath
151
153
} ) ) ;
152
154
}
153
155
}
@@ -362,7 +364,7 @@ function collectTestRequires(node) {
362
364
}
363
365
364
366
function getRelatedTestImports ( ast , filePath , functionList ) {
365
- let relatedFunctions = [ ] ;
367
+ let relatedCode = [ ] ;
366
368
let requiresFromFile = collectTestRequires ( ast ) ;
367
369
368
370
for ( let fileImport in requiresFromFile ) {
@@ -372,14 +374,27 @@ function getRelatedTestImports(ast, filePath, functionList) {
372
374
_ . forEach ( requiresFromFile [ fileImport ] . functionNames , ( funcName ) => {
373
375
let functionFromList = functionList [ requiredPath + ':' + funcName ] ;
374
376
if ( functionFromList ) {
375
- relatedFunctions . push ( _ . extend ( functionFromList , {
377
+ relatedCode . push ( _ . extend ( functionFromList , {
376
378
fileName : requiredPath
377
379
} ) ) ;
378
380
}
379
381
} )
380
382
}
381
383
382
- return relatedFunctions ;
384
+ for ( let relCode of relatedCode ) {
385
+ let relatedCodeImports = '' ;
386
+ for ( let func of relCode . relatedFunctions ) {
387
+ if ( func . importPath ) {
388
+ relatedCodeImports += `${ func . importPath } \n` ;
389
+ }
390
+ }
391
+
392
+ if ( relatedCodeImports ) {
393
+ relCode . code = `${ relatedCodeImports } \n${ relCode . code } ` ;
394
+ }
395
+ }
396
+
397
+ return relatedCode ;
383
398
}
384
399
385
400
module . exports = {
0 commit comments