Skip to content

Commit 65f65ba

Browse files
feat: add Client Unit Tests and Enhance Workflow Summary Reporting (#74)
add client-side tests and enhance GitHub Actions reporting What's Implemented Client-Side Tests: - Added unit tests for core frontend logic using the testing framework (e.g., Vitest or Jest). - Captured and stored test output to `test-output.txt` for summary extraction. GitHub Actions Workflow Enhancements: - Improved `Post workflow summary` step to include: - Workflow status, commit hash, branch name, and Node version. - Test result summary including test count and coverage. - Build output verification and `dist/` size. - Linting result reporting without failing the pipeline. Goal Establish automated frontend test execution and enhance CI visibility with test, build, and quality metrics in the GitHub Actions summary.
1 parent c965a5e commit 65f65ba

File tree

11 files changed

+2386
-2
lines changed

11 files changed

+2386
-2
lines changed

.github/workflows/build-and-test-client.yml

Lines changed: 75 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,12 @@ jobs:
4343
run: npm ci
4444

4545
- name: Lint code
46+
id: lint
4647
run: npm run lint
4748
continue-on-error: true
4849

4950
- name: Run tests if test files exist (.test.* or in __tests__ directories)
51+
id: run-tests
5052
run: |
5153
# Only look in directories that exist to avoid find errors
5254
paths=""
@@ -58,12 +60,18 @@ jobs:
5860
if [ -n "$test_files" ]; then
5961
echo "Test files found:"
6062
echo "$test_files"
61-
npm run test
63+
echo "tests_found=true" >> $GITHUB_OUTPUT
64+
# Run tests and capture output
65+
npm run test 2>&1 | tee test-output.txt
66+
TEST_EXIT_CODE=${PIPESTATUS[0]}
67+
echo "test_exit_code=$TEST_EXIT_CODE" >> $GITHUB_OUTPUT
6268
else
6369
echo "No test files found (no *.test.* or __tests__/*). Skipping tests."
70+
echo "tests_found=false" >> $GITHUB_OUTPUT
6471
fi
6572
else
6673
echo "No test or src directories found, skipping tests."
74+
echo "tests_found=false" >> $GITHUB_OUTPUT
6775
fi
6876
6977
- name: Build client
@@ -87,4 +95,70 @@ jobs:
8795
echo "No build output found - Build and Test Client workflow failed."
8896
exit 1
8997
fi
98+
- name: Post workflow summary
99+
if: always()
100+
run: |
101+
echo "## Workflow Summary" >> $GITHUB_STEP_SUMMARY
102+
echo "- Status: ${{ job.status }}" >> $GITHUB_STEP_SUMMARY
103+
echo "- Commit: ${{ github.sha }}" >> $GITHUB_STEP_SUMMARY
104+
echo "- Branch: ${{ github.ref }}" >> $GITHUB_STEP_SUMMARY
105+
echo "- Node Version: $(node -v)" >> $GITHUB_STEP_SUMMARY
106+
107+
echo "" >> $GITHUB_STEP_SUMMARY
108+
echo "### Test Results" >> $GITHUB_STEP_SUMMARY
109+
110+
if [ "${{ steps.run-tests.outputs.tests_found }}" = "true" ]; then
111+
if [ "${{ steps.run-tests.outputs.test_exit_code }}" = "0" ]; then
112+
echo "✅ **Tests Passed**" >> $GITHUB_STEP_SUMMARY
113+
else
114+
echo "❌ **Tests Failed**" >> $GITHUB_STEP_SUMMARY
115+
fi
116+
117+
# Strip ANSI escape codes from test-output.txt
118+
if [ -f test-output.txt ]; then
119+
sed -r "s/\x1B\[[0-9;]*[mK]//g" test-output.txt > test-clean.txt
120+
121+
# Extract test statistics
122+
TEST_STATS=$(grep -E "Test Files|Tests" test-clean.txt | tail -2)
123+
if [ -n "$TEST_STATS" ]; then
124+
echo "" >> $GITHUB_STEP_SUMMARY
125+
echo "**Test Statistics:**" >> $GITHUB_STEP_SUMMARY
126+
echo '```' >> $GITHUB_STEP_SUMMARY
127+
echo "$TEST_STATS" >> $GITHUB_STEP_SUMMARY
128+
echo '```' >> $GITHUB_STEP_SUMMARY
129+
fi
130+
131+
# Extract and filter coverage summary from cleaned output
132+
COVERAGE_INFO=$(awk '/Coverage report from v8/,0' test-clean.txt | grep -E '^All files|^ src/services|^ src/services' | head -n 20)
133+
if [ -n "$COVERAGE_INFO" ]; then
134+
echo "" >> $GITHUB_STEP_SUMMARY
135+
echo "**Coverage Summary (src/services only):**" >> $GITHUB_STEP_SUMMARY
136+
echo '```' >> $GITHUB_STEP_SUMMARY
137+
echo "$COVERAGE_INFO" >> $GITHUB_STEP_SUMMARY
138+
echo '```' >> $GITHUB_STEP_SUMMARY
139+
fi
140+
fi
141+
else
142+
echo "⚠️ **No tests found** - Skipped test execution" >> $GITHUB_STEP_SUMMARY
143+
fi
144+
145+
echo "" >> $GITHUB_STEP_SUMMARY
146+
echo "### Build Results" >> $GITHUB_STEP_SUMMARY
90147
148+
if [ -d dist ]; then
149+
echo "✅ **Build successful** - Output found in dist/" >> $GITHUB_STEP_SUMMARY
150+
BUILD_SIZE=$(du -sh dist 2>/dev/null | cut -f1)
151+
if [ -n "$BUILD_SIZE" ]; then
152+
echo "- Build size: $BUILD_SIZE" >> $GITHUB_STEP_SUMMARY
153+
fi
154+
else
155+
echo "❌ **Build failed** - No dist/ directory found" >> $GITHUB_STEP_SUMMARY
156+
fi
157+
158+
echo "" >> $GITHUB_STEP_SUMMARY
159+
echo "### Code Quality" >> $GITHUB_STEP_SUMMARY
160+
if [ "${{ steps.lint.outcome }}" = "success" ]; then
161+
echo "✅ **Linting passed**" >> $GITHUB_STEP_SUMMARY
162+
else
163+
echo "⚠️ **Linting failed** (continued on error)" >> $GITHUB_STEP_SUMMARY
164+
fi

0 commit comments

Comments
 (0)