-
Notifications
You must be signed in to change notification settings - Fork 31
chore: Run browser contract tests in CI. #1001
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
a6948c6
chore: Run browser contract tests in CI.
kinyoklion 9f12319
Combine workflows. Add readme.
kinyoklion 7d20d35
Merge branch 'main' into rlamb/browser-conrtact-tests
kinyoklion af08f94
Run tests using shared action.
kinyoklion e035f91
Playwright tweaks.
kinyoklion f7d755b
Try installing from package script.
kinyoklion File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| # Browser SDK Contract Tests | ||
|
|
||
| This directory contains the contract test implementation for the LaunchDarkly Browser SDK using the [SDK Test Harness](https://github.com/launchdarkly/sdk-test-harness). | ||
|
|
||
| ## Architecture | ||
|
|
||
| The browser contract tests consist of three components: | ||
|
|
||
| 1. **Adapter** (`adapter/`): A Node.js server that: | ||
| - Exposes a REST API on port 8000 for the test harness | ||
| - Runs a WebSocket server on port 8001 for browser communication | ||
| - Translates REST commands to WebSocket messages | ||
|
|
||
| 2. **Entity** (`entity/`): A browser application (Vite app) that: | ||
| - Connects to the adapter via WebSocket | ||
| - Implements the actual SDK test logic | ||
| - Runs the Browser SDK in a real browser environment | ||
|
|
||
| 3. **Test Harness**: The SDK test harness that: | ||
| - Sends test commands via REST API to the adapter (port 8000) | ||
| - Validates SDK behavior across different scenarios | ||
|
|
||
| ## Running Locally | ||
|
|
||
| ### Prerequisites | ||
|
|
||
| - Node.js 18 or later | ||
| - Yarn | ||
| - A modern browser (for manual testing) | ||
|
|
||
| ### Quick Start | ||
|
|
||
| ```bash | ||
| # From the repository root | ||
| ./packages/sdk/browser/contract-tests/run-test-service.sh | ||
| ``` | ||
|
|
||
| This script will: | ||
| 1. Start the adapter (WebSocket bridge) | ||
| 2. Start the entity (browser app with Vite dev server) | ||
| 3. Open the browser app in your default browser | ||
|
|
||
| The services will be available at: | ||
| - Adapter REST API: http://localhost:8000 | ||
| - Adapter WebSocket: ws://localhost:8001 | ||
| - Browser App: http://localhost:5173 | ||
|
|
||
| You then run the `sdk-test-harness`. More information is available here: https://github.com/launchdarkly/sdk-test-harness | ||
|
|
||
| Example with local clone of the test harness: | ||
| ```bash | ||
| go run . --url http://localhost:8123 -skip-from path-to-your-js-core-clone/packages/sdk/browser/contract-tests/suppressions.txt | ||
| ``` |
42 changes: 42 additions & 0 deletions
42
packages/sdk/browser/contract-tests/entity/open-browser.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| #!/usr/bin/env node | ||
|
|
||
| /** | ||
| * Opens a headless browser and navigates to the contract test entity page. | ||
| * Keeps the browser open until the process is terminated. | ||
| * | ||
| * Usage: node open-browser.mjs [url] | ||
| * Default URL: http://localhost:5173 | ||
| */ | ||
|
|
||
| import { chromium } from 'playwright'; | ||
|
|
||
| const url = process.argv[2] || 'http://localhost:5173'; | ||
|
|
||
| console.log(`Opening headless browser at ${url}...`); | ||
|
|
||
| const browser = await chromium.launch({ | ||
| headless: true, | ||
| args: ['--no-sandbox', '--disable-setuid-sandbox'] | ||
| }); | ||
|
|
||
| const context = await browser.newContext(); | ||
| const page = await context.newPage(); | ||
|
|
||
| // Log console messages from the browser | ||
| page.on('console', (msg) => { | ||
| console.log(`[Browser Console] ${msg.type()}: ${msg.text()}`); | ||
| }); | ||
|
|
||
| // Log page errors | ||
| page.on('pageerror', (error) => { | ||
| console.error(`[Browser Error] ${error.message}`); | ||
| }); | ||
|
|
||
| await page.goto(url); | ||
|
|
||
| console.log('Browser is open and running. Press Ctrl+C to close.'); | ||
|
|
||
| // Keep the process alive | ||
| await new Promise(() => { | ||
| // Intentionally never resolve - keeps browser open until process is killed | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.