Skip to content

Commit 8671dbf

Browse files
authored
Merge pull request #1 from codacy-acme/v0.1
V0.1
2 parents 5da0bbd + 99d4230 commit 8671dbf

File tree

8 files changed

+1174
-0
lines changed

8 files changed

+1174
-0
lines changed

.eslintrc.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
module.exports = {
2+
env: {
3+
node: true,
4+
es6: true,
5+
jest: true,
6+
},
7+
extends: ['eslint:recommended'],
8+
plugins: ['jest'],
9+
rules: {
10+
'jest/no-disabled-tests': 'warn',
11+
'jest/no-focused-tests': 'error',
12+
'jest/no-identical-title': 'error',
13+
'jest/valid-expect': 'error',
14+
},
15+
};

.github/workflows/codacy.yml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: Client Side Tools and Coverage
2+
3+
on:
4+
push:
5+
branches: [ '*' ]
6+
pull_request:
7+
branches: [ '*' ]
8+
workflow_dispatch:
9+
10+
jobs:
11+
build:
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- name: Checkout code
16+
uses: actions/checkout@v2
17+
18+
- name: Set up Node.js
19+
uses: actions/setup-node@v2
20+
with:
21+
node-version: '18' # Choose your Node.js version
22+
23+
- name: Run Codacy Analysis CLI with Docker (optional)
24+
run: |
25+
export CODACY_CODE=$GITHUB_WORKSPACE
26+
docker run \
27+
--rm=true \
28+
--env CODACY_CODE="$CODACY_CODE" \
29+
--volume /var/run/docker.sock:/var/run/docker.sock \
30+
--volume "$CODACY_CODE":"$CODACY_CODE" \
31+
--volume /tmp:/tmp \
32+
codacy/codacy-analysis-cli \
33+
analyze --tool eslint --upload --project-token ${{ secrets.CODACY_PROJECT_TOKEN }} --max-allowed-issues 99999 --commit-uuid $GITHUB_SHA
34+
35+
- name: Install dependencies
36+
run: |
37+
npm install -g nyc # Install Istanbul (nyc) for code coverage
38+
npm install # Install project dependencies
39+
npm install --save-dev nyc
40+
npm install --save-dev chai
41+
npm install --save-dev blanket
42+
npm install --save-dev mocha
43+
npm install --save-dev mocha-lcov-reporter
44+
45+
- name: Run tests and collect coverage
46+
run: |
47+
# Replace with the actual command to run your tests
48+
npm test
49+
continue-on-error: true
50+
51+
- name: Upload coverage report to Codacy
52+
env:
53+
CODACY_PROJECT_TOKEN: ${{ secrets.CODACY_PROJECT_TOKEN }}
54+
run: |
55+
bash <(curl -Ls https://coverage.codacy.com/get.sh) report -r $GITHUB_WORKSPACE/lcov.info
56+
continue-on-error: true

__tests__/main.test.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
const { addNumbers, subtractNumbers } = require('../main');
2+
const { expect } = require('chai');
3+
4+
// Describe a test suite for main.js
5+
describe('Main Module', () => {
6+
// Test the addNumbers function
7+
describe('addNumbers', () => {
8+
it('should add two numbers correctly', () => {
9+
const result = addNumbers(5, 3);
10+
expect(result).to.equal(8);
11+
});
12+
});
13+
14+
// Test the subtractNumbers function
15+
describe('subtractNumbers', () => {
16+
it('should subtract two numbers correctly', () => {
17+
const result = subtractNumbers(10, 3);
18+
expect(result).to.equal(7);
19+
});
20+
});
21+
});

jest.config.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// jest.config.js
2+
3+
module.exports = {
4+
testEnvironment: 'node',
5+
coverageProvider: 'v8', // Use Istanbul (nyc) for code coverage
6+
collectCoverage: true,
7+
collectCoverageFrom: ['**/*.js'],
8+
};
9+

main.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// This is the main JavaScript file of your sample project.
2+
3+
// Import the utility functions from util.js
4+
const { add, subtract } = require('./util');
5+
6+
// Function to add two numbers
7+
function addNumbers(a, b) {
8+
return add(a, b);
9+
}
10+
11+
// Function to subtract two numbers
12+
function subtractNumbers(a, b) {
13+
return subtract(a, b);
14+
}
15+
16+
// Removed the unused variable
17+
// const unusedVariable = 'This variable is not used';
18+
19+
// Removed the missing semicolon
20+
const missingSemicolon = 'This line is missing a semicolon';
21+
22+
// Removed the undefined variable usage
23+
// console.log(undefinedVariable);
24+
25+
// Removed the attempt to reassign a constant
26+
// const constantValue = 42;
27+
// constantValue = 43;
28+
29+
// Removed the missing function argument
30+
// function missingArgument(arg1, arg2) {
31+
// return arg1 + arg2;
32+
// }
33+
34+
module.exports = {
35+
addNumbers,
36+
subtractNumbers,
37+
};

0 commit comments

Comments
 (0)