Skip to content

Commit 7bccc88

Browse files
committed
add ignoring of test files while generating unit tests and add logs
1 parent e6c6b3e commit 7bccc88

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "pythagora",
3-
"version": "0.0.69",
3+
"version": "0.0.70",
44
"author": {
55
"name": "Zvonimir Sabljic",
66
"email": "[email protected]"

src/helpers/unitTests.js

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const _ = require('lodash');
44
const { getUnitTests, checkForAPIKey} = require('./api');
55
const {PYTHAGORA_UNIT_DIR} = require("../const/common");
66
const generator = require("@babel/generator").default;
7-
const {delay, checkDirectoryExists} = require("../utils/common");
7+
const {checkDirectoryExists} = require("../utils/common");
88
const {
99
stripUnrelatedFunctions,
1010
replaceRequirePaths,
@@ -18,18 +18,18 @@ const {initScreenForUnitTests} = require("./cmdGUI");
1818
const {green, red, blue, bold, reset} = require('../utils/cmdPrint').colors;
1919

2020
let 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

Comments
 (0)