Skip to content

Commit

Permalink
chore: added jest
Browse files Browse the repository at this point in the history
  • Loading branch information
ValchanOficial committed Jun 6, 2023
1 parent d7b34b5 commit b969232
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 24 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
coverage/
package-lock.json
yarn.lock
node_modules
1 change: 1 addition & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = {presets: ['@babel/preset-env']}
35 changes: 18 additions & 17 deletions index.spec.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
const assert = require('assert');
const { Soma, Subtracao, Multiplicacao, Divisao } = require('./index');
const { test } = require('node:test');
import 'jest';
import { Divisao, Multiplicacao, Soma, Subtracao } from './index.js';

test('Teste de soma', () => {
assert.strictEqual(Soma(1, 1), 2);
});

test('Teste de subtração', () => {
assert.strictEqual(Subtracao(4, 1), 3);
});

test('Teste de multiplicação', () => {
assert.strictEqual(Multiplicacao(4, 1), 4);
});

test('Teste de divisão', () => {
assert.strictEqual(Divisao(5, 1), 5);
describe('Calculadora', () => {
test('Teste de soma', () => {
expect(Soma(1, 1)).toBe(2);
});

test('Teste de subtração', () => {
expect(Subtracao(4, 1)).toBe(3);
});

test('Teste de multiplicação', () => {
expect(Multiplicacao(4, 1)).toBe(4);
});

test('Teste de divisão', () => {
expect(Divisao(5, 1)).toBe(5);
});
});
17 changes: 15 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
"version": "1.0.0",
"description": "Pipeline de CI com SonarCloud",
"main": "index.js",
"type": "commonjs",
"scripts": {
"start": "node index.js",
"test": "node index.spec.js"
"test": "jest --coverage"
},
"repository": {
"type": "git",
Expand All @@ -20,5 +21,17 @@
"bugs": {
"url": "https://github.com/ValchanOficial/FullCycleDesafioPipelineCISonarCloud/issues"
},
"homepage": "https://github.com/ValchanOficial/FullCycleDesafioPipelineCISonarCloud#readme"
"homepage": "https://github.com/ValchanOficial/FullCycleDesafioPipelineCISonarCloud#readme",
"dependencies": {
"jest": "^29.5.0"
},
"jest": {
"collectCoverage": true,
"coverageReporters": [
"lcov"
]
},
"devDependencies": {
"@babel/preset-env": "^7.22.4"
}
}
15 changes: 10 additions & 5 deletions sonar-project.properties
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
sonar.projectKey=ValchanOficial_FullCycleDesafioPipelineCISonarCloud
sonar.organization=valchanoficial
sonar.language=js
sonar.sourceEncoding=UTF-8

# This is the name and version displayed in the SonarCloud UI.
sonar.projectName=FullCycleDesafioPipelineCISonarCloud
sonar.projectVersion=1.0

# Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows.
#sonar.sources=.
sonar.sources=.
sonar.inclusions=**/*.js
sonar.exclusions=**/*.spec.js

# Encoding of the source code. Default is default system encoding
#sonar.sourceEncoding=UTF-8
sonar.tests=.
sonar.test.inclusions=**/*.spec.js

sonar.javascript.lcov.reportPaths=coverage/lcov.info
sonar.testExecutionReportPaths=./reports/ut_report.xml

0 comments on commit b969232

Please sign in to comment.