@@ -138,6 +138,7 @@ function getRelatedFunctions(node, ast, filePath, functionList) {
138138 }
139139
140140 let requiredPath = requiresFromFile . find ( require => require . includes ( funcName ) ) ;
141+ const importPath = requiredPath ;
141142 if ( ! requiredPath ) {
142143 requiredPath = filePath ;
143144 } else {
@@ -147,7 +148,8 @@ function getRelatedFunctions(node, ast, filePath, functionList) {
147148 let functionFromList = functionList [ requiredPath + ':' + funcName ] ;
148149 if ( functionFromList ) {
149150 relatedFunctions . push ( _ . extend ( functionFromList , {
150- fileName : requiredPath
151+ fileName : requiredPath ,
152+ importPath
151153 } ) ) ;
152154 }
153155 }
@@ -362,7 +364,7 @@ function collectTestRequires(node) {
362364}
363365
364366function getRelatedTestImports ( ast , filePath , functionList ) {
365- let relatedFunctions = [ ] ;
367+ let relatedCode = [ ] ;
366368 let requiresFromFile = collectTestRequires ( ast ) ;
367369
368370 for ( let fileImport in requiresFromFile ) {
@@ -372,14 +374,27 @@ function getRelatedTestImports(ast, filePath, functionList) {
372374 _ . forEach ( requiresFromFile [ fileImport ] . functionNames , ( funcName ) => {
373375 let functionFromList = functionList [ requiredPath + ':' + funcName ] ;
374376 if ( functionFromList ) {
375- relatedFunctions . push ( _ . extend ( functionFromList , {
377+ relatedCode . push ( _ . extend ( functionFromList , {
376378 fileName : requiredPath
377379 } ) ) ;
378380 }
379381 } )
380382 }
381383
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 ;
383398}
384399
385400module . exports = {
0 commit comments