Enhance test jobs with caching, coverage, and parallel execution
CI improvements: - Add needs: [] to run tests parallel with build (faster pipeline) - Add pip/npm caching (faster subsequent runs) - Add 15m timeout to prevent hung jobs - Add pytest coverage with cobertura report for GitLab - Add pytest JUnit report for test tab in MR - Add vitest coverage with cobertura report for GitLab - Add coverage regex for badge display Frontend: - Add @vitest/coverage-v8 dependency - Configure vitest coverage reporter (text, cobertura, html)
This commit is contained in:
@@ -18,23 +18,62 @@ hadolint:
|
|||||||
# Run Python backend tests
|
# Run Python backend tests
|
||||||
python_tests:
|
python_tests:
|
||||||
stage: test
|
stage: test
|
||||||
|
needs: [] # Run in parallel with build
|
||||||
image: deps.global.bsf.tools/docker/python:3.12-slim
|
image: deps.global.bsf.tools/docker/python:3.12-slim
|
||||||
|
timeout: 15m
|
||||||
|
variables:
|
||||||
|
PIP_CACHE_DIR: "$CI_PROJECT_DIR/.pip-cache"
|
||||||
|
cache:
|
||||||
|
key: pip-$CI_COMMIT_REF_SLUG
|
||||||
|
paths:
|
||||||
|
- .pip-cache/
|
||||||
|
policy: pull-push
|
||||||
before_script:
|
before_script:
|
||||||
- pip install -r backend/requirements.txt
|
- pip install -r backend/requirements.txt
|
||||||
- pip install pytest pytest-asyncio httpx
|
- pip install pytest pytest-asyncio pytest-cov httpx
|
||||||
script:
|
script:
|
||||||
- cd backend
|
- cd backend
|
||||||
- python -m pytest -v
|
- python -m pytest -v --cov=app --cov-report=term --cov-report=xml:coverage.xml --cov-report=html:coverage_html --junitxml=pytest-report.xml
|
||||||
|
artifacts:
|
||||||
|
when: always
|
||||||
|
expire_in: 1 week
|
||||||
|
paths:
|
||||||
|
- backend/coverage.xml
|
||||||
|
- backend/coverage_html/
|
||||||
|
- backend/pytest-report.xml
|
||||||
|
reports:
|
||||||
|
junit: backend/pytest-report.xml
|
||||||
|
coverage_report:
|
||||||
|
coverage_format: cobertura
|
||||||
|
path: backend/coverage.xml
|
||||||
|
coverage: '/TOTAL.*\s+(\d+%)/'
|
||||||
|
|
||||||
# Run frontend tests
|
# Run frontend tests
|
||||||
frontend_tests:
|
frontend_tests:
|
||||||
stage: test
|
stage: test
|
||||||
|
needs: [] # Run in parallel with build
|
||||||
image: deps.global.bsf.tools/docker/node:20-alpine
|
image: deps.global.bsf.tools/docker/node:20-alpine
|
||||||
|
timeout: 15m
|
||||||
|
cache:
|
||||||
|
key: npm-$CI_COMMIT_REF_SLUG
|
||||||
|
paths:
|
||||||
|
- frontend/node_modules/
|
||||||
|
policy: pull-push
|
||||||
before_script:
|
before_script:
|
||||||
- cd frontend
|
- cd frontend
|
||||||
- npm ci
|
- npm ci
|
||||||
script:
|
script:
|
||||||
- npm run test -- --run
|
- npm run test -- --run --reporter=verbose --coverage
|
||||||
|
artifacts:
|
||||||
|
when: always
|
||||||
|
expire_in: 1 week
|
||||||
|
paths:
|
||||||
|
- frontend/coverage/
|
||||||
|
reports:
|
||||||
|
coverage_report:
|
||||||
|
coverage_format: cobertura
|
||||||
|
path: frontend/coverage/cobertura-coverage.xml
|
||||||
|
coverage: '/All files[^|]*\|[^|]*\s+([\d\.]+)/'
|
||||||
rules:
|
rules:
|
||||||
- exists:
|
- exists:
|
||||||
- frontend/package.json
|
- frontend/package.json
|
||||||
|
|||||||
@@ -23,6 +23,7 @@
|
|||||||
"@types/react": "^18.2.48",
|
"@types/react": "^18.2.48",
|
||||||
"@types/react-dom": "^18.2.18",
|
"@types/react-dom": "^18.2.18",
|
||||||
"@vitejs/plugin-react": "^4.2.1",
|
"@vitejs/plugin-react": "^4.2.1",
|
||||||
|
"@vitest/coverage-v8": "^1.3.1",
|
||||||
"jsdom": "^24.0.0",
|
"jsdom": "^24.0.0",
|
||||||
"typescript": "^5.3.3",
|
"typescript": "^5.3.3",
|
||||||
"vite": "^5.0.12",
|
"vite": "^5.0.12",
|
||||||
|
|||||||
@@ -16,5 +16,10 @@ export default defineConfig({
|
|||||||
environment: 'jsdom',
|
environment: 'jsdom',
|
||||||
setupFiles: './src/test/setup.ts',
|
setupFiles: './src/test/setup.ts',
|
||||||
css: true,
|
css: true,
|
||||||
|
coverage: {
|
||||||
|
provider: 'v8',
|
||||||
|
reporter: ['text', 'cobertura', 'html'],
|
||||||
|
reportsDirectory: './coverage',
|
||||||
|
},
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user