Skip to content

Add ability to run single test via Test.js #95

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 1 commit into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
}