Skip to content

Commit

Permalink
Merge pull request #865 from WildMeOrg/code-cov-test
Browse files Browse the repository at this point in the history
Update codecov-report.yml
  • Loading branch information
tsubramanian authored Nov 10, 2024
2 parents c51f9fc + f446ea0 commit 2958437
Show file tree
Hide file tree
Showing 5 changed files with 134 additions and 6 deletions.
104 changes: 98 additions & 6 deletions .github/workflows/codecov-report.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,98 @@
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
with:
fail_ci_if_error: false
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
name: CodCov, Run Backend and Frontend Tests

on:
push:
branches:
- '**'

jobs:
test:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

# Set up Java for backend tests
- name: Set up Java
uses: actions/setup-java@v4
with:
distribution: 'zulu'
java-version: '8'

# Set up Node.js for frontend tests
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '16'

# Install dependencies for backend
- name: Install backend dependencies
run: |
#cd src/test
mvn clean install
mkdir -p src/surefire-reports
mkdir -p frontend/coverage
# Run backend tests with coverage
- name: Run backend tests
run: mvn test -e
working-directory: ./
continue-on-error: true

# Install dependencies for frontend
- name: Install frontend dependencies
run: |
cd frontend
npm install
# Run frontend tests with coverage
- name: Run frontend tests
run: npm run test --coverage
working-directory: frontend
continue-on-error: true

# Upload test results and coverage
- name: Upload coverage results
uses: actions/upload-artifact@v3
with:
name: test-results
path: |
target/surefire-reports
frontend/coverage
# List coverage files
- name: Verify coverage files
run: |
echo "Checking backend coverage files..."
ls -l target/site/jacoco/ || echo "No backend coverage files found"
echo "Checking frontend coverage files..."
ls -l frontend/coverage/ || echo "No frontend coverage files found"
# Upload to Codecov
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }} # Add Codecov token as a secret in GitHub
files: |
target/site/jacoco/jacoco.xml
frontend/coverage/lcov.info
flags: backend,frontend
name: codecov-coverage-report
fail_ci_if_error: false # Does not block merge if there’s an error

- name: List files
run: |
#cd src/test
ls -l target/surefire-reports
ls -l frontend/coverage
# Display test coverage in the summary (optional)
- name: Display test coverage summary
run: |
echo "Backend Test Results:"
cat target/surefire-reports/*.txt || true
echo "Frontend Test Coverage Summary:"
cat frontend/coverage/*.* || true
5 changes: 5 additions & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,5 +92,10 @@
"webpack-bundle-analyzer": "^4.10.1",
"webpack-cli": "^5.1.4",
"webpack-dev-server": "^4.15.1"
},
"jest":{
"collectCoverage": true,
"coverageReporters": ["lcov", "text"],
"coverageDirectory": "./coverage"
}
}
4 changes: 4 additions & 0 deletions frontend/src/__tests__/MultiLanguageDropdown.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import { localeMap, languageMap } from "../constants/locales";
import "@testing-library/jest-dom"; // Ensure you have this installed for extended matchers
import Cookies from "js-cookie";

beforeAll(()=> {
process.env.PUBLIC_URL ="/react";
});

jest.mock("js-cookie", () => ({
get: jest.fn(),
}));
Expand Down
7 changes: 7 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,12 @@
"husky": "^7.0.4",
"lint-staged": ">=8",
"prettier": "^3.3.3"
},
{
"jest": {
"collectCoverage": true,
"coverageReporters": ["lcov", "text"],
"coverageDirectory": "./coverage"
}
}
}
20 changes: 20 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,26 @@
</executions>
</plugin>

<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.8</version>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
Expand Down

0 comments on commit 2958437

Please sign in to comment.