Skip to content
This repository has been archived by the owner on Oct 29, 2024. It is now read-only.

prepare 7.0.0 release #182

Merged
merged 1 commit into from
Feb 24, 2023
Merged
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
69 changes: 23 additions & 46 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ jobs:

macos:
xcode: <<parameters.xcode-version>>
resource_class: macos.x86.medium.gen2
resource_class: large

environment:
ANDROID_SDK_ROOT: "/tmp/Android"
ANDROID_SDK_ROOT: '/tmp/Android'

steps:
- checkout
Expand Down Expand Up @@ -49,16 +49,6 @@ jobs:
mkdir -p test
cd test
[ -d "CITest" ] || npx react-native@<<parameters.rn-version>> init CITest --version <<parameters.rn-version>> --skip-install

# HACK: rn 0.64.x init the test project targeting ios 10, which is incompatible with the ios SDK which requires
# a minimum of ios 11
sed -i.bak "s/platform :ios, '10.0'/platform :ios, '11.0'/" CITest/ios/Podfile
sed -i.bak "s/IPHONEOS_DEPLOYMENT_TARGET = 10.0;/IPHONEOS_DEPLOYMENT_TARGET = 11.0;/" CITest/ios/CITest.xcodeproj/project.pbxproj

#HACK: force rn android 0.64.x init to use minSdkVersion 30 to pass the build
sed -i.bak 's/buildToolsVersion = "29.0.3"/buildToolsVersion = "30.0.2"/' CITest/android/build.gradle
sed -i.bak "s/compileSdkVersion = 29/compileSdkVersion = 31/" CITest/android/build.gradle
sed -i.bak "s/targetSdkVersion = 29/targetSdkVersion = 31/" CITest/android/build.gradle

- save_cache:
name: Save RN project template to cache
Expand All @@ -75,7 +65,15 @@ jobs:

- run:
name: Add LaunchDarkly dependency
command: cd ../test/CITest && npx yarn add file:../../project
command: |
cd ../test/CITest && npx yarn add file:../../project
cd node_modules/launchdarkly-react-native-client-sdk/ios
rm -rf LaunchdarklyReactNativeClient.xcworkspace
rm -rf build
rm -rf Pods
rm -rf Tests
rm -rf Podfile
rm -rf Podfile.lock

- restore_cache:
name: Restore gem cache
Expand Down Expand Up @@ -110,7 +108,7 @@ jobs:
- when:
# We only care to build Android application and debug iOS Build for a single XCode version
condition:
equal: [ 13.2.1, << parameters.xcode-version >> ]
equal: [13.2.1, << parameters.xcode-version >>]
steps:
- run:
name: Build application for iOS (Debug)
Expand All @@ -124,43 +122,22 @@ jobs:
- store_artifacts:
path: artifacts

test-javascript:
docker:
- image: cimg/node:current
steps:
- checkout

- run: npm install
- run: mkdir -p reports/jest
- run:
command: npm run test:junit
environment:
JEST_JUNIT_OUTPUT_DIR: "./reports/jest"

- run: npm run check-typescript

- store_test_results:
path: reports

workflows:
version: 2
all-tests:
install-sdk-build-app:
jobs:
- test-javascript
- build-applications-using-template:
name: rn<<matrix.rn-version>>-xc<<matrix.xcode-version>>-build-apps-using-template
matrix:
parameters:
rn-version: [ "0.64.4", "0.65.2", "0.66.4", "0.67.3", "0.68.0","0.69.4", "0.70.1" ]
xcode-version: [ "12.5.1", "13.2.1", "13.4.1", "14.0.1" ]
rn-version: ['0.69.4', '0.70.1']
xcode-version: ['12.5.1', '13.2.1', '13.4.1', '14.0.1']
exclude:
- rn-version: "0.64.4"
xcode-version: "13.4.1"
- rn-version: "0.64.4"
xcode-version: "14.0.1"
- rn-version: "0.65.2"
xcode-version: "13.4.1"
- rn-version: "0.65.2"
xcode-version: "14.0.1"
requires:
- test-javascript
- rn-version: '0.69.4'
xcode-version: '13.4.1'
- rn-version: '0.69.4'
xcode-version: '14.0.1'
- rn-version: '0.70.1'
xcode-version: '13.4.1'
- rn-version: '0.70.1'
xcode-version: '14.0.1'
68 changes: 68 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
name: Tests
on: [push]

jobs:
tsc:
runs-on: ubuntu-latest
name: Typescript
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: '16.x'
cache: 'yarn'
- run: yarn && yarn tsc

js-tests:
runs-on: ubuntu-latest
name: JS tests
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: '16.x'
cache: 'yarn'
- run: yarn && yarn test

android-tests:
runs-on: ubuntu-latest
name: Android tests
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: '16.x'
cache: 'yarn'
- run: yarn && cd android && ./gradlew test

# ripped from these two places:
# https://vmois.dev/xcode-github-actions/
# https://gist.github.com/ricardopereira/10198e68f27c14601d77ebc7a8352da1
ios-tests:
runs-on: macOS-latest
strategy:
matrix:
destination: ['platform=iOS Simulator,name=iPhone 13,OS=16.2']
name: iOS tests
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: '16.x'
cache: 'yarn'
- uses: actions/cache@v3
id: cocoapods-cache
with:
path: ios/Pods
key: ${{ runner.os }}-pods-${{ hashFiles('**/Podfile.lock') }}
restore-keys: |
${{ runner.os }}-pods-
- name: CocoaPods
if: steps.cocoapods-cache.outputs.cache-hit != 'true'
run: cd ios && yarn && pod install
- name: Select Xcode
run: sudo xcode-select -switch /Applications/Xcode_14.2.app && /usr/bin/xcodebuild -version
- name: Run tests
run: cd ios && xcodebuild -quiet -workspace LaunchdarklyReactNativeClient.xcworkspace -scheme LaunchdarklyReactNativeClient -sdk iphonesimulator -destination "${destination}" test | xcpretty && exit ${PIPESTATUS[0]}
env:
destination: ${{ matrix.destination }}
5 changes: 5 additions & 0 deletions .ldrelease/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ repo:
public: react-native-client-sdk
private: react-native-client-sdk-private

branches:
- name: main
description: 7.x
- name: 6.x

publications:
- url: https://www.npmjs.com/package/launchdarkly-react-native-client-sdk
description: npm
Expand Down
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CHANGELOG.md
89 changes: 61 additions & 28 deletions ManualTestApp/App.js → ManualTestApp/App.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import React, { useState, useEffect } from 'react';
import { useState, useEffect, ReactNode } from 'react';
import { SafeAreaView, ScrollView, StyleSheet, Text, View, Button, TextInput, Alert, Switch } from 'react-native';
import { Picker } from '@react-native-picker/picker';
import LDClient from 'launchdarkly-react-native-client-sdk';
import MessageQueue from 'react-native/Libraries/BatchedBridge/MessageQueue.js';
import LDClient, { LDMultiKindContext } from 'launchdarkly-react-native-client-sdk';
import MessageQueue from 'react-native/Libraries/BatchedBridge/MessageQueue';

const Wrapper = ({ children }): Node => {
const Wrapper = ({ children }: { children: ReactNode }) => {
const styles = {
scroll: { backgroundColor: '#fff', padding: 10 },
area: { backgroundColor: '#fff', flex: 1 },
Expand All @@ -17,11 +17,11 @@ const Wrapper = ({ children }): Node => {
};

const Body = () => {
const [client, setClient] = useState(null);
const [client, setClient] = useState<LDClient | null>(null);
const [flagKey, setFlagKey] = useState('dev-test-flag');
const [flagType, setFlagType] = useState('bool');
const [isOffline, setIsOffline] = useState(false);
const [userKey, setUserKey] = useState('user key');
const [contextKey, setContextKey] = useState('context-key');
const [listenerKey, setListenerKey] = useState('');
const [listeners, setListeners] = useState({});

Expand All @@ -36,69 +36,96 @@ const Body = () => {
version: '0.0.1',
},
};
let user = { key: userKey };
const anonymousUserContext = {
kind: 'user',
key: 'user-key-1',
anonymous: true,
};

// A multi-context can contain both anonymous and non-anonymous contexts.
// Here, organization is not anonymous.
const multiContext: LDMultiKindContext = {
kind: 'multi',
user: anonymousUserContext,
org: {
key: 'org-key',
name: 'Example organization name',
_meta: {
privateAttributes: ['address', 'phone'],
},
address: {
street: 'sunset blvd',
postcode: 94105,
},
phone: 5551234,
},
};

try {
await ldClient.configure(config, user);
await ldClient.configure(config, multiContext);
} catch (err) {
console.error(err);
}
setClient(ldClient);
}

if (client == null) {
initializeClient();
initializeClient().then(() => console.log('ld client initialized successfully'));
}
});

const evalFlag = async () => {
let res;
if (flagType === 'bool') {
res = await client.boolVariation(flagKey, false);
res = await client?.boolVariation(flagKey, false);
} else if (flagType === 'string') {
res = await client.stringVariation(flagKey, '');
res = await client?.stringVariation(flagKey, '');
} else if (flagType === 'number') {
res = await client.numberVariation(flagKey, 0.0);
res = await client?.numberVariation(flagKey, 0.0);
} else if (flagType === 'json') {
res = await client.jsonVariation(flagKey, null);
res = await client?.jsonVariation(flagKey, null);
}

Alert.alert('LD Server Response', JSON.stringify(res));
};

const track = () => {
client.track(flagKey, false);
client?.track(flagKey, false);
};

const identify = () => {
client.identify({ key: userKey });
client?.identify({ kind: 'user', key: contextKey });
};

const listen = () => {
if (listeners.hasOwnProperty(listenerKey)) {
return;
}
let listener = (value) => Alert.alert('Listener Callback', value);
client.registerFeatureFlagListener(listenerKey, listener);
let listener = (value: string | undefined) => Alert.alert('Listener Callback', value);
client?.registerFeatureFlagListener(listenerKey, listener);
setListeners({ ...listeners, ...{ [listenerKey]: listener } });
};

const removeListener = () => {
client.unregisterFeatureFlagListener(listenerKey, listeners[listenerKey]);
// @ts-ignore
client?.unregisterFeatureFlagListener(listenerKey, listeners[listenerKey]);
// @ts-ignore
let { [listenerKey]: omit, ...newListeners } = listeners;
setListeners(newListeners);
};

const flush = () => {
client.flush();
client?.flush();
};

const setOffline = (newIsOffline) => {
if (newIsOffline) {
client.setOffline();
const setOffline = (offline: boolean) => {
if (offline) {
client?.setOffline();
} else {
client.setOnline();
client?.setOnline();
}
setIsOffline(newIsOffline);

setIsOffline(offline);
};

return (
Expand All @@ -116,8 +143,8 @@ const Body = () => {
<Text>Offline</Text>
<Switch value={isOffline} onValueChange={setOffline} />
</View>
<Text>User Key:</Text>
<TextInput style={styles.input} onChangeText={setUserKey} value={userKey} autoCapitalize="none" />
<Text>Context key:</Text>
<TextInput style={styles.input} onChangeText={setContextKey} value={contextKey} autoCapitalize="none" />
<View style={styles.row}>
<Button title="Identify" onPress={identify} />
<Button title="Track" onPress={track} />
Expand Down Expand Up @@ -155,11 +182,17 @@ const App = () => {
};

MessageQueue.spy((msg) => {
if (msg.module != 'LaunchdarklyReactNativeClient' && !msg.method.includes('LaunchdarklyReactNativeClient')) {
if (
msg.module != 'LaunchdarklyReactNativeClient' &&
typeof msg.method !== 'number' &&
!msg.method.includes('LaunchdarklyReactNativeClient')
) {
return;
}
let logMsg = msg.type === 0 ? 'N->JS: ' : 'JS->N: ';
logMsg += msg.method.replace('LaunchdarklyReactNativeClient.', '');
if (typeof msg.method !== 'number') {
logMsg += msg.method.replace('LaunchdarklyReactNativeClient.', '');
}

let params = [...msg.args];
if (params.length >= 2) {
Expand Down
Loading