Skip to content
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

chore: Add Detox e2e tests for RN SDK. #376

Merged
merged 33 commits into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
039d05a
chore: Added initial Detox CI config for react-native.
yusinto Feb 8, 2024
2d1d098
chore: Get ssm mobile key.
yusinto Feb 9, 2024
f5c453b
chore: Add instructions to test github actions locally.
yusinto Feb 9, 2024
0d424de
Update README.md
yusinto Feb 9, 2024
1a312b9
Update react-native.yml
yusinto Feb 9, 2024
668b68e
chore: Hardcode xcode version to fix pod install glog error.
yusinto Feb 10, 2024
e78d8ea
Update react-native.yml
yusinto Feb 10, 2024
846d617
Update react-native.yml
yusinto Feb 10, 2024
2fad756
chore: Update osx runner to 14 to use latest xcode.
yusinto Feb 10, 2024
95b161a
chore: Fixing visibility test failure.
yusinto Feb 10, 2024
03ccac0
Update README.md
yusinto Feb 10, 2024
5bfd752
Update package.json
yusinto Feb 10, 2024
84ae6e1
Update package.json
yusinto Feb 10, 2024
b26c65a
Update .detoxrc.js
yusinto Feb 10, 2024
95e6da1
Update starter.test.ts
yusinto Feb 10, 2024
e7874af
chore: Attempt to fix broken variation test.
yusinto Feb 12, 2024
42c17bc
Update react-native.yml
yusinto Feb 12, 2024
fe71d08
Update welcome.tsx
yusinto Feb 12, 2024
16ecb60
chore: Restore build-test job.
yusinto Feb 12, 2024
0ea0b57
chore: Added scrollable output.
yusinto Feb 12, 2024
f55a8b6
Merge branch 'main' into yus/sc-228487/detox-in-ci
yusinto Feb 16, 2024
2d0d4a7
Update react-native.yml
yusinto Feb 16, 2024
fdfabda
Update react-native.yml
yusinto Feb 16, 2024
954a7ca
Update react-native.yml
yusinto Feb 16, 2024
d776b85
Update package.json
yusinto Feb 16, 2024
eacb54e
Update react-native.yml
yusinto Feb 16, 2024
017a574
Update react-native.yml
yusinto Feb 16, 2024
23190fb
fix: Set hoisting limits so example app uses its own external deps.
yusinto Feb 20, 2024
9c23a75
chore: Install only packages for example app.
yusinto Feb 20, 2024
0b10bc8
Update react-native.yml
yusinto Feb 20, 2024
c3c6e17
Update react-native.yml
yusinto Feb 20, 2024
51bbe23
Update react-native.yml
yusinto Feb 20, 2024
3c0aee8
Update react-native.yml
yusinto Feb 20, 2024
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
22 changes: 22 additions & 0 deletions .github/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# LaunchDarkly Github Actions for JavaScript SDKs.

This directory contains Github Actions for building, deploying, releasing
libraries in this monorepo.

## Local testing using act

You can use [act](https://nektosact.com/usage/index.html) to run github actions locally for testing.

1. Install and run Docker.
2. Install act.

```shell
brew install act
```

3. Run a workflow file.

```shell
# To run the react-native build/test/e2e
act -W '.github/workflows/react-native.yml' -P macos-14=-self-hosted
```
64 changes: 62 additions & 2 deletions .github/workflows/react-native.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,71 @@ jobs:
build-test-react-native:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
- id: shared
name: Shared CI Steps
uses: ./actions/ci
with:
workspace_name: '@launchdarkly/react-native-client-sdk'
workspace_path: packages/sdk/react-native
detox-ios:
# macos-latest uses macos-12 and we need macos-14 to get xcode 15.
# https://github.com/actions/runner-images/blob/main/README.md
runs-on: macos-14
permissions:
id-token: write
contents: read
defaults:
run:
working-directory: packages/sdk/react-native/example
steps:
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
- name: Install deps
run: yarn workspaces focus
- name: Build
run: yarn workspaces foreach -pR --topological-dev --from 'react-native-example' run build
- name: Install macOS dependencies
run: |
brew tap wix/brew
brew install applesimutils
env:
HOMEBREW_NO_AUTO_UPDATE: 1
HOMEBREW_NO_INSTALL_CLEANUP: 1

- name: Cache Detox build
id: cache-detox-build
uses: actions/cache@v4
with:
path: ios/build
key: ${{ runner.os }}-detox-build
restore-keys: |
${{ runner.os }}-detox-build

- name: Detox rebuild framework cache
run: yarn detox rebuild-framework-cache

- uses: ./actions/release-secrets
name: 'Get mobile key'
with:
aws_assume_role: ${{ vars.AWS_ROLE_ARN }}
ssm_parameter_pairs: '/sdk/detox/mobile-key = MOBILE_KEY'

- name: Set mobile key
run: echo "MOBILE_KEY=$MOBILE_KEY" > .env

- name: Expo prebuild
# HACK: Deleting ios/.xcode.env.local is needed to solve an xcode build issue with rn 0.73
# https://github.com/facebook/react-native/issues/42112#issuecomment-1884536225
run: |
export NO_FLIPPER=1
yarn expo-prebuild
rm -rf ./ios/.xcode.env.local

- name: Detox build
run: yarn detox build --configuration ios.sim.release

- name: Detox test
run: yarn detox test --configuration ios.sim.release --cleanup --headless --record-logs all --take-screenshots failing
11 changes: 5 additions & 6 deletions packages/sdk/react-native/example/build-run-detox.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
#!/bin/bash

export NO_FLIPPER=1

echo "===== Installing all dependencies"
yarn

echo "===== Rebuild detox cache"
yarn detox rebuild-framework-cache

echo "===== Building native code"
yarn expo-prebuild

Expand All @@ -12,11 +17,5 @@ yarn expo-prebuild
echo "===== Delete .xcode.env.local"
rm -rf ./ios/.xcode.env.local

echo "===== Start metro in background"
yarn start &

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Metro no longer needed in release builds when running e2e.

echo "===== Run ios tests"
yarn detox-ios

echo "===== Exit"
kill -9 $(lsof -t -i:8081)
8 changes: 6 additions & 2 deletions packages/sdk/react-native/example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
"ios-log": "react-native log-ios",
"web": "expo start --web --clear",
"clean": "yarn expo-prebuild && yarn cache clean && rm -rf node_modules && rm -rf .expo",
"detox-build-ios": "detox build -c ios.sim.debug",
"detox-run-ios": "detox test -c ios.sim.debug",
"detox-build-ios": "detox build -c ios.sim.release",
"detox-run-ios": "detox test -c ios.sim.release --cleanup --headless",
Comment on lines +18 to +19
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Use release builds for e2e tests instead of debug builds.

"detox-ios": "yarn detox-build-ios && yarn detox-run-ios",
"test": "./build-run-detox.sh"
},
Expand All @@ -41,5 +41,9 @@
"jest": "^29.7.0",
"ts-jest": "^29.1.1",
"typescript": "^5.2.2"
},
"packageManager": "[email protected]",
"installConfig": {
"hoistingLimits": "workspaces"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Force example app to use its own copies of deps, except for @launchdarkly/* deps. Without this, different versions of the a package like event-target-shim will conflict and result in cryptic metro compilation errors.

}
}
8 changes: 6 additions & 2 deletions packages/sdk/react-native/example/src/welcome.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useState } from 'react';
import { StyleSheet, Text, TextInput, TouchableOpacity, View } from 'react-native';
import { ScrollView, StyleSheet, Text, TextInput, TouchableOpacity, View } from 'react-native';

import { ConnectionMode } from '@launchdarkly/js-client-sdk-common';
import { useBoolVariation, useLDClient } from '@launchdarkly/react-native-client-sdk';
Expand All @@ -20,13 +20,17 @@ export default function Welcome() {
ldc.setConnectionMode(m);
};

const context = ldc.getContext() ?? 'No context identified.';

return (
<View style={styles.container}>
<Text>Welcome to LaunchDarkly</Text>
<Text>
{flagKey}: {`${flagValue}`}
</Text>
<Text>context: {JSON.stringify(ldc.getContext(), null, 2)}</Text>
<ScrollView style={{ flexGrow: 0.2, backgroundColor: 'black', maxHeight: 200 }}>
<Text style={{ color: 'orange' }}>Logging: {JSON.stringify(context, null, 2)}</Text>
</ScrollView>
Comment on lines +31 to +33
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Replace Text with a ScrollView so ui elements don't shift when the json string gets displayed. The shitfing affects UI elements positioning and hence tapping/clicking fails.

<TextInput
style={styles.input}
autoCapitalize="none"
Expand Down
Loading