Skip to content

Commit 6d94fee

Browse files
committed
add scripts
1 parent 9e5e9e4 commit 6d94fee

2 files changed

Lines changed: 78 additions & 0 deletions

File tree

scripts/capture-logs.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
const CDP = require('chrome-remote-interface');
2+
3+
async function captureLogs() {
4+
// Retry connection until Chrome is ready
5+
let client;
6+
for (let i = 0; i < 30; i++) {
7+
try {
8+
client = await CDP({port: 9222});
9+
break;
10+
} catch (err) {
11+
await new Promise(r => setTimeout(r, 500));
12+
}
13+
}
14+
15+
if (!client) {
16+
console.error('Failed to connect to Chrome on port 9222');
17+
process.exit(1);
18+
}
19+
20+
const {Log, Runtime} = client;
21+
22+
await Log.enable();
23+
await Runtime.enable();
24+
25+
Log.entryAdded((params) => {
26+
const {entry} = params;
27+
console.log(`[LOG:${entry.level}] ${entry.text}`);
28+
});
29+
30+
Runtime.consoleAPICalled((params) => {
31+
const args = params.args.map(arg => arg.value || arg.description || '').join(' ');
32+
console.log(`[CONSOLE:${params.type}] ${args}`);
33+
});
34+
35+
console.error('CDP: Connected and listening for logs...');
36+
}
37+
38+
captureLogs();

scripts/wasm-test-with-logs.sh

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/bin/bash
2+
3+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
4+
5+
# Install chrome-remote-interface if needed
6+
cd "$SCRIPT_DIR"
7+
if [ ! -d "node_modules/chrome-remote-interface" ]; then
8+
npm install chrome-remote-interface
9+
fi
10+
cd - > /dev/null
11+
12+
# Start a background job to check what's listening on 9222
13+
(
14+
sleep 5
15+
echo "=== Checking ports ==="
16+
# Find chromedriver port
17+
DRIVER_PORT=$(lsof -i -P | grep chromedri | grep LISTEN | head -1 | awk '{print $9}' | cut -d: -f2)
18+
echo "Chromedriver port: $DRIVER_PORT"
19+
if [ -n "$DRIVER_PORT" ]; then
20+
echo "Querying chromedriver sessions..."
21+
curl -s http://localhost:$DRIVER_PORT/sessions 2>/dev/null | head -5
22+
fi
23+
# Check what ports Chrome is using
24+
echo "Chrome debug ports:"
25+
lsof -i -P | grep "Google Chrome" | grep LISTEN || echo " none"
26+
echo "=== End port check ==="
27+
) &
28+
CHECK_PID=$!
29+
30+
# Start CDP log capture (will retry until Chrome is up)
31+
node "$SCRIPT_DIR/capture-logs.js" &
32+
CDP_PID=$!
33+
34+
# Cleanup on exit
35+
trap "kill $CDP_PID $CHECK_PID 2>/dev/null" EXIT
36+
37+
# Run the test
38+
CHROMEDRIVER=$(which chromedriver) \
39+
CARGO_TARGET_WASM32_UNKNOWN_UNKNOWN_RUNNER='wasm-bindgen-test-runner' \
40+
cargo +nightly test --target=wasm32-unknown-unknown --lib -- --nocapture

0 commit comments

Comments
 (0)