Skip to content

Commit 8ce85d7

Browse files
author
Dias, Diego
committed
Add CI/CD test coverage workflow for Sprint 3
- Add Jest coverage configuration with 100% threshold - Create inline test verification script that: - Runs inline assertion tests with Node.js - Detects console.assert failures - Verifies test parity between inline and Jest tests - Reports disparities in both directions - Add GitHub Actions workflow that: - Triggers on coursework/sprint-3-implement-and-rewrite* branches - Runs inline tests with parity check - Runs Jest tests with coverage - Generates coverage report on PRs
1 parent ccb6ce8 commit 8ce85d7

File tree

4 files changed

+212
-1
lines changed

4 files changed

+212
-1
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: Test Coverage Report
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
push:
8+
branches:
9+
- 'coursework/sprint-3-implement-and-rewrite*'
10+
11+
jobs:
12+
test-coverage:
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- name: Checkout code
17+
uses: actions/checkout@v4
18+
19+
- name: Setup Node.js
20+
uses: actions/setup-node@v4
21+
with:
22+
node-version: '20'
23+
cache: 'npm'
24+
25+
- name: Install dependencies
26+
run: npm ci
27+
28+
- name: Run Inline Assertion Tests & Verify Parity
29+
run: ./scripts/run-inline-tests.sh
30+
31+
- name: Run Jest Tests with Coverage
32+
run: npm run test:coverage
33+
34+
- name: Generate Coverage Report Comment
35+
uses: ArtiomTr/jest-coverage-report-action@v2
36+
with:
37+
github-token: ${{ secrets.GITHUB_TOKEN }}
38+
test-script: npm run test:coverage
39+
coverage-file: ./coverage/jest-tests/coverage-summary.json
40+
annotations: failed-tests
41+
package-manager: npm
42+
43+
- name: Upload Coverage Reports
44+
uses: actions/upload-artifact@v4
45+
with:
46+
name: coverage-report
47+
path: coverage/jest-tests/

jest.config.jest-tests.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
module.exports = {
2+
displayName: "Jest Tests",
3+
testMatch: ["**/rewrite-tests-with-jest/**/*.test.js"],
4+
collectCoverage: true,
5+
coverageDirectory: "coverage/jest-tests",
6+
collectCoverageFrom: [
7+
"Sprint-3/1-implement-and-rewrite-tests/implement/*.js",
8+
"!Sprint-3/1-implement-and-rewrite-tests/implement/*.test.js",
9+
],
10+
coveragePathIgnorePatterns: [
11+
"/node_modules/",
12+
],
13+
coverageReporters: ["text", "lcov", "json-summary"],
14+
coverageThreshold: {
15+
global: {
16+
branches: 100,
17+
functions: 100,
18+
lines: 100,
19+
statements: 100,
20+
},
21+
},
22+
};

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
"description": "Like learning a musical instrument, programming requires daily practice.",
55
"main": "index.js",
66
"scripts": {
7-
"test": "jest"
7+
"test": "jest",
8+
"test:coverage": "jest --config=jest.config.jest-tests.js --coverage"
89
},
910
"keywords": [],
1011
"author": "Code Your Future",

scripts/run-inline-tests.sh

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
#!/bin/bash
2+
3+
# Comprehensive script to:
4+
# 1. Run inline assertion tests with proper logging
5+
# 2. Detect and fail on assertion errors
6+
# 3. Verify test case parity with Jest tests
7+
8+
set -e
9+
10+
IMPLEMENT_DIR="Sprint-3/1-implement-and-rewrite-tests/implement"
11+
JEST_DIR="Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest"
12+
13+
PASSED=0
14+
FAILED=0
15+
TOTAL=0
16+
PARITY_ISSUES=false
17+
18+
echo "🧪 Running Inline Assertion Tests"
19+
echo "=========================================="
20+
echo ""
21+
22+
# Run each implementation file
23+
for file in "$IMPLEMENT_DIR"/*.js; do
24+
filename=$(basename "$file")
25+
echo "Testing: $filename"
26+
echo "------------------------------------------"
27+
28+
TOTAL=$((TOTAL + 1))
29+
30+
# Run the file and capture output
31+
OUTPUT=$(node "$file" 2>&1) || true
32+
33+
# Check if output contains "Assertion failed"
34+
if echo "$OUTPUT" | grep -q "Assertion failed"; then
35+
echo "❌ FAILED"
36+
echo "$OUTPUT"
37+
FAILED=$((FAILED + 1))
38+
else
39+
echo "✅ PASSED"
40+
if [ ! -z "$OUTPUT" ]; then
41+
echo "$OUTPUT"
42+
fi
43+
PASSED=$((PASSED + 1))
44+
fi
45+
46+
echo ""
47+
done
48+
49+
echo "=========================================="
50+
echo "📊 Test Execution Summary"
51+
echo "=========================================="
52+
echo "Total Files: $TOTAL"
53+
echo "Passed: $PASSED"
54+
echo "Failed: $FAILED"
55+
echo ""
56+
57+
# Now check test parity
58+
echo "=========================================="
59+
echo "🔍 Verifying Test Case Parity with Jest"
60+
echo "=========================================="
61+
echo ""
62+
63+
for impl_file in "$IMPLEMENT_DIR"/*.js; do
64+
filename=$(basename "$impl_file")
65+
base_name="${filename%.js}"
66+
jest_file="$JEST_DIR/${base_name}.test.js"
67+
68+
echo "Comparing: $filename"
69+
echo "------------------------------------------"
70+
71+
if [ ! -f "$jest_file" ]; then
72+
echo "⚠️ No corresponding Jest test file found"
73+
PARITY_ISSUES=true
74+
echo ""
75+
continue
76+
fi
77+
78+
# Count assertions
79+
inline_count=$(grep -c "assertEquals(" "$impl_file" || echo "0")
80+
jest_count=$(grep -c "expect(" "$jest_file" || echo "0")
81+
82+
echo " Inline assertions: $inline_count"
83+
echo " Jest assertions: $jest_count"
84+
85+
if [ "$inline_count" -eq "$jest_count" ]; then
86+
echo " ✅ Test counts match"
87+
else
88+
echo " ⚠️ MISMATCH DETECTED"
89+
if [ $inline_count -gt $jest_count ]; then
90+
diff=$((inline_count - jest_count))
91+
echo " → Inline tests have $diff MORE assertion(s) than Jest"
92+
echo " → Jest tests may be missing $diff test case(s)"
93+
else
94+
diff=$((jest_count - inline_count))
95+
echo " → Jest tests have $diff MORE assertion(s) than Inline"
96+
echo " → Inline tests may be missing $diff test case(s)"
97+
fi
98+
PARITY_ISSUES=true
99+
fi
100+
101+
echo ""
102+
done
103+
104+
# Final summary
105+
echo "=========================================="
106+
echo "🎯 Final Summary"
107+
echo "=========================================="
108+
echo ""
109+
110+
if [ $FAILED -gt 0 ]; then
111+
echo "❌ TEST FAILURES"
112+
echo "$FAILED inline test file(s) have failing assertions"
113+
echo " → Fix the failing assertions before proceeding"
114+
echo ""
115+
fi
116+
117+
if [ "$PARITY_ISSUES" = true ]; then
118+
echo "⚠️ TEST PARITY ISSUES"
119+
echo " → The number of test cases differs between inline and Jest tests"
120+
echo " → Both test suites should cover the same use cases"
121+
echo " → Review the comparison above and sync the test cases"
122+
echo ""
123+
fi
124+
125+
if [ $FAILED -eq 0 ] && [ "$PARITY_ISSUES" = false ]; then
126+
echo "✅ All inline tests passed!"
127+
echo "✅ Test parity verified - test counts match!"
128+
echo ""
129+
echo "🎉 Everything looks good!"
130+
exit 0
131+
else
132+
if [ $FAILED -gt 0 ]; then
133+
echo "❌ Exiting with failure due to test failures"
134+
exit 1
135+
else
136+
# Parity issues are warnings, not failures (tests still passed)
137+
echo "⚠️ Tests passed but parity issues detected"
138+
echo " Please sync test cases between inline and Jest tests"
139+
exit 0
140+
fi
141+
fi

0 commit comments

Comments
 (0)