Skip to content

Commit 264f85f

Browse files
authored
chore: refactor integration test structure and update contributing guidelines (#15)
Signed-off-by: Tomer Figenblat <[email protected]>
1 parent 2d48bde commit 264f85f

File tree

13 files changed

+54
-27
lines changed

13 files changed

+54
-27
lines changed

CONTRIBUTING.md

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,35 @@ and the [tsconfig.json](tsconfig.json) configuration file. Also note the _TypeSc
6262
Use [java_maven.js](src/providers/java_maven.js) as an example to get you started.
6363
* Import the new _Provider_ and list in the in _availableProviders_ array in [provider.js](src/provider.js).
6464
* Update the _choices_ configuration for the _manifest-name_ positional argument in [cli.js](src/cli.js).
65-
* Add Integration Test scenarios for the added provider in [integration/langs](integration/langs).
66-
Use the [java scenarios](integration/langs/java) as an example.
65+
* Add Integration Test scenarios for the added provider in [integration/scenarios](integration/scenarios).
66+
Use the [java scenarios](integration/scenarios/java) as an example.
6767
* Update the documentation. This document and [README.md](README.md).
6868

6969
### Integration Tests
7070

71-
WIP
71+
Integration tests are performed with a _bash_ script executing _node_ scripts.<br/>
72+
In [integration/run_its.sh](integration/run_its.sh) we start with a function called _match_ taking 2 arguments:
73+
* `$1` is a file name for the holding the expected result (scenarios)
74+
* `$2` is a command execution for evaluation (testers)
75+
76+
The _match_ function will match the content of the file to the output of the command.
77+
Typically, test cases in [integration/run_its.sh](integration/run_its.sh) will invoke the _match_ function with
78+
a scenario from the [integration/scenarios](integration/scenarios) and a _node_ command invoking one of the _node_
79+
scripts in [integration/testers](integration/testers).<br/>
80+
81+
We have 3 _testers_:
82+
* [integration/testers/cli](integration/testers/cli) is a _package.json_ used for installing the _ESM module_.
83+
Invoking the CLI Script is done against the _@RHEcosystemAppEng/crda-javascript-api/dist/src/cli.js_ in the tester's _node_modules_.
84+
* [integration/testers/javascript](integration/testers/javascript) is a _javascript_ script invoking the _ESM module_.
85+
* [integration/testers/typescript](integration/testers/typescript) is a _typescript_ script invoking the _ESM module_.
86+
87+
Run integration tests from the project's root:
88+
89+
> Don't forget to run `npm run compile` before running the integration tests.
90+
91+
```shell
92+
(cd integration/ && bash ./run_its.sh)
93+
```
7294

7395
> We currently run integration tests against the actual production _Backend_, this will be replaced by opting for a _Mock Server_.
7496

integration/run_its.sh

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,9 @@ echo "- SUCCESSFUL"
4747
###### JavaScript Integration Tests ######
4848
##########################################
4949
echo "PREPARING JavaScript integration tests environment"
50-
rm -rf javascript/node_modules
51-
if ! npm --prefix javascript install --silent
50+
rm -rf testers/javascript/node_modules
51+
rm -f testers/javascript/package-lock.json
52+
if ! npm --prefix ./testers/javascript install --silent
5253
then
5354
echo "- FAILED Installing modules for JS environment"
5455
exit $?
@@ -57,49 +58,51 @@ echo "- SUCCESSFUL"
5758

5859
#### JAVA MAVEN
5960
echo "RUNNING JavaScript integration test for Stack Analysis report in Html for Java Maven"
60-
match "langs/java/expected_stack_html" "node javascript/index.js stack langs/java/pom.xml true"
61+
match "scenarios/java/expected_stack_html" "node testers/javascript/index.js stack scenarios/java/pom.xml true"
6162

6263
echo "RUNNING JavaScript integration test for Stack Analysis report in Json for Java Maven"
63-
match "langs/java/expected_stack_json" "node javascript/index.js stack langs/java/pom.xml false"
64+
match "scenarios/java/expected_stack_json" "node testers/javascript/index.js stack scenarios/java/pom.xml false"
6465

6566
echo "RUNNING JavaScript integration test for Component Analysis report for Java Maven"
66-
match "langs/java/expected_component" "node javascript/index.js component pom.xml '$(<langs/java/pom.xml)'"
67+
match "scenarios/java/expected_component" "node testers/javascript/index.js component pom.xml '$(<scenarios/java/pom.xml)'"
6768

6869
##########################################
6970
###### TypeScript Integration Tests ######
7071
##########################################
7172
echo "PREPARING TypeScript integration tests environment"
72-
rm -rf typescript/node_modules
73-
if ! npm --prefix typescript install --silent
73+
rm -rf testers/typescript/node_modules
74+
rm -f testers/typescript/package-lock.json
75+
if ! npm --prefix ./testers/typescript install --silent
7476
then
7577
echo "- FAILED Installing modules for TS environment"
7678
exit $?
7779
fi
7880
echo "- SUCCESSFUL"
7981

80-
rm -rf typescript/dist
81-
if ! npm --prefix typescript run compile > /dev/null 2>&1
82+
rm -rf testers/typescript/dist
83+
if ! npm --prefix ./testers/typescript run compile > /dev/null 2>&1
8284
then
8385
echo "- FAILED Compiling TS module"
8486
exit $?
8587
fi
8688

8789
#### JAVA MAVEN
8890
echo "RUNNING TypeScript integration test for Stack Analysis report in Html for Java Maven"
89-
match "langs/java/expected_stack_html" "node typescript/dist/index.js stack langs/java/pom.xml true"
91+
match "scenarios/java/expected_stack_html" "node testers/typescript/dist/index.js stack scenarios/java/pom.xml true"
9092

9193
echo "RUNNING TypeScript integration test for Stack Analysis report in Json for Java Maven"
92-
match "langs/java/expected_stack_json" "node typescript/dist/index.js stack langs/java/pom.xml false"
94+
match "scenarios/java/expected_stack_json" "node testers/typescript/dist/index.js stack scenarios/java/pom.xml false"
9395

9496
echo "RUNNING TypeScript integration test for Component Analysis report for Java Maven"
95-
match "langs/java/expected_component" "node typescript/dist/index.js component pom.xml '$(<langs/java/pom.xml)'"
97+
match "scenarios/java/expected_component" "node testers/typescript/dist/index.js component pom.xml '$(<scenarios/java/pom.xml)'"
9698

9799
##########################################
98100
###### CMD Script Integration Tests ######
99101
##########################################
100102
echo "PREPARING CLI Script integration tests environment"
101-
rm -rf cli/node_modules
102-
if ! npm --prefix cli install --silent
103+
rm -rf testers/cli/node_modules
104+
rm -f testers/cli/package-lock.json
105+
if ! npm --prefix ./testers/cli install --silent
103106
then
104107
echo "- FAILED Installing modules for JS environment"
105108
exit $?
@@ -108,13 +111,13 @@ echo "- SUCCESSFUL"
108111

109112
#### JAVA MAVEN
110113
echo "RUNNING CLI Script integration test for Stack Analysis report in Html for Java Maven"
111-
match "langs/java/expected_stack_html" "node cli/node_modules/@RHEcosystemAppEng/crda-javascript-api/dist/src/cli.js stack langs/java/pom.xml --html"
114+
match "scenarios/java/expected_stack_html" "node testers/cli/node_modules/@RHEcosystemAppEng/crda-javascript-api/dist/src/cli.js stack scenarios/java/pom.xml --html"
112115

113116
echo "RUNNING CLI Script integration test for Stack Analysis full report in Json for Java Maven"
114-
match "langs/java/expected_stack_json" "node cli/node_modules/@RHEcosystemAppEng/crda-javascript-api/dist/src/cli.js stack langs/java/pom.xml"
117+
match "scenarios/java/expected_stack_json" "node testers/cli/node_modules/@RHEcosystemAppEng/crda-javascript-api/dist/src/cli.js stack scenarios/java/pom.xml"
115118

116119
echo "RUNNING CLI Script integration test for Stack Analysis summary only report in Json for Java Maven"
117-
match "langs/java/expected_stack_json_summary" "node cli/node_modules/@RHEcosystemAppEng/crda-javascript-api/dist/src/cli.js stack langs/java/pom.xml --summary"
120+
match "scenarios/java/expected_stack_json_summary" "node testers/cli/node_modules/@RHEcosystemAppEng/crda-javascript-api/dist/src/cli.js stack scenarios/java/pom.xml --summary"
118121

119122
echo "RUNNING CLI Script integration test for Component Analysis report for Java Maven"
120-
match "langs/java/expected_component" "node cli/node_modules/@RHEcosystemAppEng/crda-javascript-api/dist/src/cli.js component pom.xml '$(<langs/java/pom.xml)'"
123+
match "scenarios/java/expected_component" "node testers/cli/node_modules/@RHEcosystemAppEng/crda-javascript-api/dist/src/cli.js component pom.xml '$(<scenarios/java/pom.xml)'"
File renamed without changes.

integration/cli/package.json renamed to integration/testers/cli/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66
"type": "module",
77
"license": "Apache-2.0",
88
"dependencies": {
9-
"@RHEcosystemAppEng/crda-javascript-api": "file:../../"
9+
"@RHEcosystemAppEng/crda-javascript-api": "file:../../../"
1010
}
1111
}
File renamed without changes.

integration/javascript/package.json renamed to integration/testers/javascript/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66
"type": "module",
77
"license": "Apache-2.0",
88
"dependencies": {
9-
"@RHEcosystemAppEng/crda-javascript-api": "file:../../"
9+
"@RHEcosystemAppEng/crda-javascript-api": "file:../../../"
1010
}
1111
}

0 commit comments

Comments
 (0)