Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,8 @@ jobs:
with:
node-version: '18.x'
- run: npm install
- run: npm test
- run: npm run test:coverage
- name: SonarQube Scan
uses: SonarSource/sonarqube-scan-action@v6
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules
node_modules
coverage
10 changes: 9 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"description": "",
"main": "index.js",
"scripts": {
"test": "jest"
"test": "jest",
"test:coverage": "jest --coverage"
},
"repository": {
"type": "git",
Expand All @@ -16,6 +17,13 @@
"url": "https://github.com/mschead/full-cycle-ci/issues"
},
"homepage": "https://github.com/mschead/full-cycle-ci#readme",
"jest": {
"coverageReporters": [
"lcov",
"text-summary"
],
"coverageDirectory": "coverage"
},
"dependencies": {
"jest": "^30.2.0"
}
Expand Down
14 changes: 14 additions & 0 deletions sonar-project.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
sonar.projectKey=mschead_full-cycle-ci
sonar.organization=schead-org
sonar.javascript.lcov.reportPaths=./coverage/lcov.info

# This is the name and version displayed in the SonarCloud UI.
sonar.projectName=full-cycle-ci
sonar.projectVersion=1.0

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

# Encoding of the source code. Default is default system encoding
sonar.sourceEncoding=UTF-8
10 changes: 9 additions & 1 deletion math.js → src/math.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,12 @@ function divide(a, b) {
return a / b;
}

module.exports = { add, subtract, multiply, divide };
function square(a) {
return a * a;
}

function modulo(a, b) {
return a % b;
}

module.exports = { add, subtract, multiply, divide, square, modulo };
10 changes: 9 additions & 1 deletion math.test.js → src/math.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { add, subtract, multiply, divide } = require("./math");
const { add, subtract, multiply, divide, square, modulo } = require("./math");

it("should add two numbers", () => {
expect(add(1, 2)).toBe(3);
Expand All @@ -15,3 +15,11 @@ it("should multiply two numbers", () => {
it("should divide two numbers", () => {
expect(divide(1, 2)).toBe(0.5);
});

it("should square a number", () => {
expect(square(2)).toBe(4);
});

it("should modulo two numbers", () => {
expect(modulo(1, 2)).toBe(1);
});