Skip to content

Commit 34e5ca3

Browse files
Copilotsofthack007
andcommitted
Improve Wokwi workflow: better logging, error handling, and CommonJS compatibility
Co-authored-by: softhack007 <[email protected]>
1 parent f8f82ea commit 34e5ca3

File tree

5 files changed

+34
-15
lines changed

5 files changed

+34
-15
lines changed

.github/workflows/wokwi-test.yml

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -67,29 +67,44 @@ jobs:
6767
- name: Start Wokwi simulator in background
6868
run: |
6969
cd test/wokwi
70-
# Start simulator in background
71-
./run-simulator.sh &
70+
# Create log directory
71+
mkdir -p logs
72+
73+
# Start simulator in background with a 180 second timeout
74+
WOKWI_TIMEOUT=180 ./run-simulator.sh > logs/wokwi.log 2>&1 &
7275
WOKWI_PID=$!
7376
echo "WOKWI_PID=$WOKWI_PID" >> $GITHUB_ENV
77+
echo "Started Wokwi simulator with PID $WOKWI_PID"
7478
7579
# Wait for simulator to start and web server to be ready
7680
echo "Waiting for WLED web server to be ready..."
77-
timeout=60
81+
max_wait=120
7882
elapsed=0
79-
while [ $elapsed -lt $timeout ]; do
80-
if curl -s http://localhost:8080 > /dev/null 2>&1; then
81-
echo "Web server is ready!"
83+
while [ $elapsed -lt $max_wait ]; do
84+
if curl -s -f http://localhost:8080 > /dev/null 2>&1; then
85+
echo "Web server is ready after $elapsed seconds!"
8286
break
8387
fi
84-
echo "Waiting... ($elapsed seconds)"
85-
sleep 2
86-
elapsed=$((elapsed + 2))
88+
if ! kill -0 $WOKWI_PID 2>/dev/null; then
89+
echo "Error: Wokwi simulator process died"
90+
echo "Last 50 lines of Wokwi log:"
91+
tail -50 logs/wokwi.log || true
92+
exit 1
93+
fi
94+
echo "Still waiting... ($elapsed seconds)"
95+
sleep 5
96+
elapsed=$((elapsed + 5))
8797
done
8898
89-
if [ $elapsed -ge $timeout ]; then
90-
echo "Error: Web server did not start within $timeout seconds"
99+
if [ $elapsed -ge $max_wait ]; then
100+
echo "Error: Web server did not start within $max_wait seconds"
101+
echo "Last 50 lines of Wokwi log:"
102+
tail -50 logs/wokwi.log || true
103+
kill $WOKWI_PID || true
91104
exit 1
92105
fi
106+
107+
echo "WLED is ready for testing!"
93108
94109
- name: Run Playwright tests
95110
run: npm run test:wokwi
@@ -117,6 +132,7 @@ jobs:
117132
with:
118133
name: wokwi-test-results
119134
path: |
135+
test/wokwi/logs/
120136
test-results/
121137
playwright-report/
122138
retention-days: 7

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,5 @@ _codeql_detected_source_root
3838
/test/wokwi/firmware.bin
3939
/test/wokwi/firmware.elf
4040
/test/wokwi/.wokwi/
41+
/test/wokwi/logs/
4142

playwright.config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { defineConfig, devices } from '@playwright/test';
1+
const { defineConfig, devices } = require('@playwright/test');
22

33
/**
44
* Playwright configuration for WLED-MM Wokwi testing
55
* See https://playwright.dev/docs/test-configuration.
66
*/
7-
export default defineConfig({
7+
module.exports = defineConfig({
88
testDir: './test/playwright',
99

1010
/* Run tests in files in parallel */

test/playwright/wokwi-basic.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { test, expect } from '@playwright/test';
1+
const { test, expect } = require('@playwright/test');
22

33
/**
44
* Basic WLED-MM Web Interface Tests

test/wokwi/run-simulator.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ fi
1818

1919
echo "Starting Wokwi simulator..."
2020
echo "Timeout: ${WOKWI_TIMEOUT} seconds"
21+
echo "Web server will be available at http://localhost:8080"
2122

22-
# Run wokwi-cli with timeout
23+
# Run wokwi-cli with timeout (in milliseconds)
2324
# The simulator will forward port 80 to localhost:8080
25+
# Note: wokwi-cli runs in foreground, so this needs to be backgrounded or run in a separate process
2426
wokwi-cli --timeout ${WOKWI_TIMEOUT}000 diagram.json

0 commit comments

Comments
 (0)