@@ -4,7 +4,7 @@ const _ = require('lodash');
44const { getUnitTests, checkForAPIKey} = require ( './api' ) ;
55const { PYTHAGORA_UNIT_DIR } = require ( "../const/common" ) ;
66const generator = require ( "@babel/generator" ) . default ;
7- const { delay , checkDirectoryExists} = require ( "../utils/common" ) ;
7+ const { checkDirectoryExists} = require ( "../utils/common" ) ;
88const {
99 stripUnrelatedFunctions,
1010 replaceRequirePaths,
@@ -18,18 +18,18 @@ const {initScreenForUnitTests} = require("./cmdGUI");
1818const { green, red, blue, bold, reset} = require ( '../utils/cmdPrint' ) . colors ;
1919
2020let functionList = { } ,
21- leftPanel ,
22- rightPanel ,
2321 screen ,
2422 scrollableContent ,
2523 spinner ,
2624 rootPath = '' ,
2725 queriedPath = '' ,
2826 folderStructureTree = [ ] ,
2927 testsGenerated = [ ] ,
28+ skippedFiles = [ ] ,
3029 errors = [ ] ,
31- ignoreFolders = [ 'node_modules' , 'pythagora_tests' ] ,
32- processExtensions = [ '.js' , '.ts' ] ,
30+ ignoreFolders = [ 'node_modules' , 'pythagora_tests' , '__tests__' ] ,
31+ ignoreFilesEndingWith = [ ".test.js" , ".test.ts" , ".test.tsx" ] ,
32+ processExtensions = [ '.js' , '.ts' , '.tsx' ] ,
3333 ignoreErrors = [ 'BABEL_PARSER_SYNTAX_ERROR' ] ,
3434 force
3535;
@@ -164,8 +164,9 @@ async function createTests(filePath, prefix, funcToTest) {
164164 ) ;
165165 spinner . start ( folderStructureTree , indexToPush ) ;
166166
167- let testFilePath = path . join ( getTestFolderPath ( filePath , rootPath ) , `/${ funcData . functionName } .test.js ` ) ;
167+ let testFilePath = path . join ( getTestFolderPath ( filePath , rootPath ) , `/${ funcData . functionName } .test${ extension } ` ) ;
168168 if ( fs . existsSync ( testFilePath ) && ! force ) {
169+ skippedFiles . push ( testFilePath ) ;
169170 await spinner . stop ( ) ;
170171 folderStructureTree [ indexToPush ] . line = `${ green } ${ folderStructureTree [ indexToPush ] . line } ${ reset } ` ;
171172 continue ;
@@ -227,11 +228,14 @@ async function traverseDirectory(directory, onlyCollectFunctionData, prefix = ''
227228 const absolutePath = path . join ( directory , file ) ;
228229 const stat = fs . statSync ( absolutePath ) ;
229230 const isLast = files . indexOf ( file ) === files . length - 1 ;
231+
232+ if ( ignoreFilesEndingWith . some ( ending => file . endsWith ( ending ) ) ) continue ;
233+
230234 if ( stat . isDirectory ( ) ) {
231- if ( ignoreFolders . includes ( path . basename ( absolutePath ) ) || path . basename ( absolutePath ) . charAt ( 0 ) === '.' ) continue ;
235+ if ( ignoreFolders . includes ( path . basename ( absolutePath ) ) || path . basename ( absolutePath ) . charAt ( 0 ) === '.' ) continue ;
232236
233237 if ( onlyCollectFunctionData && isPathInside ( path . dirname ( queriedPath ) , absolutePath ) ) {
234- updateFolderTree ( prefix , isLast , absolutePath )
238+ updateFolderTree ( prefix , isLast , absolutePath ) ;
235239 }
236240
237241 const newPrefix = isLast ? `${ prefix } ` : `${ prefix } | ` ;
@@ -286,6 +290,7 @@ async function generateTestsForDirectory(args) {
286290 console . error ( 'There were errors encountered while trying to generate unit tests.\n' ) ;
287291 console . error ( `You can find logs here: ${ errLogPath } ` ) ;
288292 }
293+ if ( skippedFiles . length ) console . log ( `${ bold } ${ skippedFiles . length } files were skipped because tests already exist. If you want to override them add "--force" flag to command${ reset } ` ) ;
289294 if ( testsGenerated . length === 0 ) {
290295 console . log ( `${ bold + red } No tests generated!${ reset } ` ) ;
291296 } else {
0 commit comments