@@ -4,7 +4,7 @@ const _ = require('lodash');
4
4
const { getUnitTests, checkForAPIKey} = require ( './api' ) ;
5
5
const { PYTHAGORA_UNIT_DIR } = require ( "../const/common" ) ;
6
6
const generator = require ( "@babel/generator" ) . default ;
7
- const { delay , checkDirectoryExists} = require ( "../utils/common" ) ;
7
+ const { checkDirectoryExists} = require ( "../utils/common" ) ;
8
8
const {
9
9
stripUnrelatedFunctions,
10
10
replaceRequirePaths,
@@ -18,18 +18,18 @@ const {initScreenForUnitTests} = require("./cmdGUI");
18
18
const { green, red, blue, bold, reset} = require ( '../utils/cmdPrint' ) . colors ;
19
19
20
20
let functionList = { } ,
21
- leftPanel ,
22
- rightPanel ,
23
21
screen ,
24
22
scrollableContent ,
25
23
spinner ,
26
24
rootPath = '' ,
27
25
queriedPath = '' ,
28
26
folderStructureTree = [ ] ,
29
27
testsGenerated = [ ] ,
28
+ skippedFiles = [ ] ,
30
29
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' ] ,
33
33
ignoreErrors = [ 'BABEL_PARSER_SYNTAX_ERROR' ] ,
34
34
force
35
35
;
@@ -164,8 +164,9 @@ async function createTests(filePath, prefix, funcToTest) {
164
164
) ;
165
165
spinner . start ( folderStructureTree , indexToPush ) ;
166
166
167
- let testFilePath = path . join ( getTestFolderPath ( filePath , rootPath ) , `/${ funcData . functionName } .test.js ` ) ;
167
+ let testFilePath = path . join ( getTestFolderPath ( filePath , rootPath ) , `/${ funcData . functionName } .test${ extension } ` ) ;
168
168
if ( fs . existsSync ( testFilePath ) && ! force ) {
169
+ skippedFiles . push ( testFilePath ) ;
169
170
await spinner . stop ( ) ;
170
171
folderStructureTree [ indexToPush ] . line = `${ green } ${ folderStructureTree [ indexToPush ] . line } ${ reset } ` ;
171
172
continue ;
@@ -227,11 +228,14 @@ async function traverseDirectory(directory, onlyCollectFunctionData, prefix = ''
227
228
const absolutePath = path . join ( directory , file ) ;
228
229
const stat = fs . statSync ( absolutePath ) ;
229
230
const isLast = files . indexOf ( file ) === files . length - 1 ;
231
+
232
+ if ( ignoreFilesEndingWith . some ( ending => file . endsWith ( ending ) ) ) continue ;
233
+
230
234
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 ;
232
236
233
237
if ( onlyCollectFunctionData && isPathInside ( path . dirname ( queriedPath ) , absolutePath ) ) {
234
- updateFolderTree ( prefix , isLast , absolutePath )
238
+ updateFolderTree ( prefix , isLast , absolutePath ) ;
235
239
}
236
240
237
241
const newPrefix = isLast ? `${ prefix } ` : `${ prefix } | ` ;
@@ -286,6 +290,7 @@ async function generateTestsForDirectory(args) {
286
290
console . error ( 'There were errors encountered while trying to generate unit tests.\n' ) ;
287
291
console . error ( `You can find logs here: ${ errLogPath } ` ) ;
288
292
}
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 } ` ) ;
289
294
if ( testsGenerated . length === 0 ) {
290
295
console . log ( `${ bold + red } No tests generated!${ reset } ` ) ;
291
296
} else {
0 commit comments