diff --git a/integration/cli/package.json b/integration/cli/package.json new file mode 100644 index 0000000..26678f2 --- /dev/null +++ b/integration/cli/package.json @@ -0,0 +1,11 @@ +{ + "name": "cli-it", + "version": "0.0.1", + "description": "crda-javascript-api cli integration tests", + "private": true, + "type": "module", + "license": "Apache-2.0", + "dependencies": { + "@RHEcosystemAppEng/crda-javascript-api": "file:../../" + } +} diff --git a/integration/expected_stack_json_summary b/integration/expected_stack_json_summary new file mode 100644 index 0000000..14fc8e2 --- /dev/null +++ b/integration/expected_stack_json_summary @@ -0,0 +1,14 @@ +{ + "dependencies": { + "scanned": 1, + "transitive": 0 + }, + "vulnerabilities": { + "total": 7, + "direct": 1, + "critical": 1, + "high": 3, + "medium": 2, + "low": 1 + } +} diff --git a/integration/run_it.sh b/integration/run_it.sh index f5221ad..8b1eba0 100755 --- a/integration/run_it.sh +++ b/integration/run_it.sh @@ -1,5 +1,15 @@ #!/usr/bin/env bash +# utility function takes file name and a command +# used for matching the file content and the command output +match() { + if [[ $(< "$1") != "$(eval "$2")" ]]; then + echo "- FAILED" + exit 1 + fi + echo "- PASSED" +} + ########################################## ###### Verify Required Tools Exists ###### ########################################## @@ -29,20 +39,10 @@ fi echo "- SUCCESSFUL" echo "RUNNING JavaScript integration test for Stack Analysis report in Html" -htmlStackRep=$(node javascript/index.js stack pom.xml true) -if [[ $(< expected_stack_html) != "$htmlStackRep" ]]; then - echo "- FAILED" - exit 1 -fi -echo "- PASSED" +match "expected_stack_html" "node javascript/index.js stack pom.xml true" echo "RUNNING JavaScript integration test for Stack Analysis report in Json" -jsonStackRep=$(node javascript/index.js stack pom.xml false) -if [[ $(< expected_stack_json) != "$jsonStackRep" ]]; then - echo "- FAILED" - exit 1 -fi -echo "- PASSED" +match "expected_stack_json" "node javascript/index.js stack pom.xml false" ########################################## ###### TypeScript Integration Tests ###### @@ -62,17 +62,27 @@ then fi echo "RUNNING TypeScript integration test for Stack Analysis report in Html" -htmlStackRep=$(node typescript/dist/index.js stack pom.xml true) -if [[ $(< expected_stack_html) != "$htmlStackRep" ]]; then - echo "- FAILED" - exit 1 -fi -echo "- PASSED" +match "expected_stack_html" "node typescript/dist/index.js stack pom.xml true" echo "RUNNING TypeScript integration test for Stack Analysis report in Json" -jsonStackRep=$(node typescript/dist/index.js stack pom.xml false) -if [[ $(< expected_stack_json) != "$jsonStackRep" ]]; then - echo "- FAILED" - exit 1 +match "expected_stack_json" "node typescript/dist/index.js stack pom.xml false" + +########################################## +###### CMD Script Integration Tests ###### +########################################## +echo "PREPARING CLI Script integration tests environment" +if ! npm --prefix cli install --force --silent +then + echo "- FAILED Installing modules for JS environment" + exit $? fi -echo "- PASSED" +echo "- SUCCESSFUL" + +echo "RUNNING CLI Script integration test for Stack Analysis report in Html" +match "expected_stack_html" "node cli/node_modules/@RHEcosystemAppEng/crda-javascript-api/dist/src/cli.js stack pom.xml --html" + +echo "RUNNING CLI Script integration test for Stack Analysis report in full Json" +match "expected_stack_json" "node cli/node_modules/@RHEcosystemAppEng/crda-javascript-api/dist/src/cli.js stack pom.xml" + +echo "RUNNING CLI Script integration test for Stack Analysis report in full Json" +match "expected_stack_json_summary" "node cli/node_modules/@RHEcosystemAppEng/crda-javascript-api/dist/src/cli.js stack pom.xml --summary" diff --git a/package.json b/package.json index 615be40..d143671 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,7 @@ "npm": ">= 9.0.0" }, "type": "module", - "bin": "dist/src/cmd.js", + "bin": "dist/src/cli.js", "main": "dist/src/index.js", "module": "dist/src/index.js", "types": "dist/src/index.d.ts", @@ -74,7 +74,7 @@ "src/**" ], "exclude": [ - "src/cmd.js", + "src/cli.js", "src/index.js" ], "lines": 85, diff --git a/src/cmd.js b/src/cli.js similarity index 100% rename from src/cmd.js rename to src/cli.js