Skip to content

Commit cb9d158

Browse files
test(js-client-sdk): adding hello app test (#1158)
**Requirements** - [x] I have added test coverage for new or changed functionality - [x] I have followed the repository's [pull request submission guidelines](../blob/main/CONTRIBUTING.md#submitting-pull-requests) - [x] I have validated my changes against all supported platform versions **Related issues** sdk-1910 **Describe the solution you've provided** added the test **Additional context** I deviated a bit from the specs and read the flag value from the UI. I think we should update the specs to include this as a way to verify. <!-- devin-review-badge-begin --> --- <a href="https://app.devin.ai/review/launchdarkly/js-core/pull/1158" target="_blank"> <picture> <source media="(prefers-color-scheme: dark)" srcset="https://static.devin.ai/assets/gh-open-in-devin-review-dark.svg?v=1"> <img src="https://static.devin.ai/assets/gh-open-in-devin-review-light.svg?v=1" alt="Open with Devin"> </picture> </a> <!-- devin-review-badge-end --> <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Medium Risk** > Adds new Playwright-based e2e execution to CI (including a new nightly workflow) and changes example env var expectations, which could cause CI failures or scheduled runs to break if secrets/roles or placeholders don’t match. > > **Overview** > Adds a Playwright e2e smoke test for `@launchdarkly/browser-example` (with new `playwright.config.ts`, `e2e/verify.spec.ts`, and `yarn test` script/deps) that verifies the page reports the flag evaluates to `true`. > > Updates the example’s configuration to use `LAUNCHDARKLY_CLIENT_SIDE_ID`/`LAUNCHDARKLY_FLAG_KEY` in `.env.template`, README, and `tsdown.config.ts` placeholder replacement. > > Extends GitHub Actions to run the browser example test as part of `browser.yml` and introduces a new scheduled `browser-nightly.yaml` workflow that runs the same example job daily (including installing Chromium via Playwright). > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit f21bfcb. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY --> --------- Co-authored-by: devin-ai-integration[bot] <158243242+devin-ai-integration[bot]@users.noreply.github.com>
1 parent c0ec2d2 commit cb9d158

8 files changed

Lines changed: 77 additions & 13 deletions

File tree

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: sdk/browser nightly
2+
3+
on:
4+
schedule:
5+
- cron: '0 0 * * *'
6+
7+
jobs:
8+
run-example:
9+
runs-on: ubuntu-latest
10+
permissions:
11+
id-token: write
12+
steps:
13+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
14+
- uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6.3.0
15+
with:
16+
node-version: 22
17+
- uses: ./actions/run-example
18+
with:
19+
workspace_name: '@launchdarkly/browser-example'
20+
aws_assume_role: ${{ vars.AWS_ROLE_ARN }}
21+
before_test: 'yarn workspace @launchdarkly/browser-example playwright install --with-deps chromium'

.github/workflows/browser.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,3 +131,18 @@ jobs:
131131
pkill -f "playwright" || true
132132
pkill -f "http-server" || true
133133
pkill -f "browser-contract-test-adapter" || true
134+
135+
run-example:
136+
runs-on: ubuntu-latest
137+
permissions:
138+
id-token: write
139+
steps:
140+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
141+
- uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6.3.0
142+
with:
143+
node-version: 22
144+
- uses: ./actions/run-example
145+
with:
146+
workspace_name: '@launchdarkly/browser-example'
147+
aws_assume_role: ${{ vars.AWS_ROLE_ARN }}
148+
before_test: 'yarn workspace @launchdarkly/browser-example playwright install --with-deps chromium'
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
# Set LD_CLIENT_SIDE_ID to your LaunchDarkly client-side ID
2-
LD_CLIENT_SIDE_ID=
1+
# Set LAUNCHDARKLY_CLIENT_SIDE_ID to your LaunchDarkly client-side ID
2+
LAUNCHDARKLY_CLIENT_SIDE_ID=
33

4-
# Set LD_FLAG_KEY to the feature flag key you want to evaluate
5-
LD_FLAG_KEY=
4+
# Set LAUNCHDARKLY_FLAG_KEY to the feature flag key you want to evaluate
5+
LAUNCHDARKLY_FLAG_KEY=

packages/sdk/browser/example/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ Nodejs 20.6.0 or later
1818
1919
2. Set the variables in `.env` to your specific LD values
2020
```
21-
# Set LD_CLIENT_SIDE_ID to your LaunchDarkly client-side ID
22-
LD_CLIENT_SIDE_ID=
21+
# Set LAUNCHDARKLY_CLIENT_SIDE_ID to your LaunchDarkly client-side ID
22+
LAUNCHDARKLY_CLIENT_SIDE_ID=
2323
24-
# Set LD_FLAG_KEY to the feature flag key you want to evaluate
25-
LD_FLAG_KEY=
24+
# Set LAUNCHDARKLY_FLAG_KEY to the feature flag key you want to evaluate
25+
LAUNCHDARKLY_FLAG_KEY=
2626
```
2727
> [!NOTE]
2828
> Setting these values is equivilent to modifying the `clientSideID` and `flagKey`
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// eslint-disable-next-line import/no-extraneous-dependencies
2+
import { expect, test as it } from '@playwright/test';
3+
4+
it('evaluates the feature flag to true', async ({ page }) => {
5+
await page.goto('/');
6+
await expect(page.locator('body')).toContainText('feature flag evaluates to true', {
7+
timeout: 20_000,
8+
});
9+
});

packages/sdk/browser/example/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,15 @@
1414
"scripts": {
1515
"start": "open index.html",
1616
"clean": "rm -rf dist dist-static",
17-
"build": "npm run clean && tsdown"
17+
"build": "npm run clean && tsdown",
18+
"test": "playwright test"
1819
},
1920
"dependencies": {
2021
"@launchdarkly/js-client-sdk": "workspace:^"
2122
},
2223
"devDependencies": {
24+
"@playwright/test": "^1.49.1",
25+
"playwright": "^1.49.1",
2326
"tsdown": "^0.17.0-beta.4",
2427
"typescript": "^5.9.3"
2528
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// eslint-disable-next-line import/no-extraneous-dependencies
2+
import { defineConfig } from '@playwright/test';
3+
4+
export default defineConfig({
5+
testDir: './e2e',
6+
timeout: 30_000,
7+
reporter: [['list']],
8+
use: {
9+
baseURL: 'http://localhost:4173',
10+
},
11+
webServer: {
12+
command: 'npx http-server . -p 4173 --silent',
13+
url: 'http://localhost:4173',
14+
reuseExistingServer: !process.env.CI,
15+
},
16+
});

packages/sdk/browser/example/tsdown.config.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ if (fs.existsSync('.env')) {
1010

1111
const ENTRY_FILE = path.join('src', 'app.ts');
1212
const OUTPUT_FILE = path.join('dist', 'app.js');
13-
const { LD_CLIENT_SIDE_ID, LD_FLAG_KEY } = process.env;
13+
const { LAUNCHDARKLY_CLIENT_SIDE_ID, LAUNCHDARKLY_FLAG_KEY } = process.env;
1414

1515
const CLIENT_SIDE_ID_PLACEHOLDER = 'LD_CLIENT_SIDE_ID';
1616
const FLAG_KEY_PLACEHOLDER = 'LD_FLAG_KEY';
@@ -22,14 +22,14 @@ export default defineConfig({
2222
noExternal: ['@launchdarkly/js-client-sdk'],
2323
hooks(hooks) {
2424
hooks.hook('build:done', () => {
25-
if (LD_CLIENT_SIDE_ID) {
25+
if (LAUNCHDARKLY_CLIENT_SIDE_ID) {
2626
const content = fs.readFileSync(OUTPUT_FILE).toString();
2727
fs.writeFileSync(
2828
OUTPUT_FILE,
29-
content.replaceAll(CLIENT_SIDE_ID_PLACEHOLDER, LD_CLIENT_SIDE_ID),
29+
content.replaceAll(CLIENT_SIDE_ID_PLACEHOLDER, LAUNCHDARKLY_CLIENT_SIDE_ID),
3030
);
3131
}
32-
const flagKey = LD_FLAG_KEY || 'sample-feature';
32+
const flagKey = LAUNCHDARKLY_FLAG_KEY || 'sample-feature';
3333
const content = fs.readFileSync(OUTPUT_FILE).toString();
3434
fs.writeFileSync(OUTPUT_FILE, content.replaceAll(FLAG_KEY_PLACEHOLDER, flagKey));
3535
});

0 commit comments

Comments
 (0)