diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5044ada..f125b7b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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: @@ -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: | @@ -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 diff --git a/README.md b/README.md index aaa07b0..dd9e8f3 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/app.js b/app.js new file mode 100644 index 0000000..2f62be5 --- /dev/null +++ b/app.js @@ -0,0 +1,36 @@ +const Calculator = require('./calculator'); +const MathUtils = require('./mathUtils'); + +// 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}`); diff --git a/app/core/calculator.test.js b/app/core/calculator.test.js index 7560167..6dbcf41 100644 --- a/app/core/calculator.test.js +++ b/app/core/calculator.test.js @@ -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 -}); diff --git a/babel.config.js b/babel.config.js new file mode 100644 index 0000000..a79d119 --- /dev/null +++ b/babel.config.js @@ -0,0 +1,3 @@ +module.exports = { + presets: ['@babel/preset-env'], +}; diff --git a/jest.config.js b/jest.config.js index 137e9ef..88f5acd 100644 --- a/jest.config.js +++ b/jest.config.js @@ -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 }; diff --git a/package.json b/package.json index 3a7b637..9f884c7 100644 --- a/package.json +++ b/package.json @@ -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" } } diff --git a/vite.config.js b/vite.config.js index 6d248dd..6bc606d 100644 --- a/vite.config.js +++ b/vite.config.js @@ -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', }, } });