Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
a647e28
Update calculator.test.js
nofarb Jun 13, 2025
8cb3afe
Update ci.yml
nofarb Jun 13, 2025
10ac3a2
Update ci.yml
nofarb Jun 13, 2025
6a1254f
Update ci.yml
nofarb Jun 13, 2025
c5656f9
Update vite.config.js
nofarb Jun 13, 2025
bb0f231
Update package.json
nofarb Jun 13, 2025
2e64761
Update package.json
nofarb Jun 13, 2025
8dc7af7
Update vite.config.js
nofarb Jun 13, 2025
12321e4
Update ci.yml
nofarb Jun 13, 2025
2bec7da
Update vite.config.js
nofarb Jun 13, 2025
9f74226
Update package.json
nofarb Jun 13, 2025
eab59c6
Update jest.config.js
nofarb Jun 13, 2025
a09b462
Update package.json
nofarb Jun 13, 2025
cdb78be
Update ci.yml
nofarb Jun 13, 2025
7c3188e
Update package.json
nofarb Jun 13, 2025
bddd633
Update ci.yml
nofarb Jun 13, 2025
84cd05e
Update package.json
nofarb Jun 13, 2025
9eb666d
Update package.json
nofarb Jun 13, 2025
a3ddfbc
Update ci.yml
nofarb Jun 13, 2025
cf59279
Update package.json
nofarb Jun 13, 2025
1f4e619
Create babel.config.js
nofarb Jun 13, 2025
d3f6c60
Update ci.yml
nofarb Jun 13, 2025
bedbeb0
Update README.md
nofarb Jun 13, 2025
f479552
Update vite.config.js
nofarb Jun 13, 2025
97f0c69
Update vite.config.js
nofarb Jun 13, 2025
668ad99
Update package.json
nofarb Jun 13, 2025
c79e426
Update package.json
nofarb Jun 13, 2025
15774af
Update ci.yml
nofarb Jun 13, 2025
63b42a3
Update ci.yml
nofarb Jun 13, 2025
9b737a2
Update ci.yml
nofarb Jun 13, 2025
1339c7f
Update ci.yml
nofarb Jun 13, 2025
a785640
Update ci.yml
nofarb Jun 13, 2025
d771873
Update ci.yml
nofarb Jun 13, 2025
2b21da5
Create app.js
nofarb Jun 13, 2025
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
32 changes: 17 additions & 15 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,9 @@ jobs:
node-version: 18

- name: Install dependencies
run: npm install


- name: Verify Vitest installation
run: |
echo "Checking Vitest installation..."
which vitest || echo "Vitest not found!" # Check if Vitest is installed
npm list vitest # List the Vitest package to verify installation
run: |
npm install vitest --save-dev
npm install c8 --save-dev


# Uncomment this block if you eventually want bundle analysis enabled again:
Expand All @@ -50,7 +45,10 @@ jobs:
# run: npm run build

- name: Run tests with coverage
run: npm run test --coverage || true
run: |
mkdir -p coverage
npm run test -- --coverage || true


- name: List all files recursively (debugging step)
run: |
Expand All @@ -59,17 +57,21 @@ jobs:
find . -type f -name "*.json"
find . -type f -name "*.lcov*"

- name: Upload code coverage to Codacy
run: bash <(curl -Ls https://coverage.codacy.com/get.sh)
env:
CODACY_PROJECT_TOKEN: ${{ secrets.CODACY_PROJECT_TOKEN }}
CODACY_API_TOKEN: ${{ secrets.CODACY_API_TOKEN }}
CODACY_ORGANIZATION_PROVIDER: gh
CODACY_USERNAME: nofarb
CODACY_PROJECT_NAME: example-javascript


- name: Upload code coverage to Codecov
uses: codecov/codecov-action@v5
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_ORG_TOKEN }}
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

- name: Upload test results to Codecov
if: ${{ !cancelled() }}
uses: codecov/test-results-action@v1
with:
token: ${{ secrets.CODECOV_ORG_TOKEN }}

- name: SonarQube Scan
uses: SonarSource/sonarqube-scan-action@v5
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
This example repository shows how Codecov can be integrated with a simple javascript project. It uses **GitHub Actions** and **CircleCI** as CI/CD providers and **jest** as the coverage provider.

For more information, please see the links below.

## Links
- [Quick Start](https://docs.codecov.com/docs/quick-start)
- [GitHub Tutorial](https://docs.codecov.com/docs/github-tutorial)
Expand Down
36 changes: 36 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
const Calculator = require('./calculator');

Check failure on line 1 in app.js

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

app.js#L1

Require statement not part of import statement.
const MathUtils = require('./mathUtils');

Check failure on line 2 in app.js

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

app.js#L2

Require statement not part of import statement.

// Let's do some very convoluted math operations for no reason.

const calc = new Calculator();

// We'll add 10 and 20, then check if the result is even or odd, and then square it, cube it, and find the factorial of the result.

let sum = calc.add(10, 20); // Sum of 10 + 20

let isEven = MathUtils.isEven(sum); // Is the sum even?
let isOdd = MathUtils.isOdd(sum); // Is the sum odd?

console.log(`Sum: ${sum}`);
console.log(`Is the sum even? ${isEven}`);
console.log(`Is the sum odd? ${isOdd}`);

let squared = MathUtils.square(sum); // Square of the sum
let cubed = MathUtils.cube(sum); // Cube of the sum

console.log(`Squared sum: ${squared}`);
console.log(`Cubed sum: ${cubed}`);

let factorial = MathUtils.factorial(sum); // Factorial of the sum

console.log(`Factorial of sum: ${factorial}`);

// Now let's subtract the sum by 5, check if it's even, square it again, then divide by 3
let result = calc.subtract(sum, 5);
let resultSquared = MathUtils.square(result);
let resultDivided = calc.divide(resultSquared, 3);

console.log(`Subtract 5 from sum: ${result}`);
console.log(`Squared result: ${resultSquared}`);
console.log(`Result divided by 3: ${resultDivided}`);
30 changes: 0 additions & 30 deletions app/core/calculator.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,33 +26,3 @@ test('subtract function', () => {
expect(subtract(1e+100, 1e+100)).toBe(0); // Large number subtraction
});

test('multiply function', () => {
expect(multiply(1, 2)).toBe(2);
expect(multiply(2, 0)).toBe(0);
expect(multiply(-2, 3)).toBe(-6);
expect(multiply(0.5, 2)).toBe(1); // Floating point multiplication
expect(multiply(1000, 1000)).toBe(1000000); // Large number multiplication
});

test('divide function', () => {
expect(divide(10, 2)).toBe(5);
expect(divide(1, 0)).toBe("Cannot divide by 0"); // Divide by zero case
expect(divide(-10, 2)).toBe(-5);
expect(divide(10, -2)).toBe(-5);
expect(divide(1000, 1000)).toBe(1); // Large number division
expect(divide(5, "a")).toThrow(); // Invalid division input
});

test('divide2 function', () => {
expect(divide(10, 2)).toBe(5); // Valid division
expect(divide(1, 0)).toBe("Cannot divide by 0"); // This tests the divide by zero scenario
expect(divide(-10, 2)).toBe(-5); // Negative division
expect(divide(10, -2)).toBe(-5); // Negative division with swapped operands
});


test('floating-point operations', () => {
expect(add(0.1, 0.2)).toBeCloseTo(0.3, 5); // Floating point precision
expect(subtract(0.3, 0.1)).toBeCloseTo(0.2, 5); // Floating point subtraction
expect(multiply(0.1, 0.2)).toBeCloseTo(0.02, 5); // Floating point multiplication
});
3 changes: 3 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
presets: ['@babel/preset-env'],
};
6 changes: 3 additions & 3 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module.exports = {
testEnvironment: 'jsdom',
collectCoverage: true, // Enable coverage collection
coverageDirectory: 'coverage', // Set the output directory for coverage reports
coverageReporters: ['json', 'lcov', 'text', 'html'], // Specify formats for coverage reports
coverageReporters: ['lcov', 'json', 'html'], // Generate LCOV, JSON, and HTML reports
coverageDirectory: 'coverage', // Directory where the coverage reports will be saved
testEnvironment: 'node', // Or 'jsdom' depending on your needs
};
13 changes: 4 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@



{
"scripts": {
"test": "vitest run --coverage",
"build": "vite build"
"test": "vitest run"
},
"dependencies": {
"vitest": "1.6.1",
"@vitest/coverage-v8": "1.6.1",
"vite": "your-vite-version-here"
"devDependencies": {
"vitest": "^0.20.0",
"vite": "^2.9.0"
}
}
10 changes: 5 additions & 5 deletions vite.config.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { defineConfig } from 'vitest/config'; // Import Vitest config
import { defineConfig } from 'vitest/config';

export default defineConfig({
test: {
include: ['app/**/*.test.js'], // Path to test files
include: ['app/**/*.test.js'],
coverage: {
provider: 'v8', // Using v8 coverage provider for modern JavaScript
reporters: ['lcov', 'text', 'json', 'html', 'cobertura'], // Output coverage formats
reportDir: 'coverage/lcov-report', // Directory for coverage reports
provider: 'v8',
reporters: ['lcov', 'json', 'html'],
reportDir: 'coverage',
},
}
});