Skip to content

Commit

Permalink
chore: Add Detox e2e tests for RN SDK. (#376)
Browse files Browse the repository at this point in the history
Runs e2e tests for iOS. Android will follow in a separate PR. Only
contains basic eval and variation tests right now.


![Simulator_Screenshot_-_iPhone_Xs_-_2024-02-12_at_14_04_12](https://github.com/launchdarkly/js-core/assets/1593077/f828a627-e0d0-4a50-b38f-e2098c673433)
  • Loading branch information
yusinto authored Feb 23, 2024
1 parent 7a4ea60 commit eba7284
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 12 deletions.
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 &

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",
"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"
}
}
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>
<TextInput
style={styles.input}
autoCapitalize="none"
Expand Down

0 comments on commit eba7284

Please sign in to comment.