Skip to content

Commit 72d0e23

Browse files
authored
Merge pull request #16 from mathmelo/develop
feature/tests
2 parents 68728e8 + 69d3055 commit 72d0e23

File tree

6 files changed

+102
-23
lines changed

6 files changed

+102
-23
lines changed

.github/workflows/ci.yaml

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,33 @@
11
name: ci-node-workflow
2-
on:
2+
on:
33
pull_request:
4+
types: [opened, synchronize, reopened]
45
branches:
56
- develop
6-
jobs:
7+
jobs:
8+
sonarcloud:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v4
12+
with:
13+
fetch-depth: 0
14+
- uses: actions/setup-node@v4
15+
with:
16+
node-version: 22
17+
- run: npm run test:cov
18+
19+
- name: SonarQube Cloud Scan
20+
uses: SonarSource/sonarcloud-github-action@master
21+
env:
22+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
23+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
724
check-application:
825
runs-on: ubuntu-latest
926
steps:
1027
- uses: actions/checkout@v4
1128
- uses: actions/setup-node@v4
1229
with:
13-
node-version: 20
30+
node-version: 22
1431
- run: npm run test
1532
- run: npm run start
1633

@@ -32,4 +49,4 @@ jobs:
3249
with:
3350
context: .
3451
push: true
35-
tags: mathmelo/ci-github-actions:latest
52+
tags: mathmelo/ci-github-actions:latest

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
lcov.info
2+
node_modules
3+
.scannerwork

index.js

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,27 @@
11
function soma(a, b) {
2-
return a + b
2+
return a + b;
33
}
44

5-
console.log('passou aqui')
5+
function divisao(a, b) {
6+
return a / b;
7+
}
8+
9+
function multiplicacao(a, b) {
10+
return a * b;
11+
}
12+
13+
function subtracao(a, b) {
14+
return a - b;
15+
}
16+
17+
function potencia(a, b) {
18+
return Math.pow(a, b);
19+
}
620

7-
module.exports = soma
21+
module.exports = {
22+
soma,
23+
multiplicacao,
24+
subtracao,
25+
potencia,
26+
divisao,
27+
};

index.test.js

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,33 @@
1-
const soma = require('./index.js')
2-
const { deepStrictEqual } = require('assert')
1+
const {
2+
soma,
3+
subtracao,
4+
divisao,
5+
multiplicacao,
6+
potencia,
7+
} = require("./index.js");
8+
const { deepStrictEqual } = require("assert");
9+
const { test, describe } = require("node:test");
310

4-
;(async () => {
5-
deepStrictEqual(30, soma(15, 15))
6-
})()
11+
/**
12+
* Node v22.11.0 LTS
13+
* node --test --experimental-test-coverage --test-reporter=lcov --test-reporter-destination=lcov.info
14+
* Gerar arquivo lcov.info para integração com sonar scanner
15+
*/
16+
17+
describe("Operacoes basicas", () => {
18+
test("teste da funcao soma", () => {
19+
deepStrictEqual(30, soma(15, 15));
20+
});
21+
test("teste da funcao multiplicacao", () => {
22+
deepStrictEqual(16, multiplicacao(4, 4));
23+
});
24+
test("teste da funcao divisao", () => {
25+
deepStrictEqual(6, divisao(30, 5));
26+
});
27+
test("teste da funcao subtracao", () => {
28+
deepStrictEqual(75, subtracao(100, 25));
29+
});
30+
test("teste da funcao potencia", () => {
31+
deepStrictEqual(8, potencia(2, 3));
32+
});
33+
});

package.json

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
{
2-
"name": "gitsign",
3-
"version": "1.0.0",
4-
"main": "index.js",
5-
"scripts": {
6-
"start": "node index.js",
7-
"test": "node index.test.js"
8-
},
9-
"keywords": [],
10-
"author": "",
11-
"license": "ISC",
12-
"description": ""
2+
"name": "gitsign",
3+
"version": "1.0.0",
4+
"main": "index.js",
5+
"scripts": {
6+
"start": "node index.js",
7+
"test": "node index.test.js",
8+
"test:cov": "node --test --experimental-test-coverage --test-reporter=lcov --test-reporter-destination=lcov.info"
9+
},
10+
"keywords": [],
11+
"author": "",
12+
"license": "ISC",
13+
"description": ""
1314
}

sonar-project.properties

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
sonar.projectKey=mathmelo_ci-github-actions
2+
sonar.organization=mathmelo2000
3+
4+
sonar.sources=.
5+
sonar.exclusions=**/*.test.js
6+
7+
sonar.tests=.
8+
sonar.test.inclusions=**/*.test.js
9+
# sonar.host.url=http://sonarqube:9000
10+
# sonar.login=
11+
sonar.javascript.lcov.reportPaths=lcov.info

0 commit comments

Comments
 (0)