Skip to content

Commit 43dbcd5

Browse files
committed
Initial commit
1 parent 5da0bbd commit 43dbcd5

File tree

7 files changed

+158
-0
lines changed

7 files changed

+158
-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: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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: Install dependencies
24+
run: |
25+
npm install -g nyc # Install Istanbul (nyc) for code coverage
26+
npm install # Install project dependencies
27+
28+
- name: Run tests and collect coverage
29+
run: |
30+
# Replace with the actual command to run your tests
31+
npm test
32+
33+
# Generate code coverage report using nyc (Istanbul)
34+
nyc report --reporter=lcov > $GITHUB_WORKSPACE/lcov.info
35+
nyc report --reporter=text-summary # Display summary in the console
36+
37+
- name: Upload coverage report to Codacy
38+
env:
39+
CODACY_PROJECT_TOKEN: ${{ secrets.CODACY_PROJECT_TOKEN }}
40+
run: |
41+
bash <(curl -Ls https://coverage.codacy.com/get.sh) report -r $GITHUB_WORKSPACE/lcov.info
42+
43+
- name: Run Codacy Analysis CLI with Docker (optional)
44+
run: |
45+
export CODACY_CODE=$GITHUB_WORKSPACE
46+
docker run \
47+
--rm=true \
48+
--env CODACY_CODE="$CODACY_CODE" \
49+
--volume /var/run/docker.sock:/var/run/docker.sock \
50+
--volume "$CODACY_CODE":"$CODACY_CODE" \
51+
--volume /tmp:/tmp \
52+
codacy/codacy-analysis-cli \
53+
analyze --tool eslint --upload --project-token ${{ secrets.CODACY_PROJECT_TOKEN }} --max-allowed-issues 99999 --commit-uuid $GITHUB_SHA
54+
if: success() # Optional, run only if the previous steps were successful

__tests__/main.test.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// __tests__/main.test.js
2+
3+
const main = require('../main');
4+
5+
test('addNumbers function adds two numbers correctly', () => {
6+
expect(main.addNumbers(2, 3)).toBe(5);
7+
});
8+
9+
test('subtractNumbers function subtracts two numbers correctly', () => {
10+
expect(main.subtractNumbers(5, 2)).toBe(3);
11+
});
12+
13+
// Add more tests for other functions if needed

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+
// Error: Unused variable 'unusedVariable'
17+
const unusedVariable = 'This variable is not used';
18+
19+
// Error: Missing semicolon at the end of the line
20+
const missingSemicolon = 'This line is missing a semicolon';
21+
22+
// Error: Using an undefined variable
23+
console.log(undefinedVariable);
24+
25+
// Error: Trying to reassign a constant
26+
const constantValue = 42;
27+
constantValue = 43;
28+
29+
// Error: Missing function argument
30+
function missingArgument(arg1, arg2) {
31+
return arg1 + arg2;
32+
}
33+
34+
module.exports = {
35+
addNumbers,
36+
subtractNumbers,
37+
};

package.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"name": "sample-javascript-project",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"keywords": [],
10+
"author": "",
11+
"license": "ISC"
12+
}

util.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// This is a utility module with some basic functions.
2+
3+
// Function to add two numbers
4+
function add(a, b) {
5+
return a + b;
6+
}
7+
8+
// Function to subtract two numbers
9+
function subtract(a, b) {
10+
return a - b;
11+
}
12+
13+
// Export the functions to make them accessible in other modules
14+
module.exports = {
15+
add,
16+
subtract,
17+
};
18+

0 commit comments

Comments
 (0)