| ... | ... | @@ -348,6 +348,8 @@ C:\GitLab-Runner>gitlab-runner.exe restart |
|
|
|
|
|
|
|
### Step 6: Unit tests and code coverage
|
|
|
|
|
|
|
|
***HOX!*** To do this step you need to install database to virtual machine so unit tests can be performed! [GUIDE](https://gitlab.labranet.jamk.fi/Iotitude/Virtuaalikaveri/blob/gRPC/DATABASE.md#linux-installation)
|
|
|
|
|
|
|
|
- The example project has already made unit tests and their coverage should be over 80%
|
|
|
|
- Unit tests are made with [Jest](https://jestjs.io/en/) and we will use jest for run unit tests and check their coverage
|
|
|
|
- To use Jest we need to download and install Node.js for computer where Gitlab Runner is installed
|
| ... | ... | @@ -387,14 +389,42 @@ running_scan: |
|
|
|
- Let's update version number to 1.01
|
|
|
|
- Specify sonar.source properly
|
|
|
|
- We only want to analyze server and client folders and config.js
|
|
|
|
- So
|
|
|
|
|
|
|
|
|
|
|
|
- So we edit sonar.sources to like this ***sonar.sources=server, client, config.js***
|
|
|
|
- We also want to tell SonarQube where are unit test files
|
|
|
|
- Add this line to file ***sonar.tests=./server/tests***
|
|
|
|
- To add coverage's data we need to tell what is report's path
|
|
|
|
- Add this line to file ***sonar.javascript.lcov.reportPath=coverage/lcov.info***
|
|
|
|
- Not sure how this works but SonarScanner need this data to perform analyze correctly
|
|
|
|
- Add these lines to file
|
|
|
|
|
|
|
|
```shell
|
|
|
|
sonar.test.inclusions=**/*Test*/**
|
|
|
|
sonar.exclusions=**/*Test*/**
|
|
|
|
```
|
|
|
|
- Now your ***sonar-project.properties*** should look like this
|
|
|
|
|
|
|
|
```shell
|
|
|
|
sonar.projectKey=testing
|
|
|
|
sonar.projectName=CI-testing
|
|
|
|
sonar.projectVersion=1.0
|
|
|
|
sonar.sources=server, client, config.js
|
|
|
|
sonar.tests=./server/tests
|
|
|
|
sonar.javascript.lcov.reportPath=coverage/lcov.info
|
|
|
|
sonar.test.inclusions=**/*Test*/**
|
|
|
|
sonar.exclusions=**/*Test*/**
|
|
|
|
```
|
|
|
|
|
|
|
|
- You also have to edit project's setting in SonarQube just to make sure it can find correct coverage's info
|
|
|
|
- Open SonarQube < virtual machine's ip >:9000 -> Open project "CI-testing" -> Go Administration -> General Settings -> JavaScript and on the bottom is Tests and Coverage LCOV Files
|
|
|
|
- Add line ***coverage/lcov.info*** adn save.
|
|
|
|
|
|
|
|
- Now you are ready save project and push it again to Gitlab so it can run unit tests and coverage
|
|
|
|
|
|
|
|
```shell
|
|
|
|
$ git add -A
|
|
|
|
$ git commit -m "edited sonar-project.properties and .gitlab-ci.yml for unit tests and code coverage"
|
|
|
|
$ git push origin master
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
| ... | ... | |
| ... | ... | |