Skip to content

Commit 9f12319

Browse files
committed
Combine workflows. Add readme.
1 parent a6948c6 commit 9f12319

File tree

3 files changed

+144
-124
lines changed

3 files changed

+144
-124
lines changed

.github/workflows/browser-contract-tests.yml

Lines changed: 0 additions & 124 deletions
This file was deleted.

.github/workflows/browser.yml

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,94 @@ jobs:
4242
package_name: '@launchdarkly/js-client-sdk'
4343
pr_number: ${{ github.event.number }}
4444
size_limit: 25000
45+
46+
# Contract Tests
47+
- name: Install Playwright browsers
48+
run: npx playwright install --with-deps chromium
49+
50+
- name: Install contract test dependencies
51+
run: |
52+
yarn workspace browser-contract-test-adapter install --no-immutable
53+
yarn workspace browser-contract-test-service install --no-immutable
54+
55+
- name: Build contract test adapter
56+
run: yarn workspace browser-contract-test-adapter run build
57+
58+
- name: Build contract test entity (browser app)
59+
run: yarn workspace browser-contract-test-service run build
60+
61+
- name: Start contract test adapter in background
62+
run: |
63+
yarn workspace browser-contract-test-adapter run start > /tmp/adapter.log 2>&1 &
64+
echo $! > /tmp/adapter.pid
65+
66+
- name: Serve browser app with http-server
67+
run: |
68+
npx http-server packages/sdk/browser/contract-tests/entity/dist -p 5173 --cors > /tmp/http-server.log 2>&1 &
69+
echo $! > /tmp/http-server.pid
70+
71+
- name: Wait for services to be ready
72+
run: |
73+
echo "Waiting for adapter on port 8001..."
74+
for i in {1..30}; do
75+
if nc -z localhost 8001; then
76+
echo "Adapter WebSocket ready"
77+
break
78+
fi
79+
if [ $i -eq 30 ]; then
80+
echo "Timeout waiting for adapter"
81+
cat /tmp/adapter.log
82+
exit 1
83+
fi
84+
sleep 1
85+
done
86+
87+
echo "Waiting for HTTP server on port 5173..."
88+
for i in {1..30}; do
89+
if curl -s http://localhost:5173 > /dev/null; then
90+
echo "HTTP server ready"
91+
break
92+
fi
93+
if [ $i -eq 30 ]; then
94+
echo "Timeout waiting for HTTP server"
95+
cat /tmp/http-server.log
96+
exit 1
97+
fi
98+
sleep 1
99+
done
100+
101+
- name: Open browser app in headless Chromium
102+
run: |
103+
node packages/sdk/browser/contract-tests/open-browser.mjs http://localhost:5173 > /tmp/playwright.log 2>&1 &
104+
echo $! > /tmp/playwright.pid
105+
sleep 5 # Give the browser time to initialize and connect via WebSocket
106+
107+
- name: Run contract tests
108+
run: |
109+
mkdir -p /tmp/sdk-test-harness
110+
git clone https://github.com/launchdarkly/sdk-test-harness.git /tmp/sdk-test-harness
111+
cd /tmp/sdk-test-harness
112+
go build -o test-harness .
113+
./test-harness -url http://localhost:8000 -debug -stop-service-at-end --skip-from=$GITHUB_WORKSPACE/packages/sdk/browser/contract-tests/suppressions.txt
114+
env:
115+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
116+
117+
- name: Print logs on failure
118+
if: failure()
119+
run: |
120+
echo "=== Adapter Log ==="
121+
cat /tmp/adapter.log || echo "No adapter log"
122+
echo "=== HTTP Server Log ==="
123+
cat /tmp/http-server.log || echo "No http-server log"
124+
echo "=== Playwright Log ==="
125+
cat /tmp/playwright.log || echo "No playwright log"
126+
127+
- name: Cleanup contract test services
128+
if: always()
129+
run: |
130+
[ -f /tmp/playwright.pid ] && kill $(cat /tmp/playwright.pid) || true
131+
[ -f /tmp/http-server.pid ] && kill $(cat /tmp/http-server.pid) || true
132+
[ -f /tmp/adapter.pid ] && kill $(cat /tmp/adapter.pid) || true
133+
pkill -f "playwright" || true
134+
pkill -f "http-server" || true
135+
pkill -f "browser-contract-test-adapter" || true
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Browser SDK Contract Tests
2+
3+
This directory contains the contract test implementation for the LaunchDarkly Browser SDK using the [SDK Test Harness](https://github.com/launchdarkly/sdk-test-harness).
4+
5+
## Architecture
6+
7+
The browser contract tests consist of three components:
8+
9+
1. **Adapter** (`adapter/`): A Node.js server that:
10+
- Exposes a REST API on port 8000 for the test harness
11+
- Runs a WebSocket server on port 8001 for browser communication
12+
- Translates REST commands to WebSocket messages
13+
14+
2. **Entity** (`entity/`): A browser application (Vite app) that:
15+
- Connects to the adapter via WebSocket
16+
- Implements the actual SDK test logic
17+
- Runs the Browser SDK in a real browser environment
18+
19+
3. **Test Harness**: The SDK test harness that:
20+
- Sends test commands via REST API to the adapter (port 8000)
21+
- Validates SDK behavior across different scenarios
22+
23+
## Running Locally
24+
25+
### Prerequisites
26+
27+
- Node.js 18 or later
28+
- Yarn
29+
- A modern browser (for manual testing)
30+
31+
### Quick Start
32+
33+
```bash
34+
# From the repository root
35+
./packages/sdk/browser/contract-tests/run-test-service.sh
36+
```
37+
38+
This script will:
39+
1. Start the adapter (WebSocket bridge)
40+
2. Start the entity (browser app with Vite dev server)
41+
3. Open the browser app in your default browser
42+
43+
The services will be available at:
44+
- Adapter REST API: http://localhost:8000
45+
- Adapter WebSocket: ws://localhost:8001
46+
- Browser App: http://localhost:5173
47+
48+
You then run the `sdk-test-harness`. More information is available here: https://github.com/launchdarkly/sdk-test-harness
49+
50+
Example with local clone of the test harness:
51+
```bash
52+
go run . --url http://localhost:8123 -skip-from path-to-your-js-core-clone/packages/sdk/browser/contract-tests/suppressions.txt
53+
```

0 commit comments

Comments
 (0)