Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,75 @@ jobs:
github_token: ${{ secrets.GITHUB_TOKEN }}
flutter_version: ${{ matrix.versions.flutter }}
dart_version: ${{ matrix.versions.dart }}

browser-contract-tests:
# Runs the SDK in headless Chrome with the HTTP-based SSE client. The default
# web client cannot send a request body or report an HTTP error.
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Install Dart
uses: dart-lang/setup-dart@e51d8e571e22473a2ddebf0ef8a2123f0ab2c02c # v1
with:
sdk: '3.7.2'

- name: Install Flutter
uses: subosito/flutter-action@0ca7a949e71ae44c8e688a51c5e7e93b2c87e295 # v2
with:
flutter-version: '3.29.3'
channel: 'stable'

- name: Install Melos
shell: bash
run: |
dart pub global activate melos
echo "$HOME/.pub-cache/bin" >> $GITHUB_PATH

- name: Install Dependencies
shell: bash
run: melos bs

- name: Build the browser test entity
shell: bash
run: |
pushd apps/flutter_web_contract_test_service
flutter build web --release --base-href /app/ -t lib/main.dart

- name: Contract Tests (FDv1, browser)
shell: bash
env:
CHROME_EXECUTABLE: /usr/bin/google-chrome
run: |
pushd apps/flutter_web_contract_test_service
dart run bin/adapter.dart > adapter.log 2>&1 & disown
- uses: launchdarkly/gh-actions/actions/contract-tests@contract-tests-v1.3.0
with:
test_service_port: 8080
token: ${{ secrets.GITHUB_TOKEN }}
enable_persistence_tests: false
extra_params: '-status-timeout 100 --skip-from=./apps/flutter_web_contract_test_service/testharness-suppressions.txt'

# The FDv1 run stops the adapter when it finishes, so start it again here.
- name: Contract Tests (FDv2, browser)
shell: bash
env:
CHROME_EXECUTABLE: /usr/bin/google-chrome
run: |
pushd apps/flutter_web_contract_test_service
dart run bin/adapter.dart > adapter-fdv2.log 2>&1 & disown
- uses: launchdarkly/gh-actions/actions/contract-tests@contract-tests-v1.3.0
with:
test_service_port: 8080
token: ${{ secrets.GITHUB_TOKEN }}
version: 'v3'
branch: 'v3'
enable_persistence_tests: false
extra_params: '-status-timeout 100 --skip-from=./apps/flutter_web_contract_test_service/testharness-suppressions-fdv2.txt'

- name: Upload Adapter Logs
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02
if: always()
with:
name: browser-contract-test-adapter-logs
path: apps/flutter_web_contract_test_service/adapter*.log
20 changes: 20 additions & 0 deletions apps/flutter_client_contract_test_service/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,26 @@ $ flutter test bin/contract_test_service.dart
Server listening on port 8080
```

# Running the contract test harness

The service only answers requests. The tests come from the
[sdk-test-harness](https://github.com/launchdarkly/sdk-test-harness).
Leave the service running, and run the harness in a second terminal:

```
$ cd apps/flutter_client_contract_test_service/
$ curl -s https://raw.githubusercontent.com/launchdarkly/sdk-test-harness/main/downloader/run.sh \
| VERSION=v2 PARAMS="-url http://localhost:8080 -debug -status-timeout 100 -stop-service-at-end -skip-from testharness-suppressions.txt" sh
```

This runs the FDv1 tests. To run the FDv2 tests, use `v3` in the URL and set
`VERSION=v3`. The `-stop-service-at-end` option stops the service when the
harness finishes, so start the service again before the next run.
`testharness-suppressions.txt` lists the tests that this service skips.

From the repository root, `melos run client-contract-tests` and
`melos run client-contract-tests-fdv2` do both steps.

# Updating the generated API Classes

If you need to add or modify the OpenAPI yaml files to add or modify functionality, you will then probably need to regenerate the *.openapi.dart and *.openapi.g.dart files. This can be done by running the following command:
Expand Down
60 changes: 60 additions & 0 deletions apps/flutter_web_contract_test_service/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
Contract test service that runs the Flutter SDK in a browser.

The SDK streams with the HTTP-based SSE client (`eventSource: SSEClient.http`),
not with the browser native `EventSource`. The native client cannot send a request
body or report an HTTP error. So this service is the only contract test run
that covers `usePost` and HTTP error handling for streaming on web.

# How it works

The contract test harness speaks REST. A browser cannot listen for HTTP
requests. So the service has two parts:

- `bin/adapter.dart` runs on the Dart VM. It serves the REST API for the
harness, serves the web build, starts headless Chrome, and relays each
request to the browser over a websocket.
- `lib/main.dart` is a Flutter web app. It runs in the browser, connects to
the adapter, and runs each request with the SDK.

The browser tells the adapter which capabilities it has when it connects.
`client-use-post` and `client-event-source-http-errors` need the HTTP-based
SSE client.

# Running it

You need Chrome. The `--chrome` option sets the path to Chrome. Without the
option, the adapter uses the `CHROME_EXECUTABLE` variable. Otherwise it uses
the Chrome app on macOS, and `google-chrome` from your `PATH` on other
platforms.

```
$ cd apps/flutter_web_contract_test_service/
$ flutter build web --release --base-href /app/ -t lib/main.dart
$ dart run bin/adapter.dart
Adapter listening on port 8080
Browser connected
```

Leave the adapter running, and run the
[sdk-test-harness](https://github.com/launchdarkly/sdk-test-harness) in a
second terminal:

```
$ cd apps/flutter_web_contract_test_service/
$ curl -s https://raw.githubusercontent.com/launchdarkly/sdk-test-harness/main/downloader/run.sh \
| VERSION=v2 PARAMS="-url http://localhost:8080 -debug -status-timeout 100 -stop-service-at-end -skip-from testharness-suppressions.txt" sh
```

This runs the FDv1 tests. To run the FDv2 tests, use `v3` in the URL, set
`VERSION=v3`, and skip from `testharness-suppressions-fdv2.txt`. The
`-stop-service-at-end` option stops the adapter when the harness finishes, so
start the adapter again before the next run.

From the repository root, `melos run client-web-contract-tests` (FDv1) and
`melos run client-web-contract-tests-fdv2` (FDv2) build the web app, start the
adapter, and run the harness.

`testharness-suppressions.txt` (FDv1) and `testharness-suppressions-fdv2.txt`
(FDv2) list the harness tests that this service skips. They start from the
lists of the JS browser SDK runs that use the fetch-based event source, and
each file states where it differs.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include: ../../common_analysis.yaml
Loading
Loading