1919
2020 strategy :
2121 matrix :
22- node-version : [16,18]
22+ node-version : [16, 18]
2323
2424 steps :
2525 - name : Checkout code
4040 - name : Run backend tests
4141 run : |
4242 cd week5/backend
43- npm test
43+ npm test -- --coverage --coverageReporters=json --coverageReporters=lcov
44+
45+ - name : Upload backend test artifacts
46+ uses : actions/upload-artifact@v4
47+ if : always()
48+ with :
49+ name : backend-test-results-node-${{ matrix.node-version }}
50+ path : |
51+ week5/backend/coverage/
52+ week5/backend/package.json
53+ week5/backend/jest.config.js
54+ retention-days : 30
4455
4556 - name : Start backend server and health check
4657 run : |
5061 curl -f http://localhost:3000/health
5162 curl -f http://localhost:3000/api/users
5263 pkill -f "node server.js"
64+
65+ - name : Validate backend deployment
66+ run : |
67+ cd week5/backend
68+ # Start server in background for validation
69+ npm start &
70+ SERVER_PID=$!
71+ sleep 8
72+
73+ echo "🚀 Running comprehensive API validation..."
74+
75+ # Test health endpoint
76+ echo "✅ Testing health endpoint..."
77+ curl -f -s http://localhost:3000/health | jq '.'
78+
79+ # Test root endpoint
80+ echo "✅ Testing root endpoint..."
81+ curl -f -s http://localhost:3000/ | jq '.'
82+
83+ # Test get all users
84+ echo "✅ Testing GET /api/users..."
85+ curl -f -s http://localhost:3000/api/users | jq '.'
86+
87+ # Test create user
88+ echo "✅ Testing POST /api/users..."
89+ NEW_USER=$(curl -f -s -X POST http://localhost:3000/api/users \
90+ -H "Content-Type: application/json" \
91+ -d '{"name":"CI Test User","email":"ci-test@example.com"}')
92+ echo "$NEW_USER" | jq '.'
93+ USER_ID=$(echo "$NEW_USER" | jq -r '.id')
94+
95+ # Test get specific user
96+ echo "✅ Testing GET /api/users/$USER_ID..."
97+ curl -f -s http://localhost:3000/api/users/$USER_ID | jq '.'
98+
99+ # Test delete user
100+ echo "✅ Testing DELETE /api/users/$USER_ID..."
101+ curl -f -s -X DELETE http://localhost:3000/api/users/$USER_ID | jq '.'
102+
103+ # Test 404 handling
104+ echo "✅ Testing 404 handling..."
105+ curl -s http://localhost:3000/nonexistent | jq '.'
106+
107+ echo "🎉 All API endpoints validated successfully!"
108+
109+ # Clean up
110+ kill $SERVER_PID
53111
54112 frontend-tests :
55113 name : Frontend Tests (Node.js ${{ matrix.node-version }})
@@ -78,8 +136,47 @@ jobs:
78136 - name : Run frontend tests
79137 run : |
80138 cd week5/frontend
81- npm test
82-
83-
139+ npm test -- --coverage --coverageReporters=json --coverageReporters=lcov
140+
141+ - name : Upload frontend test artifacts
142+ uses : actions/upload-artifact@v4
143+ if : always()
144+ with :
145+ name : frontend-test-results-node-${{ matrix.node-version }}
146+ path : |
147+ week5/frontend/coverage/
148+ week5/frontend/package.json
149+ week5/frontend/jest.config.js
150+ retention-days : 30
151+
152+ - name : Validate frontend deployment
153+ run : |
154+ cd week5/frontend
155+ # Start a simple HTTP server for frontend
156+ python3 -m http.server 8080 &
157+ SERVER_PID=$!
158+ sleep 5
159+
160+ echo "🚀 Running frontend validation..."
84161
85-
162+ # Test if HTML loads
163+ echo "✅ Testing HTML page load..."
164+ curl -f -s http://localhost:8080/index.html | head -20
165+
166+ # Test if CSS loads
167+ echo "✅ Testing CSS file..."
168+ curl -f -s http://localhost:8080/styles.css | head -10
169+
170+ # Test if JavaScript loads
171+ echo "✅ Testing JavaScript file..."
172+ curl -f -s http://localhost:8080/app.js | head -10
173+
174+ echo "🎉 Frontend files validated successfully!"
175+
176+ # Clean up
177+ kill $SERVER_PID
178+
179+
180+
181+
182+
0 commit comments