Skip to content

Commit d0047df

Browse files
committed
refactor: add server mgmt, enhanced reporting, improved caching
1 parent ed111b0 commit d0047df

File tree

3 files changed

+52
-20
lines changed

3 files changed

+52
-20
lines changed

.github/workflows/ci.yml

Lines changed: 44 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@ jobs:
5151
cache: "yarn"
5252
- run: yarn install --frozen-lockfile
5353
- run: yarn prepublishOnly
54+
- name: Cache React dependencies
55+
uses: actions/cache@v4
56+
with:
57+
path: react-example/node_modules
58+
key: ${{ runner.os }}-react-deps-${{ hashFiles('react-example/yarn.lock') }}
59+
restore-keys: |
60+
${{ runner.os }}-react-deps-
5461
- name: Install React example dependencies
5562
working-directory: ./react-example
5663
run: |
@@ -64,15 +71,17 @@ jobs:
6471
uses: actions/cache@v4
6572
id: playwright-cache
6673
with:
67-
path: |
68-
~/.cache/ms-playwright
69-
key: ${{ runner.os }}-playwright-${{ hashFiles('**/package-lock.json', '**/yarn.lock') }}-${{ hashFiles('**/playwright.config.ts') }}
74+
path: ~/.cache/ms-playwright
75+
key: ${{ runner.os }}-playwright-${{ hashFiles('react-example/package.json', 'react-example/playwright.config.ts') }}
7076
restore-keys: |
71-
${{ runner.os }}-playwright-${{ hashFiles('**/package-lock.json', '**/yarn.lock') }}-
77+
${{ runner.os }}-playwright-${{ hashFiles('react-example/package.json') }}-
7278
${{ runner.os }}-playwright-
7379
- name: Install Playwright browsers
7480
working-directory: ./react-example
7581
run: yarn playwright:install --with-deps
82+
- name: Install server management tools
83+
working-directory: ./react-example
84+
run: yarn add -D wait-on
7685
- name: Create environment configuration
7786
working-directory: ./react-example
7887
run: |
@@ -89,28 +98,45 @@ jobs:
8998
- name: Start React example server
9099
working-directory: ./react-example
91100
run: |
92-
yarn webpack serve --config webpack.config.js --port 8080 &
93-
for i in {1..15}; do
94-
if curl -f http://localhost:8080 >/dev/null 2>&1; then
95-
echo "Server is ready"
96-
break
97-
fi
98-
if [ $i -eq 15 ]; then
99-
echo "Server failed to start after 75 seconds"
100-
exit 1
101-
fi
102-
echo "Waiting for server... (attempt $i/15)"
103-
sleep 5
104-
done
101+
yarn webpack serve --config webpack.config.js --port 8080 --host 0.0.0.0 &
102+
SERVER_PID=$!
103+
echo "Started server with PID: $SERVER_PID"
104+
105+
# Wait for server to be ready with proper health check
106+
yarn wait-on http://localhost:8080 --timeout 60000
107+
108+
# Verify server health
109+
curl -f http://localhost:8080 > /dev/null || {
110+
echo "❌ Server health check failed"
111+
ps aux | grep webpack
112+
exit 1
113+
}
114+
echo "✅ Server is ready and healthy"
105115
- name: Run Playwright tests
106116
working-directory: ./react-example
107-
run: yarn playwright test --project=${{ matrix.browser }}
117+
run: |
118+
yarn playwright test --project=${{ matrix.browser }} --reporter=github
108119
env:
109120
CI: true
121+
PLAYWRIGHT_TIMEOUT: 30000
110122
- name: Upload Playwright report
111123
uses: actions/upload-artifact@v4
112124
if: always()
113125
with:
114126
name: playwright-report-${{ matrix.browser }}
115127
path: react-example/playwright-report/
116128
retention-days: 30
129+
- name: Upload test results
130+
uses: actions/upload-artifact@v4
131+
if: always()
132+
with:
133+
name: test-results-${{ matrix.browser }}
134+
path: react-example/test-results/
135+
retention-days: 7
136+
- name: Cleanup server processes
137+
if: always()
138+
run: |
139+
echo "🧹 Cleaning up server processes..."
140+
pkill -f "webpack serve" || true
141+
pkill -f "node.*webpack" || true
142+
echo "✅ Cleanup completed"

react-example/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@
6969
"webpack": "^5.99.9",
7070
"webpack-bundle-analyzer": "^4.10.2",
7171
"webpack-cli": "^6.0.1",
72-
"webpack-dev-server": "^5.2.2"
72+
"webpack-dev-server": "^5.2.2",
73+
"wait-on": "^7.2.0"
7374
},
7475
"dependencies": {
7576
"axios": "^1.12.2",

react-example/playwright.config.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,12 @@ export default defineConfig({
2020
/* Optimized worker count for CI vs local development */
2121
workers: process.env.CI ? 2 : undefined,
2222
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
23-
reporter: 'html',
23+
reporter: [
24+
['html'],
25+
['github'],
26+
['json', { outputFile: 'test-results/results.json' }],
27+
['junit', { outputFile: 'test-results/results.xml' }]
28+
],
2429
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
2530
use: {
2631
/* Base URL to use in actions like `await page.goto('/')`. */

0 commit comments

Comments
 (0)