Skip to content

ci(react-sdk): add contract tests#1160

Merged
joker23 merged 6 commits intomainfrom
skz/sdk-1773/react-contract-test
Mar 9, 2026
Merged

ci(react-sdk): add contract tests#1160
joker23 merged 6 commits intomainfrom
skz/sdk-1773/react-contract-test

Conversation

@joker23
Copy link
Contributor

@joker23 joker23 commented Mar 6, 2026

This PR will add the initial contract tests for react sdk

Current limitation of the contract tests is that they are basically just testing the underlying browser sdk. We will iterate these tests to be more idiomatic to the react SDK.


Open with Devin

Note

Medium Risk
Moderate risk due to new CI execution steps (Playwright install, background services, harness integration) that can introduce flakiness or longer runtimes, though runtime SDK code is largely untouched.

Overview
Adds React SDK contract tests by introducing a new packages/sdk/react/contract-tests workspace that runs a Next.js “entity” controlled via a WebSocket bridge, executes core SDK commands (flag evaluation, identify/track/flush), and supports hook callbacks for test verification.

Updates the React GitHub Actions workflow to install/build the adapter + contract-test workspace, install Playwright Chromium, start adapter/entity/browser processes, run the shared contract-tests action with a suppressions.txt, and always clean up background services. Also adds React contract-test-specific ESLint/TS config and bumps React SDK dev typings to React 19 (@types/react, @types/react-dom).

Written by Cursor Bugbot for commit c6c4040. This will update automatically on new commits. Configure here.

@joker23 joker23 requested a review from a team as a code owner March 6, 2026 17:57
@github-actions
Copy link
Contributor

github-actions bot commented Mar 6, 2026

@launchdarkly/js-sdk-common size report
This is the brotli compressed size of the ESM build.
Compressed size: 25566 bytes
Compressed size limit: 26000
Uncompressed size: 125383 bytes

@github-actions
Copy link
Contributor

github-actions bot commented Mar 6, 2026

@launchdarkly/browser size report
This is the brotli compressed size of the ESM build.
Compressed size: 172130 bytes
Compressed size limit: 200000
Uncompressed size: 800872 bytes

@github-actions
Copy link
Contributor

github-actions bot commented Mar 6, 2026

@launchdarkly/js-client-sdk size report
This is the brotli compressed size of the ESM build.
Compressed size: 24212 bytes
Compressed size limit: 25000
Uncompressed size: 83755 bytes

@github-actions
Copy link
Contributor

github-actions bot commented Mar 6, 2026

@launchdarkly/js-client-sdk-common size report
This is the brotli compressed size of the ESM build.
Compressed size: 21281 bytes
Compressed size limit: 24000
Uncompressed size: 110213 bytes

devin-ai-integration[bot]

This comment was marked as resolved.

cursor[bot]

This comment was marked as resolved.

cursor[bot]

This comment was marked as resolved.

devin-ai-integration[bot]

This comment was marked as resolved.

cursor[bot]

This comment was marked as resolved.

@joker23 joker23 force-pushed the skz/sdk-1773/react-contract-test branch 2 times, most recently from 28e9506 to 88315e6 Compare March 6, 2026 20:20
cursor[bot]

This comment was marked as resolved.

@joker23 joker23 force-pushed the skz/sdk-1773/react-contract-test branch from 88315e6 to fd066db Compare March 6, 2026 20:43
devin-ai-integration[bot]

This comment was marked as resolved.

@joker23 joker23 force-pushed the skz/sdk-1773/react-contract-test branch 4 times, most recently from f582c85 to 50833ff Compare March 6, 2026 22:13
cursor[bot]

This comment was marked as resolved.

@joker23 joker23 force-pushed the skz/sdk-1773/react-contract-test branch from 50833ff to 9d0544a Compare March 6, 2026 22:20
@joker23 joker23 marked this pull request as draft March 6, 2026 22:22
@joker23 joker23 force-pushed the skz/sdk-1773/react-contract-test branch 5 times, most recently from 8dcb7b8 to 0c9f3f2 Compare March 7, 2026 00:32
@joker23 joker23 force-pushed the skz/sdk-1773/react-contract-test branch 2 times, most recently from 080fdde to 28d9696 Compare March 7, 2026 04:58
@joker23 joker23 force-pushed the skz/sdk-1773/react-contract-test branch from 28d9696 to a16497c Compare March 7, 2026 05:20
@joker23 joker23 force-pushed the skz/sdk-1773/react-contract-test branch from 24fbd6d to c6c4040 Compare March 9, 2026 17:42
@joker23
Copy link
Contributor Author

joker23 commented Mar 9, 2026

@cursor review

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

record.client.close();
}
return prev.filter((r) => r.id !== id);
});
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Side effect in state updater causes double-close

Medium Severity

The onDeleteClient callback calls record.client.close() inside the setClients state updater function. This is a side effect in what React expects to be a pure function. Since the contract tests run via next dev (React Strict Mode is enabled by default), React will double-invoke the updater function during development, causing close() to be called twice on the same client. The side effect (close()) needs to be performed outside the state updater.

Fix in Cursor Fix in Web

@joker23
Copy link
Contributor Author

joker23 commented Mar 9, 2026

@cursor review

@joker23 joker23 marked this pull request as ready for review March 9, 2026 19:10

// NOTE: we can make this more idiomatic to React by creating a useCommand hook and reading return values from
// a rendered component. But for now, this is just a simple way to get the tests running.
export async function doCommand(client: LDReactClient, params: CommandParams): Promise<unknown> {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right now this is more or less the same as the browser contract test

@@ -0,0 +1,176 @@
import { LDContext, LDEvaluationReason } from '@launchdarkly/react-sdk';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right now this is more or less the same as the browser contract test

@@ -0,0 +1,90 @@
import { LDContext } from '@launchdarkly/react-sdk';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as browser contract tests

@@ -0,0 +1,22 @@
import { LDLogger } from '@launchdarkly/react-sdk';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as browser contract tests

@@ -0,0 +1,110 @@
import { LDLogger } from '@launchdarkly/react-sdk';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as browser contract tests

@@ -0,0 +1,94 @@
import {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as browser contract tests

@@ -0,0 +1,54 @@
#!/usr/bin/env node
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as browser contract tests

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as browser contract tests

@joker23 joker23 merged commit e46476e into main Mar 9, 2026
39 checks passed
@joker23 joker23 deleted the skz/sdk-1773/react-contract-test branch March 9, 2026 19:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants