Development #5
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Tests | |
| on: | |
| push: | |
| branches: [main, staging] | |
| pull_request: | |
| branches: [main, staging] | |
| jobs: | |
| test: | |
| runs-on: ubuntu-latest | |
| env: | |
| NODE_ENV: test | |
| NODE_OPTIONS: --experimental-vm-modules | |
| DATABASE_URL: postgresql://test:test@localhost:5432/acquisitions_test | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '20.x' | |
| cache: 'npm' | |
| - name: Install dependencies | |
| run: npm ci | |
| - name: Run tests | |
| id: run-tests | |
| run: | | |
| echo "Running tests..." | |
| if npm test; then | |
| echo "test_status=success" >> $GITHUB_OUTPUT | |
| echo "✅ All tests passed!" >> $GITHUB_STEP_SUMMARY | |
| else | |
| echo "test_status=failed" >> $GITHUB_OUTPUT | |
| echo "❌ Some tests failed!" >> $GITHUB_STEP_SUMMARY | |
| echo "::error title=Test Failures::Some tests failed. Check the logs above for details." | |
| exit 1 | |
| fi | |
| - name: Upload coverage reports | |
| uses: actions/upload-artifact@v4 | |
| if: always() | |
| with: | |
| name: coverage-reports | |
| path: coverage/ | |
| retention-days: 30 | |
| - name: Generate test summary | |
| if: always() | |
| run: | | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "## Test Results" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| if [ -f "coverage/lcov.info" ]; then | |
| echo "📊 **Coverage Report Available**" >> $GITHUB_STEP_SUMMARY | |
| echo "Coverage reports have been uploaded as artifacts." >> $GITHUB_STEP_SUMMARY | |
| fi | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "**Environment Variables:**" >> $GITHUB_STEP_SUMMARY | |
| echo "- NODE_ENV: $NODE_ENV" >> $GITHUB_STEP_SUMMARY | |
| echo "- NODE_OPTIONS: $NODE_OPTIONS" >> $GITHUB_STEP_SUMMARY | |
| echo "- DATABASE_URL: [configured]" >> $GITHUB_STEP_SUMMARY | |
| if [ "${{ steps.run-tests.outputs.test_status }}" = "failed" ]; then | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "⚠️ **Action Required:** Fix the failing tests before merging." >> $GITHUB_STEP_SUMMARY | |
| fi |