Skip to content

Commit 8a01d0a

Browse files
Merge branch 'feat/expand-unit-tests' of https://github.com/Pythagora-io/pythagora into feat/expand-unit-tests
2 parents aa209e7 + 399b31e commit 8a01d0a

File tree

4 files changed

+25
-5
lines changed

4 files changed

+25
-5
lines changed

README.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,15 @@ npx pythagora --unit-tests --func <FUNCTION_NAME>
2626

2727
Where `<FUNCTION_NAME>` is the name of the function you want to generate unit tests for. Just make sure that your function is exported from a file. You can see other options like generating tests for multiple files or folders [below in the Options section](#-options).
2828

29-
<br>
29+
<br><br>
30+
If you wish to expand your current test suite with more tests to get better code coverage you can run:
31+
32+
```bash
33+
npx pythagora --expand-unit-tests --path <PATH_TO_YOUR_TEST_SUITE>
34+
```
35+
for more details on expanding existing tests see [below in the Expanding existing tests section](#-expand-existing-tests).
36+
37+
<br><br>
3038

3139
**NOTE:** on Windows make sure to run all commands using `Git Bash` and not `Power Shell` or anything similiar
3240

@@ -77,6 +85,16 @@ When Pythagora generates unit tests, it uses the following approach:
7785

7886
<br>
7987

88+
# 📈 Expand existing tests
89+
If you already have generated tests for your codebase but you just want to increase your code coverage or cover more edge cases, simply run:
90+
91+
```bash
92+
npx pythagora --expand-unit-tests --path <PATH_TO_YOUR_TEST_SUITE>
93+
```
94+
When running command `PATH_TO_YOUR_TEST_SUITE` can be path to a single test file or to a folder and all test files inside of that folder will be processed and expanded.
95+
96+
That's all, enjoy your new code coverage!
97+
8098
# 📖 Options
8199
- To generate unit tests for **one single function**, run:
82100

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.76",
3+
"version": "0.0.78",
44
"author": {
55
"name": "Zvonimir Sabljic",
66
"email": "[email protected]"

src/bin/run.bash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ do
6060
exit 0
6161
elif [[ "${args[$i]}" == "--unit-tests" ]]
6262
then
63-
echo "${green}${bold}Generating unit tests...${reset}"
63+
echo "${green}${bold}Starting generation of unit tests...${reset}"
6464
PYTHAGORA_CONFIG="$@" node "${pythagora_dir}/src/scripts/unit.js"
6565
exit 0
6666

src/helpers/unitTests.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ async function processFile(filePath, filesToProcess) {
6969
if (importedFile && !filesToProcess.includes(importedFile)) {
7070
filesToProcess.push(importedFile);
7171
}
72-
} else if (node.type === "VariableDeclaration" && node.declarations[0].init.type === "CallExpression" && node.declarations[0].init.callee.name === "require") {
72+
} else if (node.type === "VariableDeclaration" && node.declarations.length > 0 && node.declarations[0].init && node.declarations[0].init.type === "CallExpression" && node.declarations[0].init.callee.name === "require") {
7373
let importedFile = path.resolve(path.dirname(filePath), node.declarations[0].init.arguments[0].value);
7474
importedFile = resolveFilePath(importedFile, extension);
7575
if (importedFile && !filesToProcess.includes(importedFile)) {
@@ -374,12 +374,14 @@ async function generateTestsForDirectory(args, processingFunction = 'getUnitTest
374374
API.checkForAPIKey();
375375
queriedPath = path.resolve(pathToProcess);
376376
rootPath = args.pythagora_root;
377-
({ screen, spinner, scrollableContent } = initScreenForUnitTests());
377+
console.log('Processing folder structure...');
378378

379379
await traverseDirectory(queriedPath, true, funcName, processingFunction);
380380
processedFiles = [];
381381
await traverseDirectory(queriedPath, true, funcName, processingFunction);
382382
processedFiles = [];
383+
console.log('Generating tests...');
384+
({ screen, spinner, scrollableContent } = initScreenForUnitTests());
383385
await traverseDirectory(queriedPath, false, funcName, processingFunction);
384386

385387
screen.destroy();

0 commit comments

Comments
 (0)