Skip to content

Crubin/remove request promise #55

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 31 commits into from
Jun 1, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
e5a631d
added tests for event_dispatcher
May 24, 2017
5af35d5
cleanup
May 24, 2017
2d51a8a
added test in ./tests.js to check that optlyinstance activates w/ pro…
May 24, 2017
a5d7658
event_dispatcher tests w/o require XML statement
May 24, 2017
4b66d95
added fake xml to tests.js
May 24, 2017
0da1930
cleanup
May 24, 2017
1cd47d1
cleanup
May 24, 2017
bafa9c1
tests moved to karma
May 24, 2017
dff7fcc
added sauce addon to .travis.yml file
May 24, 2017
0447fb0
fake xhr no longer needed in tests.js
May 24, 2017
37e2dd3
cleanup
May 24, 2017
6e21535
cleanup after npm run lint
May 24, 2017
578fc24
switch to karma for testing, bump node-sdk version to 1.3.1
caitlinrubin-optimizely May 25, 2017
c2abcf0
fixes from last commit
caitlinrubin-optimizely May 25, 2017
7c74459
changed version to 1.4.1 in package.json
caitlinrubin-optimizely May 25, 2017
34699a2
changed javascript_client_version to 1.4.1
caitlinrubin-optimizely May 25, 2017
377481d
cleaned up package.json devDependencies
caitlinrubin-optimizely May 25, 2017
bb0f154
added karma-webpack, took out es6
caitlinrubin-optimizely May 25, 2017
ffc6f69
cross browser testing w/ browserstack set up for iphone5, chrome, ope…
caitlinrubin-optimizely May 26, 2017
2da34bd
fixed changes needed since thurs pull, added ie, edge and safari
caitlinrubin-optimizely May 26, 2017
af5bc1b
removed karma.conf from gitignore, added browserstack credentials to …
caitlinrubin-optimizely May 26, 2017
a97a9fb
took addons out of .travis
caitlinrubin-optimizely May 26, 2017
4521a37
added grunt-cli to package.json, changed tests to include fake xhr again
caitlinrubin-optimizely May 30, 2017
3978669
trying to trigger travis build w new package.json
caitlinrubin-optimizely May 30, 2017
d6d51b1
added grunt-cli to .travis
caitlinrubin-optimizely May 30, 2017
9f103da
Merge branch 'master' into crubin/removeRequestPromise
caitlinrubin-optimizely May 30, 2017
139227b
removed 0.10 testing
caitlinrubin-optimizely May 30, 2017
b461c35
fixed year, added node v6 to travis file
caitlinrubin-optimizely May 30, 2017
94c2554
put browserstack tests into karma.bs.conf.js
caitlinrubin-optimizely Jun 1, 2017
24b1c8b
changed .travis to npm run
caitlinrubin-optimizely Jun 1, 2017
7c2df7f
changed single run to true and autowatch to false for karma.bs
caitlinrubin-optimizely Jun 1, 2017
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
8 changes: 6 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
language: node_js
node_js:
- "5"
- "0.10"
- "6"
- "node"
branches:
only:
- master
before_script:
- npm install grunt-cli -g
install: "npm install"
script:
- "npm test"
- "npm run test-travis"
after_success:
- npm run coveralls
9 changes: 9 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
-------------------------------------------------------------------------------
1.4.1
-------------------------------------------------------------------------------
* Switched to karma/browserstack for cross-browser testing
* Removed es6-promise
* Bump optimizely-server-sdk to version 1.3.1, which includes:
- Minor performance improvements.
-------------------------------------------------------------------------------

-------------------------------------------------------------------------------
1.4.0
-------------------------------------------------------------------------------
Expand Down
16 changes: 16 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module.exports = function (grunt) {
grunt.initConfig({
karma: {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we configure it to run on chrome by default, instead of Phantom

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please have it run on chrome by default instead of Phantom

unit: {
configFile: 'karma.bs.conf.js',
singleRun: true,
reporters: 'progress',
runnerPort: 9998
}
}
});

require('load-grunt-tasks')(grunt);

grunt.registerTask('default', ['karma']);
};
2 changes: 1 addition & 1 deletion Scripts/ci_unit_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
export NVM_DIR="`pwd`/.nvm" # truly local nvm install not needing sudo
mkdir -p $NVM_DIR
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.31.0/install.sh | bash
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"

function run_tests () {
echo "Installing node" $1
Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ var logger = require('optimizely-server-sdk/lib/plugins/logger');

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

var JAVASCRIPT_CLIENT_VERSION = '1.4.0';
var JAVASCRIPT_CLIENT_VERSION = '1.4.1';
var MODULE_NAME = 'INDEX';

/**
Expand Down
137 changes: 137 additions & 0 deletions karma.bs.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
// Karma configuration
// Generated on Wed May 24 2017 14:10:20 GMT-0700 (PDT)

module.exports = function(config) {
config.set({

// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: '',

//plugins
plugins: ['karma-mocha', 'karma-webpack', 'karma-browserstack-launcher'],

//browserStack setup
browserStack: {
username: 'echo $BROWSER_STACK_USERNAME',
accessKey: 'echo $BROWSER_STACK_ACCESS_KEY'
},

// to avoid DISCONNECTED messages when connecting to BrowserStack
browserDisconnectTimeout : 10000, // default 2000
browserDisconnectTolerance : 1, // default 0
browserNoActivityTimeout : 4*60*1000, //default 10000
captureTimeout : 4*60*1000, //default 60000

// define browsers
customLaunchers: {
bs_chrome_mac: {
base: 'BrowserStack',
browser: 'chrome',
browser_version: '21.0',
os: 'OS X',
os_version: 'Mountain Lion'
},
bs_edge: {
base: 'BrowserStack',
os: 'Windows',
os_version: '10',
browser: 'edge',
device: null,
browser_version: "15.0"
},
bs_firefox_mac: {
base: 'BrowserStack',
browser: 'firefox',
browser_version: '21.0',
os: 'OS X',
os_version: 'Mountain Lion'
},
bs_ie: {
base: 'BrowserStack',
os: "Windows",
os_version: "7",
browser: "ie",
device: null,
browser_version: "10.0"
},
bs_iphone6: {
base: 'BrowserStack',
device: 'iPhone 6',
os: 'ios',
os_version: '8.3'
},
bs_opera_mac: {
base: 'BrowserStack',
browser: 'opera',
browser_version: '37',
os: 'OS X',
os_version: 'Mountain Lion'
},
bs_safari: {
base: 'BrowserStack',
os: "OS X",
os_version: "Mountain Lion",
browser: "safari",
device: null,
browser_version: "6.2"
}
},

browsers: ['bs_chrome_mac', 'bs_edge', 'bs_firefox_mac', 'bs_ie', 'bs_iphone6', 'bs_opera_mac', 'bs_safari'],

// frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: ['mocha'],


// list of files / patterns to load in the browser
files: [
{pattern: './tests.js', watched: false},
{pattern: './lib/**/*tests.js', watched: false}
],


// list of files to exclude
exclude: [
],


// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
'./tests.js': ['webpack'],
'./lib/**/*tests.js': ['webpack']
},


// test results reporter to use
// possible values: 'dots', 'progress'
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
reporters: ['progress'],


// web server port
port: 9876,


// enable / disable colors in the output (reporters and logs)
colors: true,


// level of logging
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: config.LOG_INFO,


// enable / disable watching file and executing tests whenever any file changes
autoWatch: false,

// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
singleRun: true,

// Concurrency level
// how many browser should be started simultaneous
concurrency: Infinity
})
}
83 changes: 83 additions & 0 deletions karma.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
// Karma configuration
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file should be .gitignored, I think, since it is generated

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For some reason this file is still showing up

// Generated on Thu Jun 01 2017 10:12:37 GMT-0700 (PDT)

module.exports = function(config) {
config.set({

// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: '',


// frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: ['mocha', 'chai'],


// list of files / patterns to load in the browser
files: [
'./tests.js',
'./lib/**/*tests.js'
],


// list of files to exclude
exclude: [
],


// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
},


// test results reporter to use
// possible values: 'dots', 'progress'
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
reporters: ['progress'],


// web server port
port: 9876,


// enable / disable colors in the output (reporters and logs)
colors: true,


// level of logging
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: config.LOG_INFO,


// enable / disable watching file and executing tests whenever any file changes
autoWatch: false,


// start these browsers
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
browsers: ['Chrome'],


// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
singleRun: true,

// Concurrency level
// how many browser should be started simultaneous
concurrency: Infinity,

preprocessors: {
// add webpack as preprocessor
'./tests.js': ['webpack'],
'./lib/**/*tests.js': ['webpack']
},

plugins: [
require("karma-webpack"),
'karma-mocha',
'karma-chai',
'karma-chrome-launcher'
]
})
}
54 changes: 25 additions & 29 deletions lib/plugins/event_dispatcher/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,50 +14,46 @@
* limitations under the License.
*/
var fns = require('optimizely-server-sdk/lib/utils/fns');
var es6Promise = require('es6-promise').Promise;

var POST_METHOD = 'POST';
var GET_METHOD = 'GET';
var READYSTATE_COMPLETE = 4;

module.exports = {
/**
* Sample event dispatcher implementation for tracking impression and conversions
* Users of the SDK can provide their own implementation
* @param {Object} eventObj
* @return {Promise<Object>}
* @param {Function} callback
*/
dispatchEvent: function(eventObj) {
dispatchEvent: function(eventObj, callback) {
var url = eventObj.url;
var params = eventObj.params;

if (eventObj.httpVerb === POST_METHOD) {
return new es6Promise(function(resolve, reject) {

var req = new XMLHttpRequest();
req.open(POST_METHOD, url, true);
req.setRequestHeader('Content-Type', 'application/json');
req.addEventListener('load', function (evt) {
var responseObj = evt.target.responseText;
resolve(responseObj);
});
req.send(JSON.stringify(params));
});
} else {
return new es6Promise(function (resolve, reject) {
// add param for cors headers to be sent by the log endpoint
url += '?wxhr=true';
if (params) {
url += '&' + toQueryString(params);
var req = new XMLHttpRequest();
req.open(POST_METHOD, url, true);
req.setRequestHeader('Content-Type', 'application/json');
req.onreadystatechange = function() {
if (req.readyState === READYSTATE_COMPLETE && callback && typeof callback === 'function') {
callback(params);
}
};
req.send(JSON.stringify(params));
} else {
// add param for cors headers to be sent by the log endpoint
url += '?wxhr=true';
if (params) {
url += '&' + toQueryString(params);
}

var req = new XMLHttpRequest();
req.open(GET_METHOD, url, true);
req.addEventListener('load', function (evt) {
var responseObj = JSON.parse(evt.target.responseText);
resolve(responseObj);
});
req.send();
});
var req = new XMLHttpRequest();
req.open(GET_METHOD, url, true);
req.onreadystatechange = function() {
if (req.readyState === READYSTATE_COMPLETE && callback && typeof callback === 'function') {
callback();
}
};
req.send();
}
},
};
Expand Down
Loading