| ... | @@ -346,8 +346,48 @@ C:\GitLab-Runner>gitlab-runner.exe restart |
... | @@ -346,8 +346,48 @@ C:\GitLab-Runner>gitlab-runner.exe restart |
|
|
|
|
|
|
|

|
|

|
|
|
|
|
|
|
|
|
### Step 6: Unit tests and code coverage
|
|
|
|
|
|
|
|
|
- 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
|
|
|
|
- Go and download 64-bit version for Windows from [here](https://nodejs.org/en/download/)
|
|
|
|
- Install it, next you need to do is start command prompt and install jest globally
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
$ npm i jest -g
|
|
|
|
```
|
|
|
|
|
|
|
|
- Next we need to modify .yml file so Gitlab Runner can run unit tests and coverage
|
|
|
|
- We also need to edit project's settings in SonarQube and modify sonar-project.properties so it can find unit tests' and coverage's data for analysis
|
|
|
|
- First we start by editing **.gitlab-ci.yml** file
|
|
|
|
- To script we add two lines more
|
|
|
|
- Add ***- call npm i -s*** npm
|
|
|
|
- Command will install all dependencies that unit tests can perform correctly
|
|
|
|
- Add ***- call jest --coverage***
|
|
|
|
- Command will perform all unit tests and after that will perform coverage for code
|
|
|
|
- Add new information for runner, ***allow_failure: true***
|
|
|
|
- If one or more unit tests will fail it won't call whole pipeline as failed
|
|
|
|
- Now ***.gitlab-ci.yml*** file should look like this
|
|
|
|
|
|
|
|
```YAML
|
|
|
|
stages:
|
|
|
|
- scanning
|
|
|
|
running_scan:
|
|
|
|
tags:
|
|
|
|
- scan
|
|
|
|
stage: scanning
|
|
|
|
script:
|
|
|
|
- call npm i -s
|
|
|
|
- call jest --coverage
|
|
|
|
- sonar-scanner.bat
|
|
|
|
allow_failure: true
|
|
|
|
```
|
|
|
|
- Now let's edit ***sonar-project-properties***
|
|
|
|
- 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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| ... | |
... | |
| ... | | ... | |