Skip to content

Commit 46e2ab4

Browse files
[FSSDK-10316] crypto and text encoder polyfill addition for React native (#936)
* [FSSDK-10316] crypto and text encoder polyfill addition for React native * dev dep update for test cases * dependency version fix * format fix
1 parent 4909efb commit 46e2ab4

6 files changed

+44
-19
lines changed

__mocks__/fast-text-encoding.ts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export {};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export {};

lib/index.react_native.ts

+3
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ import { createHttpPollingDatafileManager } from './plugins/datafile_manager/rea
2929
import { BrowserOdpManager } from './plugins/odp_manager/index.browser';
3030
import * as commonExports from './common_exports';
3131

32+
import 'fast-text-encoding';
33+
import 'react-native-get-random-values';
34+
3235
const logger = getLogger();
3336
setLogHandler(loggerPlugin.createLogger());
3437
setLogLevel(LogLevel.INFO);

package-lock.json

+17-8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+10-2
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,8 @@
111111
"uuid": "^9.0.1"
112112
},
113113
"devDependencies": {
114+
"@react-native-community/netinfo": "^11.3.2",
114115
"@react-native-async-storage/async-storage": "^1.2.0",
115-
"@react-native-community/netinfo": "^5.9.10",
116116
"@rollup/plugin-commonjs": "^11.0.2",
117117
"@rollup/plugin-node-resolve": "^7.1.1",
118118
"@types/chai": "^4.2.11",
@@ -162,14 +162,22 @@
162162
"peerDependencies": {
163163
"@babel/runtime": "^7.0.0",
164164
"@react-native-async-storage/async-storage": "^1.2.0",
165-
"@react-native-community/netinfo": "5.9.4"
165+
"@react-native-community/netinfo": "^11.3.2",
166+
"react-native-get-random-values": "^1.11.0",
167+
"fast-text-encoding": "^1.0.6"
166168
},
167169
"peerDependenciesMeta": {
168170
"@react-native-async-storage/async-storage": {
169171
"optional": true
170172
},
171173
"@react-native-community/netinfo": {
172174
"optional": true
175+
},
176+
"react-native-get-random-values": {
177+
"optional": true
178+
},
179+
"fast-text-encoding": {
180+
"optional": true
173181
}
174182
},
175183
"publishConfig": {

tests/index.react_native.spec.ts

+12-9
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ import optimizelyFactory from '../lib/index.react_native';
2424
import configValidator from '../lib/utils/config_validator';
2525
import eventProcessorConfigValidator from '../lib/utils/event_processor_config_validator';
2626

27+
jest.mock('react-native-get-random-values')
28+
jest.mock('fast-text-encoding')
29+
2730
describe('javascript-sdk/react-native', () => {
2831
beforeEach(() => {
2932
jest.spyOn(optimizelyFactory.eventDispatcher, 'dispatchEvent');
@@ -45,10 +48,10 @@ describe('javascript-sdk/react-native', () => {
4548
});
4649

4750
describe('createInstance', () => {
48-
var fakeErrorHandler = { handleError: function() {} };
49-
var fakeEventDispatcher = { dispatchEvent: function() {} };
51+
const fakeErrorHandler = { handleError: function() {} };
52+
const fakeEventDispatcher = { dispatchEvent: function() {} };
5053
// @ts-ignore
51-
var silentLogger;
54+
let silentLogger;
5255

5356
beforeEach(() => {
5457
// @ts-ignore
@@ -65,7 +68,7 @@ describe('javascript-sdk/react-native', () => {
6568

6669
it('should not throw if the provided config is not valid', () => {
6770
expect(function() {
68-
var optlyInstance = optimizelyFactory.createInstance({
71+
const optlyInstance = optimizelyFactory.createInstance({
6972
datafile: {},
7073
// @ts-ignore
7174
logger: silentLogger,
@@ -77,7 +80,7 @@ describe('javascript-sdk/react-native', () => {
7780
});
7881

7982
it('should create an instance of optimizely', () => {
80-
var optlyInstance = optimizelyFactory.createInstance({
83+
const optlyInstance = optimizelyFactory.createInstance({
8184
datafile: {},
8285
errorHandler: fakeErrorHandler,
8386
eventDispatcher: fakeEventDispatcher,
@@ -94,7 +97,7 @@ describe('javascript-sdk/react-native', () => {
9497
});
9598

9699
it('should set the React Native JS client engine and javascript SDK version', () => {
97-
var optlyInstance = optimizelyFactory.createInstance({
100+
const optlyInstance = optimizelyFactory.createInstance({
98101
datafile: {},
99102
errorHandler: fakeErrorHandler,
100103
eventDispatcher: fakeEventDispatcher,
@@ -111,7 +114,7 @@ describe('javascript-sdk/react-native', () => {
111114
});
112115

113116
it('should allow passing of "react-sdk" as the clientEngine and convert it to "react-native-sdk"', () => {
114-
var optlyInstance = optimizelyFactory.createInstance({
117+
const optlyInstance = optimizelyFactory.createInstance({
115118
clientEngine: 'react-sdk',
116119
datafile: {},
117120
errorHandler: fakeErrorHandler,
@@ -155,7 +158,7 @@ describe('javascript-sdk/react-native', () => {
155158
});
156159

157160
it('should call logging.setLogHandler with the supplied logger', () => {
158-
var fakeLogger = { log: function() {} };
161+
const fakeLogger = { log: function() {} };
159162
optimizelyFactory.createInstance({
160163
datafile: testData.getTestProjectConfig(),
161164
// @ts-ignore
@@ -168,7 +171,7 @@ describe('javascript-sdk/react-native', () => {
168171

169172
describe('event processor configuration', () => {
170173
// @ts-ignore
171-
var eventProcessorSpy;
174+
let eventProcessorSpy;
172175
beforeEach(() => {
173176
eventProcessorSpy = jest.spyOn(eventProcessor, 'createEventProcessor');
174177
});

0 commit comments

Comments
 (0)