Skip to content

Commit b89eed7

Browse files
committed
finalized the code
1 parent 0ac6a76 commit b89eed7

File tree

8 files changed

+78
-67
lines changed

8 files changed

+78
-67
lines changed

packages/optimizely-sdk/lib/index.browser.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2016-2017, 2019, 2020 Optimizely
2+
* Copyright 2016-2017, 2019-2020 Optimizely
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -14,14 +14,15 @@
1414
* limitations under the License.
1515
*/
1616
import * as sdkLogging from '@optimizely/js-sdk-logging';
17+
import { LocalStoragePendingEventsDispatcher } from '@optimizely/js-sdk-event-processor';
18+
1719
import fns from './utils/fns';
20+
import Optimizely from './optimizely';
21+
import utilEnums from './utils/enums';
22+
import loggerPlugin from './plugins/logger';
1823
import configValidator from './utils/config_validator';
1924
import defaultErrorHandler from './plugins/error_handler';
2025
import defaultEventDispatcher from './plugins/event_dispatcher/index.browser';
21-
import utilEnums from './utils/enums';
22-
import * as eventProcessor from '@optimizely/js-sdk-event-processor';
23-
import loggerPlugin from './plugins/logger';
24-
import Optimizely from './optimizely';
2526
import eventProcessorConfigValidator from './utils/event_processor_config_validator';
2627

2728
var logger = sdkLogging.getLogger();
@@ -89,7 +90,7 @@ export var createInstance = function(config) {
8990
// prettier-ignore
9091
if (config.eventDispatcher == null) { // eslint-disable-line eqeqeq
9192
// only wrap the event dispatcher with pending events retry if the user didnt override
92-
eventDispatcher = new eventProcessor.LocalStoragePendingEventsDispatcher({
93+
eventDispatcher = new LocalStoragePendingEventsDispatcher({
9394
eventDispatcher: defaultEventDispatcher,
9495
});
9596

packages/optimizely-sdk/lib/index.browser.tests.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2016-2019, 2020 Optimizely
2+
* Copyright 2016-2020 Optimizely
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -14,15 +14,18 @@
1414
* limitations under the License.
1515
*/
1616
import * as logging from '@optimizely/js-sdk-logging';
17-
import configValidator from './utils/config_validator';
17+
import * as eventProcessor from '@optimizely/js-sdk-event-processor';
18+
1819
import Optimizely from './optimizely';
19-
import optimizelyFactory from './index.browser';
20-
import packageJSON from '../package.json';
2120
import testData from './tests/test_data';
22-
import * as eventProcessor from '@optimizely/js-sdk-event-processor';
21+
import packageJSON from '../package.json';
22+
import optimizelyFactory from './index.browser';
23+
import configValidator from './utils/config_validator';
2324
import eventProcessorConfigValidator from './utils/event_processor_config_validator';
25+
2426
import chai from 'chai';
2527
import sinon from 'sinon';
28+
2629
var assert = chai.assert;
2730
var LocalStoragePendingEventsDispatcher = eventProcessor.LocalStoragePendingEventsDispatcher;
2831

packages/optimizely-sdk/lib/index.browser.umdtests.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2018-2019, 2020 Optimizely
2+
* Copyright 2018-2020 Optimizely
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -18,13 +18,15 @@ import configValidator from './utils/config_validator';
1818
import enums from './utils/enums';
1919
import logger from './plugins/logger';
2020
import Optimizely from './optimizely';
21+
import testData from './tests/test_data';
2122
import packageJSON from '../package.json';
2223
import eventDispatcher from './plugins/event_dispatcher/index.browser';
23-
import testData from './tests/test_data';
24+
2425
import chai from 'chai';
25-
var assert = chai.assert;
2626
import sinon from 'sinon';
2727

28+
var assert = chai.assert;
29+
2830
describe('javascript-sdk', function() {
2931
describe('APIs', function() {
3032
var xhr;

packages/optimizely-sdk/lib/index.node.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/****************************************************************************
2-
* Copyright 2016-2017, 2019, 2020 Optimizely, Inc. and contributors *
2+
* Copyright 2016-2017, 2019-2020 Optimizely, Inc. and contributors *
33
* *
44
* Licensed under the Apache License, Version 2.0 (the "License"); *
55
* you may not use this file except in compliance with the License. *
@@ -14,14 +14,15 @@
1414
* limitations under the License. *
1515
***************************************************************************/
1616
import * as sdkLogging from '@optimizely/js-sdk-logging';
17+
18+
import fns from './utils/fns';
19+
import Optimizely from './optimizely';
20+
import utilEnums from './utils/enums';
21+
import loggerPlugin from './plugins/logger';
1722
import configValidator from './utils/config_validator';
1823
import defaultErrorHandler from './plugins/error_handler';
19-
import defaultEventDispatcher from './plugins/event_dispatcher/index.node';
20-
import utilEnums from './utils/enums';
21-
import fns from './utils/fns';
2224
import jsonSchemaValidator from './utils/json_schema_validator';
23-
import loggerPlugin from './plugins/logger';
24-
import Optimizely from './optimizely';
25+
import defaultEventDispatcher from './plugins/event_dispatcher/index.node';
2526
import eventProcessorConfigValidator from './utils/event_processor_config_validator';
2627

2728
const logger = sdkLogging.getLogger();

packages/optimizely-sdk/lib/index.node.tests.js

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2016-2019, 2020 Optimizely
2+
* Copyright 2016-2020 Optimizely
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -13,17 +13,19 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
import configValidator from './utils/config_validator';
16+
import * as eventProcessor from '@optimizely/js-sdk-event-processor';
17+
1718
import enums from './utils/enums';
18-
import loggerPlugin from './plugins/logger';
1919
import Optimizely from './optimizely';
20-
import optimizelyFactory from './index.node';
2120
import testData from './tests/test_data';
22-
import * as eventProcessor from '@optimizely/js-sdk-event-processor';
21+
import loggerPlugin from './plugins/logger';
22+
import optimizelyFactory from './index.node';
23+
import configValidator from './utils/config_validator';
24+
2325
import chai from 'chai';
2426
import sinon from 'sinon';
2527

26-
var assert = chai.assert;
28+
const assert = chai.assert;
2729

2830
describe('optimizelyFactory', function() {
2931
describe('APIs', function() {
@@ -37,9 +39,9 @@ describe('optimizelyFactory', function() {
3739
});
3840

3941
describe('createInstance', function() {
40-
var fakeErrorHandler = { handleError: function() {} };
41-
var fakeEventDispatcher = { dispatchEvent: function() {} };
42-
var fakeLogger;
42+
const fakeErrorHandler = { handleError: function() {} };
43+
const fakeEventDispatcher = { dispatchEvent: function() {} };
44+
let fakeLogger;
4345

4446
beforeEach(function() {
4547
fakeLogger = { log: sinon.spy(), setLogLevel: sinon.spy() };
@@ -56,9 +58,9 @@ describe('optimizelyFactory', function() {
5658

5759
it('should not throw if the provided config is not valid and log an error if logger is passed in', function() {
5860
configValidator.validate.throws(new Error('Invalid config or something'));
59-
var localLogger = loggerPlugin.createLogger({ logLevel: enums.LOG_LEVEL.INFO });
61+
const localLogger = loggerPlugin.createLogger({ logLevel: enums.LOG_LEVEL.INFO });
6062
assert.doesNotThrow(function() {
61-
var optlyInstance = optimizelyFactory.createInstance({
63+
const optlyInstance = optimizelyFactory.createInstance({
6264
datafile: {},
6365
logger: localLogger,
6466
});
@@ -71,7 +73,7 @@ describe('optimizelyFactory', function() {
7173
it('should not throw if the provided config is not valid and log an error if no logger is provided', function() {
7274
configValidator.validate.throws(new Error('Invalid config or something'));
7375
assert.doesNotThrow(function() {
74-
var optlyInstance = optimizelyFactory.createInstance({
76+
const optlyInstance = optimizelyFactory.createInstance({
7577
datafile: {},
7678
});
7779
// Invalid datafile causes onReady Promise rejection - catch this
@@ -81,7 +83,7 @@ describe('optimizelyFactory', function() {
8183
});
8284

8385
it('should create an instance of optimizely', function() {
84-
var optlyInstance = optimizelyFactory.createInstance({
86+
const optlyInstance = optimizelyFactory.createInstance({
8587
datafile: {},
8688
errorHandler: fakeErrorHandler,
8789
eventDispatcher: fakeEventDispatcher,
@@ -95,7 +97,7 @@ describe('optimizelyFactory', function() {
9597
});
9698

9799
describe('event processor configuration', function() {
98-
var eventProcessorSpy;
100+
let eventProcessorSpy;
99101
beforeEach(function() {
100102
eventProcessorSpy = sinon.stub(eventProcessor, 'LogTierV1EventProcessor').callThrough();
101103
});

packages/optimizely-sdk/lib/index.react_native.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2019, 2020 Optimizely
2+
* Copyright 2019-2020 Optimizely
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -14,21 +14,22 @@
1414
* limitations under the License.
1515
*/
1616
import * as sdkLogging from '@optimizely/js-sdk-logging';
17+
1718
import fns from './utils/fns';
19+
import utilEnums from './utils/enums';
20+
import Optimizely from './optimizely';
1821
import configValidator from './utils/config_validator';
1922
import defaultErrorHandler from './plugins/error_handler';
20-
import defaultEventDispatcher from './plugins/event_dispatcher/index.browser';
21-
import utilEnums from './utils/enums';
2223
import loggerPlugin from './plugins/logger/index.react_native';
23-
import Optimizely from './optimizely';
24+
import defaultEventDispatcher from './plugins/event_dispatcher/index.browser';
2425
import eventProcessorConfigValidator from './utils/event_processor_config_validator';
2526

26-
var logger = sdkLogging.getLogger();
27+
const logger = sdkLogging.getLogger();
2728
sdkLogging.setLogHandler(loggerPlugin.createLogger());
2829
sdkLogging.setLogLevel(sdkLogging.LogLevel.INFO);
2930

30-
var DEFAULT_EVENT_BATCH_SIZE = 10;
31-
var DEFAULT_EVENT_FLUSH_INTERVAL = 1000; // Unit is ms, default is 1s
31+
const DEFAULT_EVENT_BATCH_SIZE = 10;
32+
const DEFAULT_EVENT_FLUSH_INTERVAL = 1000; // Unit is ms, default is 1s
3233

3334
export const logging = loggerPlugin;
3435
export const errorHandler = defaultErrorHandler;
@@ -95,12 +96,12 @@ export const createInstance = function(config) {
9596
errorHandler: sdkLogging.getErrorHandler(),
9697
}
9798
);
98-
99+
99100
// If client engine is react, convert it to react native
100101
if (config.clientEngine === enums.REACT_CLIENT_ENGINE) {
101102
config.clientEngine = enums.REACT_NATIVE_CLIENT_ENGINE
102103
}
103-
104+
104105
if (!eventProcessorConfigValidator.validateEventBatchSize(config.eventBatchSize)) {
105106
logger.warn('Invalid eventBatchSize %s, defaulting to %s', config.eventBatchSize, DEFAULT_EVENT_BATCH_SIZE);
106107
config.eventBatchSize = DEFAULT_EVENT_BATCH_SIZE;

packages/optimizely-sdk/lib/index.react_native.tests.js

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2019, 2020 Optimizely
2+
* Copyright 2019-2020 Optimizely
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -14,23 +14,25 @@
1414
* limitations under the License.
1515
*/
1616
import * as logging from '@optimizely/js-sdk-logging';
17-
import configValidator from './utils/config_validator';
17+
1818
import Optimizely from './optimizely';
19-
import optimizelyFactory from './index.react_native';
20-
import packageJSON from '../package.json';
2119
import testData from './tests/test_data';
20+
import packageJSON from '../package.json';
21+
import optimizelyFactory from './index.react_native';
22+
import configValidator from './utils/config_validator';
2223
import * as eventProcessor from '@optimizely/js-sdk-event-processor';
23-
import eventProcessorConfigValidator from './utils/event_processor_config_validator';
2424
import defaultEventDispatcher from './plugins/event_dispatcher/index.browser';
25+
import eventProcessorConfigValidator from './utils/event_processor_config_validator';
26+
2527
import chai from 'chai';
2628
import sinon from 'sinon';
2729

28-
var assert = chai.assert;
30+
const assert = chai.assert;
2931

3032
describe('javascript-sdk/react-native', function() {
3133
describe('APIs', function() {
32-
var xhr;
33-
var requests;
34+
let xhr;
35+
let requests;
3436

3537
it('should expose logger, errorHandler, eventDispatcher and enums', function() {
3638
assert.isDefined(optimizelyFactory.logging);
@@ -42,9 +44,9 @@ describe('javascript-sdk/react-native', function() {
4244
});
4345

4446
describe('createInstance', function() {
45-
var fakeErrorHandler = { handleError: function() {} };
46-
var fakeEventDispatcher = { dispatchEvent: function() {} };
47-
var silentLogger;
47+
const fakeErrorHandler = { handleError: function() {} };
48+
const fakeEventDispatcher = { dispatchEvent: function() {} };
49+
let silentLogger;
4850

4951
beforeEach(function() {
5052
silentLogger = optimizelyFactory.logging.createLogger({
@@ -55,7 +57,6 @@ describe('javascript-sdk/react-native', function() {
5557
sinon.stub(configValidator, 'validate');
5658

5759
xhr = sinon.useFakeXMLHttpRequest();
58-
global.XMLHttpRequest = xhr;
5960
requests = [];
6061
xhr.onCreate = function(req) {
6162
requests.push(req);
@@ -71,7 +72,7 @@ describe('javascript-sdk/react-native', function() {
7172
it('should not throw if the provided config is not valid', function() {
7273
configValidator.validate.throws(new Error('Invalid config or something'));
7374
assert.doesNotThrow(function() {
74-
var optlyInstance = optimizelyFactory.createInstance({
75+
const optlyInstance = optimizelyFactory.createInstance({
7576
datafile: {},
7677
logger: silentLogger,
7778
});
@@ -81,7 +82,7 @@ describe('javascript-sdk/react-native', function() {
8182
});
8283

8384
it('should create an instance of optimizely', function() {
84-
var optlyInstance = optimizelyFactory.createInstance({
85+
const optlyInstance = optimizelyFactory.createInstance({
8586
datafile: {},
8687
errorHandler: fakeErrorHandler,
8788
eventDispatcher: fakeEventDispatcher,
@@ -95,7 +96,7 @@ describe('javascript-sdk/react-native', function() {
9596
});
9697

9798
it('should set the React Native JS client engine and javascript SDK version', function() {
98-
var optlyInstance = optimizelyFactory.createInstance({
99+
const optlyInstance = optimizelyFactory.createInstance({
99100
datafile: {},
100101
errorHandler: fakeErrorHandler,
101102
eventDispatcher: fakeEventDispatcher,
@@ -108,7 +109,7 @@ describe('javascript-sdk/react-native', function() {
108109
});
109110

110111
it('should allow passing of "react-sdk" as the clientEngine and convert it to "react-native-sdk"', function() {
111-
var optlyInstance = optimizelyFactory.createInstance({
112+
const optlyInstance = optimizelyFactory.createInstance({
112113
clientEngine: 'react-sdk',
113114
datafile: {},
114115
errorHandler: fakeErrorHandler,
@@ -121,13 +122,13 @@ describe('javascript-sdk/react-native', function() {
121122
});
122123

123124
it('should activate with provided event dispatcher', function() {
124-
var optlyInstance = optimizelyFactory.createInstance({
125+
const optlyInstance = optimizelyFactory.createInstance({
125126
datafile: testData.getTestProjectConfig(),
126127
errorHandler: fakeErrorHandler,
127128
eventDispatcher: optimizelyFactory.eventDispatcher,
128129
logger: silentLogger,
129130
});
130-
var activate = optlyInstance.activate('testExperiment', 'testUser');
131+
const activate = optlyInstance.activate('testExperiment', 'testUser');
131132
assert.strictEqual(activate, 'control');
132133
});
133134

@@ -143,7 +144,7 @@ describe('javascript-sdk/react-native', function() {
143144
});
144145

145146
it('uses the default event dispatcher', function() {
146-
var optlyInstance = optimizelyFactory.createInstance({
147+
const optlyInstance = optimizelyFactory.createInstance({
147148
datafile: testData.getTestProjectConfig(),
148149
errorHandler: fakeErrorHandler,
149150
logger: silentLogger,
@@ -184,7 +185,7 @@ describe('javascript-sdk/react-native', function() {
184185
});
185186

186187
it('should call logging.setLogHandler with the supplied logger', function() {
187-
var fakeLogger = { log: function() {} };
188+
const fakeLogger = { log: function() {} };
188189
optimizelyFactory.createInstance({
189190
datafile: testData.getTestProjectConfig(),
190191
logger: fakeLogger,
@@ -195,7 +196,7 @@ describe('javascript-sdk/react-native', function() {
195196
});
196197

197198
describe('event processor configuration', function() {
198-
var eventProcessorSpy;
199+
let eventProcessorSpy;
199200
beforeEach(function() {
200201
eventProcessorSpy = sinon.stub(eventProcessor, 'LogTierV1EventProcessor').callThrough();
201202
});

0 commit comments

Comments
 (0)