Browse Source

Refactor tests, deps, and specs

Remove sinon.js, calling the API direct now - no more mystery
Update configs to remove sinon.js refs
Update specs for IE8/9, bump OSX test version
master
dustinlarimer 9 years ago
parent
commit
83aa7b2da4
  1. 12
      CHANGELOG.md
  2. 11
      README.md
  3. 2
      dist/keen-tracking.js
  4. 2
      dist/keen-tracking.js.map
  5. 2
      dist/keen-tracking.min.js
  6. 29
      gulpfile.js
  7. 2
      karma.conf.js
  8. 2
      lib/index.js
  9. 4
      package.json
  10. 2
      test/unit/helpers/client-config.js
  11. 55
      test/unit/modules/record-events-browser-spec.js
  12. 15
      test/unit/modules/utils/listener-spec.js

12
CHANGELOG.md

@ -3,9 +3,19 @@
# Unreleased
-->
<a name="0.0.2"></a>
# 0.0.2
**NEW:**
* Synchronous XHR option (#28, ported from keen-js)
**BREAKING:**
* `.recordEvent` XHR calls now use POST, mirroring previous keen-js functionality (#27).
* `client.url()`: The previous keen-js implementation of `client.url()` automatically included `https://api.keen.io/3.0/projects/PROJECT_ID` + a `path` argument ('/events/whatever'), which severely limited its value. It now only returns `https://api.keen.io` + the path argument.
<a name="0.0.1"></a>
# 0.0.1 Hello, world!
**NEW:**
* [Everything](./README.md) :)

11
README.md

@ -36,13 +36,22 @@ If you haven't done so already, login to Keen IO to create a project. The Projec
<a name="upgrading-from-keen-js"></a>
**Upgrading from keen-js:**
There are several new methods and name changes from keen-js, but fear not! We have included shims and legacy methods to make this library fully backward-compatible with the core functionality of keen-js. Here are the methods and their replacement methods:
There are several new methods and name changes from keen-js, but fear not! We have included shims and legacy methods to make this library fully backward-compatible with the core functionality of keen-js, aside from one breaking change to the `client.url()` method (detailed below). Here are the methods and their replacement methods:
* `addEvent` and `addEvents` are now [`recordEvent`](#record-a-single-event) and [`recordEvents`](#record-multiple-events)
* `setGlobalProperties` is now handled by the [`extendEvents`](#extend-events) methods
* `trackExternalLinks` is now handled by the [DOM listeners](#listeners) utility (browser-only)
Please avoid using these deprecated methods, as they will eventually get axed. Deprecation messages will be visible in the developer console if [debugging](#debugging) is enabled.
**Breaking change from keen-js:** the previous implementation of `client.url()` automatically included `https://api.keen.io/3.0/projects/PROJECT_ID` + a `path` argument ('/events/whatever'), which severely limited its value. It now only returns `https://api.keen.io` + the path argument.
You can also now pass in an object to append a serialized query string to the result, like so:
```javascript
var url = client.url('/3.0/projects', { key: 'value'} );
// https://api.keen.io/3.0/projects?key=value
```
<a name="additional-resources"></a>
**Additional resources:**

2
dist/keen-tracking.js

@ -478,7 +478,7 @@ extend(Keen, {
loaded: false,
helpers: {},
utils: {},
version: '0.0.1'
version: '0.0.2'
});
Keen.log = function(message) {
if (Keen.debug && typeof console == 'object') {

2
dist/keen-tracking.js.map

File diff suppressed because one or more lines are too long

2
dist/keen-tracking.min.js

File diff suppressed because one or more lines are too long

29
gulpfile.js

@ -210,19 +210,6 @@ gulp.task('test:cli', ['test:mocha', 'test:phantom']);
function getCustomLaunchers(){
return {
sl_ios: {
base: 'SauceLabs',
browserName: 'iPhone',
platform: 'OS X 10.9',
version: '8.1'
},
sl_android: {
base: 'SauceLabs',
browserName: 'android',
platform: 'Linux',
version: '4.4'
},
sl_ie_11: {
base: 'SauceLabs',
browserName: 'internet explorer',
@ -246,12 +233,26 @@ function getCustomLaunchers(){
browserName: 'internet explorer',
platform: 'Windows XP',
version: '8'
}
},
// sl_ie_7: {
// base: 'SauceLabs',
// browserName: 'internet explorer',
// platform: 'Windows XP',
// version: '7'
// }
sl_ios: {
base: 'SauceLabs',
browserName: 'iPhone',
platform: 'OS X 10.10',
version: '8.1'
},
sl_android: {
base: 'SauceLabs',
browserName: 'android',
platform: 'Linux',
version: '4.4'
}
};
}

2
karma.conf.js

@ -1,7 +1,7 @@
module.exports = function(config) {
config.set({
browsers: [ 'Chrome', 'Firefox', 'Safari' ],
frameworks: [ 'mocha', 'sinon' ],
frameworks: [ 'mocha' ],
files: [
// Include requirejs presence
// './test/vendor/require.js',

2
lib/index.js

@ -84,7 +84,7 @@ Keen.prototype.url = function(path, data){
this.emit('error', 'Keen is missing a projectId property');
return;
}
url = this.config.protocol + '://' + this.config.host; // + this.writePath();
url = this.config.protocol + '://' + this.config.host;
if (path) {
url += path;
}

4
package.json

@ -1,6 +1,6 @@
{
"name": "keen-tracking",
"version": "0.0.1",
"version": "0.0.2",
"main": "index.js",
"browser": "lib/browser.js",
"repository": {
@ -53,13 +53,11 @@
"karma-requirejs": "^0.2.2",
"karma-safari-launcher": "^0.1.1",
"karma-sauce-launcher": "^0.2.11",
"karma-sinon": "^1.0.4",
"mocha": "^2.2.5",
"moment": "^2.10.3",
"nock": "^2.0.1",
"phantomjs": "^1.9.17",
"proclaim": "^3.3.0",
"sinon": "^1.14.1",
"vinyl-buffer": "^1.0.0",
"vinyl-source-stream": "^1.1.0"
}

2
test/unit/helpers/client-config.js

@ -4,7 +4,7 @@ module.exports = {
readKey : 'f979d53e026bdbf1ba16f01ce168bc7bcf9d5308ba672fb14e1834793a9e705eefa04793f0f87fb76b1d49a6cc2747b96a8abae0e4569d70314099b3f7790f55e98c9ac482e3883aab86a4bb577c295dbbca4867e95e2e4b15038fac5d80957ded3e868e4e6e319d3aa9275abc22b16e',
masterKey : 'FC135394DD08E3976870B7E7E83BDCD8',
protocol : 'https',
host : 'mocha.keen.io',
host : 'api.keen.io',
collection : 'mocha',
properties: {
username : 'keenio',

55
test/unit/modules/record-events-browser-spec.js

@ -1,6 +1,5 @@
var assert = require('proclaim');
var JSON2 = require('JSON2');
var sinon = require('sinon');
var Keen = require('../../../lib/browser');
var config = require('../helpers/client-config');
@ -25,11 +24,6 @@ describe('.recordEvent(s) methods (browser)', function() {
if ('undefined' !== typeof document && document.all) {
this.postUrl = this.postUrl.replace('https', 'http');
}
this.server = sinon.fakeServer.create();
});
afterEach(function(){
this.server.restore();
});
it('should not send events if set to \'false\'', function(){
@ -55,55 +49,30 @@ describe('.recordEvent(s) methods (browser)', function() {
var headers = {
'Content-Type': 'application/json'
};
this.server.respondWith( 'POST', this.postUrl, [ 201, headers, config.responses['success'] ] );
this.client.recordEvent(config.collection, config.properties, function(err, res){
this.client.recordEvent(config.collection + '_succeed', config.properties, function(err, res){
count++;
assert.isNull(err);
assert.isNotNull(res);
assert.equal(count, 1);
});
this.server.respond();
});
it('should call the error callback on error', function() {
it('should fire the callback on error', function() {
var count = 0;
var headers = {
'Content-Type': 'application/json'
};
this.client.recordEvent(config.collection, config.properties, function(err, res){
this.client.config.writeKey = 'nope';
this.client.recordEvent(config.collection + '_error', config.properties, function(err, res){
count++;
assert.isNotNull(err);
assert.isNull(res);
assert.equal(count, 1);
});
this.server.respondWith( 'POST', this.postUrl, [ 500, headers, config.responses['error'] ] );
this.server.respond();
});
});
// describe('via JSONP to a fake server', function(){
// beforeEach(function() {
// this.client = new Keen({
// projectId: config.projectId,
// writeKey: config.writeKey,
// host: config.host,
// requestType: 'jsonp'
// });
// });
// });
//
// describe('via Image Beacon to a fake server', function(){
// beforeEach(function() {
// this.client = new Keen({
// projectId: config.projectId,
// writeKey: config.writeKey,
// host: config.host,
// requestType: 'beacon'
// });
// });
// });
});
describe('.recordEvents', function() {
@ -155,43 +124,29 @@ describe('.recordEvent(s) methods (browser)', function() {
beforeEach(function() {
this.postUrl = this.client.url(this.client.writePath());
this.server = sinon.fakeServer.create();
});
afterEach(function(){
this.server.restore();
});
if ('withCredentials' in new XMLHttpRequest()) {
it('should send a POST request to the API using XHR', function() {
var count = 0;
this.client.recordEvents(this.batchData, function(err, res){
count++;
// assert.deepEqual(err, JSON.parse(config.responses['error']));
assert.isNull(err);
assert.isNotNull(res);
assert.equal(count, 1);
});
this.server.respondWith( 'POST', this.postUrl, [ 201, { 'Content-Type': 'application/json'}, config.responses['success'] ] );
this.server.respond();
});
it('should call the error callback on error', function() {
var count = 0;
this.client.config.writeKey = 'nope';
this.client.recordEvents(this.batchData, function(err, res){
count++;
// assert.deepEqual(err, JSON.parse(config.responses['error']));
assert.isNotNull(err);
assert.isNull(res);
assert.equal(count, 1);
});
this.server.respondWith( 'POST', this.postUrl, [ 500, { 'Content-Type': 'application/json'}, config.responses['error'] ] );
this.server.respond();
});
}
});
});

15
test/unit/modules/utils/listener-spec.js

@ -95,7 +95,6 @@ describe('Keen.utils.listener', function() {
this.timeout(5000);
function callback(e){
e.preventDefault();
// Keen.log('click a#listen-to-anchor');
done();
return false;
@ -113,7 +112,7 @@ describe('Keen.utils.listener', function() {
a.click();
}
else if(document.createEvent) {
ev = document.createEvent('MouseEvent');
ev = document.createEvent("MouseEvent");
ev.initMouseEvent("click",
true /* bubble */, true /* cancelable */,
window, null,
@ -128,11 +127,15 @@ describe('Keen.utils.listener', function() {
it('should set and handle `<a>` click events set with .once("click", fn)', function(done){
var listen = listener('a#listen-to-anchor-once');
listen.once('click', function(e){
listen.once('click', callback);
this.timeout(5000);
function callback(e){
// Keen.log('click a#listen-to-anchor-once');
done();
return false;
});
}
setTimeout(function(){
var ev, a;
@ -159,10 +162,6 @@ describe('Keen.utils.listener', function() {
}, 1000);
});
function createEvent(){
}
it('should remove specific handlers with .off("click", fn)', function(){
var listenToThis = listener('body a#on-off');

Loading…
Cancel
Save