Skip to content

Commit

Permalink
Add ability to run single test via Test.js (#95)
Browse files Browse the repository at this point in the history
  • Loading branch information
ignacio-chiazzo authored Oct 7, 2024
2 parents 357159f + 6326b9e commit 11f02cd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ The solutions are located under `/LeetcodeProblems`. Each problem has a test fil

### Run Tests

**Unit tests:** To run all the test run `node Test.js` in the console. To run a specific problem in your console run `node <problem_file_path>` (e.g. `node LeetcodeProblems/Lowest_Common_Ancestor_of_a_Binary_Tree.js`).
**Unit tests:** To run all the test run `node Test.js` in the console. To run a specific problem in your console run `node Test.js <problem_file_path>` (e.g. `node Test.js ./LeetcodeProblemsTests/Algorithms/easy/2Sum_Test.js`).

**Linter:** This repository uses [`es-lint`](https://eslint.org/docs/latest/user-guide/command-line-interface). To run all the tests you would need to install the packages by running `npm install` followed by `npx eslint LeetcodeProblems LeetcodeProblemsTests` which will run the eslint in all problems and tests. You can also use the [flag `--fix`](https://eslint.org/docs/latest/user-guide/command-line-interface#fixing-problems) which will automatically fix some of the errors.

Expand Down
10 changes: 8 additions & 2 deletions Test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ var solve = (problem) => {
console.log("Solving: " + problem);

const tests = require(problem);
console.log("*" * 100);
console.log("*".repeat(100));
if (Object.keys(tests).length == 0) {
console.warn("🔴 The problem " + problem + " doesn't have a test method implemented.\n");
return;
Expand Down Expand Up @@ -65,4 +65,10 @@ var loadProblemsFiles = (folder) => {
});
};

test_all();
if (process.argv.length > 2) {
const path = process.argv.pop();
solve(path);
} else {
test_all();
}

0 comments on commit 11f02cd

Please sign in to comment.