Skip to content

Commit b39740c

Browse files
Crubin/remove request promise (#55)
1 parent 6c5beec commit b39740c

13 files changed

+684
-42
lines changed

.travis.yml

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
language: node_js
22
node_js:
33
- "5"
4-
- "0.10"
4+
- "6"
55
- "node"
66
branches:
77
only:
88
- master
9+
before_script:
10+
- npm install grunt-cli -g
911
install: "npm install"
1012
script:
11-
- "npm test"
13+
- "npm run test-travis"
14+
after_success:
15+
- npm run coveralls

CHANGELOG

+9
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
-------------------------------------------------------------------------------
2+
1.4.1
3+
-------------------------------------------------------------------------------
4+
* Switched to karma/browserstack for cross-browser testing
5+
* Removed es6-promise
6+
* Bump optimizely-server-sdk to version 1.3.1, which includes:
7+
- Minor performance improvements.
8+
-------------------------------------------------------------------------------
9+
110
-------------------------------------------------------------------------------
211
1.4.0
312
-------------------------------------------------------------------------------

Gruntfile.js

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
module.exports = function (grunt) {
2+
grunt.initConfig({
3+
karma: {
4+
unit: {
5+
configFile: 'karma.bs.conf.js',
6+
singleRun: true,
7+
reporters: 'progress',
8+
runnerPort: 9998
9+
}
10+
}
11+
});
12+
13+
require('load-grunt-tasks')(grunt);
14+
15+
grunt.registerTask('default', ['karma']);
16+
};

Scripts/ci_unit_tests.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
export NVM_DIR="`pwd`/.nvm" # truly local nvm install not needing sudo
66
mkdir -p $NVM_DIR
77
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.31.0/install.sh | bash
8-
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"
8+
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"
99

1010
function run_tests () {
1111
echo "Installing node" $1

index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ var logger = require('optimizely-server-sdk/lib/plugins/logger');
2222

2323
var Optimizely = require('optimizely-server-sdk/lib/optimizely');
2424

25-
var JAVASCRIPT_CLIENT_VERSION = '1.4.0';
25+
var JAVASCRIPT_CLIENT_VERSION = '1.4.1';
2626
var MODULE_NAME = 'INDEX';
2727

2828
/**

karma.bs.conf.js

+137
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
// Karma configuration
2+
// Generated on Wed May 24 2017 14:10:20 GMT-0700 (PDT)
3+
4+
module.exports = function(config) {
5+
config.set({
6+
7+
// base path that will be used to resolve all patterns (eg. files, exclude)
8+
basePath: '',
9+
10+
//plugins
11+
plugins: ['karma-mocha', 'karma-webpack', 'karma-browserstack-launcher'],
12+
13+
//browserStack setup
14+
browserStack: {
15+
username: 'echo $BROWSER_STACK_USERNAME',
16+
accessKey: 'echo $BROWSER_STACK_ACCESS_KEY'
17+
},
18+
19+
// to avoid DISCONNECTED messages when connecting to BrowserStack
20+
browserDisconnectTimeout : 10000, // default 2000
21+
browserDisconnectTolerance : 1, // default 0
22+
browserNoActivityTimeout : 4*60*1000, //default 10000
23+
captureTimeout : 4*60*1000, //default 60000
24+
25+
// define browsers
26+
customLaunchers: {
27+
bs_chrome_mac: {
28+
base: 'BrowserStack',
29+
browser: 'chrome',
30+
browser_version: '21.0',
31+
os: 'OS X',
32+
os_version: 'Mountain Lion'
33+
},
34+
bs_edge: {
35+
base: 'BrowserStack',
36+
os: 'Windows',
37+
os_version: '10',
38+
browser: 'edge',
39+
device: null,
40+
browser_version: "15.0"
41+
},
42+
bs_firefox_mac: {
43+
base: 'BrowserStack',
44+
browser: 'firefox',
45+
browser_version: '21.0',
46+
os: 'OS X',
47+
os_version: 'Mountain Lion'
48+
},
49+
bs_ie: {
50+
base: 'BrowserStack',
51+
os: "Windows",
52+
os_version: "7",
53+
browser: "ie",
54+
device: null,
55+
browser_version: "10.0"
56+
},
57+
bs_iphone6: {
58+
base: 'BrowserStack',
59+
device: 'iPhone 6',
60+
os: 'ios',
61+
os_version: '8.3'
62+
},
63+
bs_opera_mac: {
64+
base: 'BrowserStack',
65+
browser: 'opera',
66+
browser_version: '37',
67+
os: 'OS X',
68+
os_version: 'Mountain Lion'
69+
},
70+
bs_safari: {
71+
base: 'BrowserStack',
72+
os: "OS X",
73+
os_version: "Mountain Lion",
74+
browser: "safari",
75+
device: null,
76+
browser_version: "6.2"
77+
}
78+
},
79+
80+
browsers: ['bs_chrome_mac', 'bs_edge', 'bs_firefox_mac', 'bs_ie', 'bs_iphone6', 'bs_opera_mac', 'bs_safari'],
81+
82+
// frameworks to use
83+
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
84+
frameworks: ['mocha'],
85+
86+
87+
// list of files / patterns to load in the browser
88+
files: [
89+
{pattern: './tests.js', watched: false},
90+
{pattern: './lib/**/*tests.js', watched: false}
91+
],
92+
93+
94+
// list of files to exclude
95+
exclude: [
96+
],
97+
98+
99+
// preprocess matching files before serving them to the browser
100+
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
101+
preprocessors: {
102+
'./tests.js': ['webpack'],
103+
'./lib/**/*tests.js': ['webpack']
104+
},
105+
106+
107+
// test results reporter to use
108+
// possible values: 'dots', 'progress'
109+
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
110+
reporters: ['progress'],
111+
112+
113+
// web server port
114+
port: 9876,
115+
116+
117+
// enable / disable colors in the output (reporters and logs)
118+
colors: true,
119+
120+
121+
// level of logging
122+
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
123+
logLevel: config.LOG_INFO,
124+
125+
126+
// enable / disable watching file and executing tests whenever any file changes
127+
autoWatch: false,
128+
129+
// Continuous Integration mode
130+
// if true, Karma captures browsers, runs the tests and exits
131+
singleRun: true,
132+
133+
// Concurrency level
134+
// how many browser should be started simultaneous
135+
concurrency: Infinity
136+
})
137+
}

karma.conf.js

+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
// Karma configuration
2+
// Generated on Thu Jun 01 2017 10:12:37 GMT-0700 (PDT)
3+
4+
module.exports = function(config) {
5+
config.set({
6+
7+
// base path that will be used to resolve all patterns (eg. files, exclude)
8+
basePath: '',
9+
10+
11+
// frameworks to use
12+
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
13+
frameworks: ['mocha', 'chai'],
14+
15+
16+
// list of files / patterns to load in the browser
17+
files: [
18+
'./tests.js',
19+
'./lib/**/*tests.js'
20+
],
21+
22+
23+
// list of files to exclude
24+
exclude: [
25+
],
26+
27+
28+
// preprocess matching files before serving them to the browser
29+
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
30+
preprocessors: {
31+
},
32+
33+
34+
// test results reporter to use
35+
// possible values: 'dots', 'progress'
36+
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
37+
reporters: ['progress'],
38+
39+
40+
// web server port
41+
port: 9876,
42+
43+
44+
// enable / disable colors in the output (reporters and logs)
45+
colors: true,
46+
47+
48+
// level of logging
49+
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
50+
logLevel: config.LOG_INFO,
51+
52+
53+
// enable / disable watching file and executing tests whenever any file changes
54+
autoWatch: false,
55+
56+
57+
// start these browsers
58+
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
59+
browsers: ['Chrome'],
60+
61+
62+
// Continuous Integration mode
63+
// if true, Karma captures browsers, runs the tests and exits
64+
singleRun: true,
65+
66+
// Concurrency level
67+
// how many browser should be started simultaneous
68+
concurrency: Infinity,
69+
70+
preprocessors: {
71+
// add webpack as preprocessor
72+
'./tests.js': ['webpack'],
73+
'./lib/**/*tests.js': ['webpack']
74+
},
75+
76+
plugins: [
77+
require("karma-webpack"),
78+
'karma-mocha',
79+
'karma-chai',
80+
'karma-chrome-launcher'
81+
]
82+
})
83+
}

lib/plugins/event_dispatcher/index.js

+25-29
Original file line numberDiff line numberDiff line change
@@ -14,50 +14,46 @@
1414
* limitations under the License.
1515
*/
1616
var fns = require('optimizely-server-sdk/lib/utils/fns');
17-
var es6Promise = require('es6-promise').Promise;
1817

1918
var POST_METHOD = 'POST';
2019
var GET_METHOD = 'GET';
20+
var READYSTATE_COMPLETE = 4;
2121

2222
module.exports = {
2323
/**
2424
* Sample event dispatcher implementation for tracking impression and conversions
2525
* Users of the SDK can provide their own implementation
2626
* @param {Object} eventObj
27-
* @return {Promise<Object>}
27+
* @param {Function} callback
2828
*/
29-
dispatchEvent: function(eventObj) {
29+
dispatchEvent: function(eventObj, callback) {
3030
var url = eventObj.url;
3131
var params = eventObj.params;
32-
3332
if (eventObj.httpVerb === POST_METHOD) {
34-
return new es6Promise(function(resolve, reject) {
35-
36-
var req = new XMLHttpRequest();
37-
req.open(POST_METHOD, url, true);
38-
req.setRequestHeader('Content-Type', 'application/json');
39-
req.addEventListener('load', function (evt) {
40-
var responseObj = evt.target.responseText;
41-
resolve(responseObj);
42-
});
43-
req.send(JSON.stringify(params));
44-
});
45-
} else {
46-
return new es6Promise(function (resolve, reject) {
47-
// add param for cors headers to be sent by the log endpoint
48-
url += '?wxhr=true';
49-
if (params) {
50-
url += '&' + toQueryString(params);
33+
var req = new XMLHttpRequest();
34+
req.open(POST_METHOD, url, true);
35+
req.setRequestHeader('Content-Type', 'application/json');
36+
req.onreadystatechange = function() {
37+
if (req.readyState === READYSTATE_COMPLETE && callback && typeof callback === 'function') {
38+
callback(params);
5139
}
40+
};
41+
req.send(JSON.stringify(params));
42+
} else {
43+
// add param for cors headers to be sent by the log endpoint
44+
url += '?wxhr=true';
45+
if (params) {
46+
url += '&' + toQueryString(params);
47+
}
5248

53-
var req = new XMLHttpRequest();
54-
req.open(GET_METHOD, url, true);
55-
req.addEventListener('load', function (evt) {
56-
var responseObj = JSON.parse(evt.target.responseText);
57-
resolve(responseObj);
58-
});
59-
req.send();
60-
});
49+
var req = new XMLHttpRequest();
50+
req.open(GET_METHOD, url, true);
51+
req.onreadystatechange = function() {
52+
if (req.readyState === READYSTATE_COMPLETE && callback && typeof callback === 'function') {
53+
callback();
54+
}
55+
};
56+
req.send();
6157
}
6258
},
6359
};

0 commit comments

Comments
 (0)