You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@senssoft.apache.org by rf...@apache.org on 2016/09/20 21:03:52 UTC
[1/8] incubator-senssoft-useralejs git commit: Removed unnecessary
log statement.
Repository: incubator-senssoft-useralejs
Updated Branches:
refs/heads/master 0679b331f -> 416450cdb
Removed unnecessary log statement.
Project: http://git-wip-us.apache.org/repos/asf/incubator-senssoft-useralejs/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-senssoft-useralejs/commit/90a18a55
Tree: http://git-wip-us.apache.org/repos/asf/incubator-senssoft-useralejs/tree/90a18a55
Diff: http://git-wip-us.apache.org/repos/asf/incubator-senssoft-useralejs/diff/90a18a55
Branch: refs/heads/master
Commit: 90a18a55e105a19c05b745eec43a66bd48f72fe1
Parents: 0679b33
Author: Rob Foley <ro...@gmail.com>
Authored: Tue Sep 20 09:42:38 2016 -0400
Committer: Rob Foley <ro...@gmail.com>
Committed: Tue Sep 20 09:42:38 2016 -0400
----------------------------------------------------------------------
src/sendLogs.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-senssoft-useralejs/blob/90a18a55/src/sendLogs.js
----------------------------------------------------------------------
diff --git a/src/sendLogs.js b/src/sendLogs.js
index b9a15c4..006693d 100644
--- a/src/sendLogs.js
+++ b/src/sendLogs.js
@@ -22,7 +22,7 @@ export function sendOnInterval(logs, config) {
if (logs.length >= config.logCountThreshold) {
var data = logs;
logs = [];
- console.log(data);
+ // console.log(data);
sendLogs(data, config.url, 5);
}
}, config.transmitInterval);
[2/8] incubator-senssoft-useralejs git commit: Added null check to log
Posted by rf...@apache.org.
Added null check to log
Project: http://git-wip-us.apache.org/repos/asf/incubator-senssoft-useralejs/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-senssoft-useralejs/commit/355f4c23
Tree: http://git-wip-us.apache.org/repos/asf/incubator-senssoft-useralejs/tree/355f4c23
Diff: http://git-wip-us.apache.org/repos/asf/incubator-senssoft-useralejs/diff/355f4c23
Branch: refs/heads/master
Commit: 355f4c2353c8b1598fcd46922e94465162acf04e
Parents: 90a18a5
Author: Rob Foley <ro...@gmail.com>
Authored: Tue Sep 20 10:36:17 2016 -0400
Committer: Rob Foley <ro...@gmail.com>
Committed: Tue Sep 20 10:36:17 2016 -0400
----------------------------------------------------------------------
src/main.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-senssoft-useralejs/blob/355f4c23/src/main.js
----------------------------------------------------------------------
diff --git a/src/main.js b/src/main.js
index 5bf2135..c48aef8 100644
--- a/src/main.js
+++ b/src/main.js
@@ -76,7 +76,7 @@ export function options(newConfig) {
}
export function log(customLog) {
- if (typeof customLog === 'object') {
+ if (customLog !== null && typeof customLog === 'object') {
logs.push(customLog);
return true;
} else {
[4/8] incubator-senssoft-useralejs git commit: Updated to object
shorthand.
Posted by rf...@apache.org.
Updated to object shorthand.
Project: http://git-wip-us.apache.org/repos/asf/incubator-senssoft-useralejs/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-senssoft-useralejs/commit/87b43c7d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-senssoft-useralejs/tree/87b43c7d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-senssoft-useralejs/diff/87b43c7d
Branch: refs/heads/master
Commit: 87b43c7d142832b6d621b241e2d0ff44c179d7e4
Parents: bcb96cb
Author: Rob Foley <ro...@gmail.com>
Authored: Tue Sep 20 10:40:25 2016 -0400
Committer: Rob Foley <ro...@gmail.com>
Committed: Tue Sep 20 10:40:25 2016 -0400
----------------------------------------------------------------------
test/main_spec.js | 36 ++++++++++--------------------------
1 file changed, 10 insertions(+), 26 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-senssoft-useralejs/blob/87b43c7d/test/main_spec.js
----------------------------------------------------------------------
diff --git a/test/main_spec.js b/test/main_spec.js
index 611a06d..6fd0741 100644
--- a/test/main_spec.js
+++ b/test/main_spec.js
@@ -3,17 +3,16 @@ import jsdom from 'jsdom';
import fs from 'fs';
describe('Userale API', () => {
- var file = 'file://' + __dirname + '/main.html';
- var html = fs.readFileSync(__dirname + '/main.html');
+ const url = 'file://' + __dirname + '/main.html';
+ const html = fs.readFileSync(__dirname + '/main.html');
+ const features = {
+ FetchExternalResources : ['script'],
+ ProcessExternalResources : ['script']
+ };
it('provides configs', (done) => {
jsdom.env({
- html : html,
- url : file,
- features : {
- FetchExternalResources : ['script'],
- ProcessExternalResources : ['script']
- },
+ html, url, features,
done : (err, window) => {
const config = window.userale.options();
expect(config).to.be.an('object');
@@ -40,12 +39,7 @@ describe('Userale API', () => {
it('edits configs', (done) => {
jsdom.env({
- html : html,
- url : file,
- features : {
- FetchExternalResources : ['script'],
- ProcessExternalResources : ['script']
- },
+ html, url, features,
done : (err, window) => {
const config = window.userale.options();
const interval = config.transmitInterval;
@@ -63,12 +57,7 @@ describe('Userale API', () => {
it('starts + stops', (done) => {
jsdom.env({
- html : html,
- url : file,
- features : {
- FetchExternalResources : ['script'],
- ProcessExternalResources : ['script']
- },
+ html, url, features,
done : (err, window) => {
setTimeout(() => {
const { userale } = window;
@@ -89,12 +78,7 @@ describe('Userale API', () => {
it('sends custom logs', (done) => {
jsdom.env({
- html: html,
- url: file,
- features : {
- FetchExternalResources : ['script'],
- ProcessExternalResources : ['script']
- },
+ html, url, features,
done: (err, window) => {
const { userale } = window;
[6/8] incubator-senssoft-useralejs git commit: Added tests for
attachHandlers.js
Posted by rf...@apache.org.
Added tests for attachHandlers.js
Project: http://git-wip-us.apache.org/repos/asf/incubator-senssoft-useralejs/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-senssoft-useralejs/commit/7e52366c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-senssoft-useralejs/tree/7e52366c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-senssoft-useralejs/diff/7e52366c
Branch: refs/heads/master
Commit: 7e52366c1e33f76f8b5fe19b978e6250658e0a08
Parents: 2718a06
Author: Rob Foley <ro...@gmail.com>
Authored: Tue Sep 20 14:24:03 2016 -0400
Committer: Rob Foley <ro...@gmail.com>
Committed: Tue Sep 20 14:24:03 2016 -0400
----------------------------------------------------------------------
test/attachHandlers_spec.js | 67 ++++++++++++++++++++++++++++++++++++++--
1 file changed, 65 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-senssoft-useralejs/blob/7e52366c/test/attachHandlers_spec.js
----------------------------------------------------------------------
diff --git a/test/attachHandlers_spec.js b/test/attachHandlers_spec.js
index 5000c0d..64aeb3d 100644
--- a/test/attachHandlers_spec.js
+++ b/test/attachHandlers_spec.js
@@ -1,12 +1,75 @@
import { expect } from 'chai';
import jsdom from 'jsdom';
import fs from 'fs';
+import { attachHandlers } from '../src/attachHandlers';
+import * as packager from '../src/packageLogs';
describe('attachHandlers', () => {
- it('attaches all the event handlers');
- it('debounces bufferedEvents');
+ it('attaches all the event handlers without duplicates', (done) => {
+ let duplicateEvents = 0;
+ const initialDocument = global.document;
+ const initialWindow = global.window;
+ // List of supported document events
+ const missingDocumentEvents = [
+ 'click', 'dblclick', 'mousedown', 'mouseup', 'focus', 'blur',
+ 'input', 'change', 'dragstart', 'dragend', 'drag', 'drop',
+ 'keydown', 'mouseover', 'submit'
+ ];
+ // List of supported window events
+ const missingWindowEvents = ['wheel', 'scroll', 'resize', 'load', 'blur', 'focus'];
+ // Acts as a kind of Proxy for addEventListener. Keeps track of added listeners.
+ const listenerHook = eventList => (ev) => {
+ const evIndex = eventList.indexOf(ev);
+ if (evIndex !== -1) {
+ eventList.splice(evIndex, 1);
+ } else {
+ duplicateEvents++;
+ }
+ };
+ global.document = { addEventListener: listenerHook(missingDocumentEvents) };
+ global.window = { addEventListener: listenerHook(missingWindowEvents) };
+ attachHandlers({ logDetails: true });
+ expect(duplicateEvents).to.equal(0);
+ expect(missingDocumentEvents.length).to.equal(0);
+ expect(missingWindowEvents.length).to.equal(0);
+ global.document = initialDocument;
+ global.window = initialWindow;
+ done();
+ });
+ it('debounces bufferedEvents', (done) => {
+ let callCount = 0;
+ let testingEvent = false;
+ const bufferedEvents = ['wheel', 'scroll', 'resize'];
+ const initialWindow = global.window;
+ const initialDocument = global.document;
+ const rate = 500;
+ const initialPackage = packager.packageLog;
+ packager.packageLog = () => { callCount++; };
+ global.document = { addEventListener: () => {} };
+ // Tries to call an event 3 times. Twice in quick succession, then once after the set delay.
+ // Number of actual calls to packageLog are recorded in callCount. Should amount to exactly 2 calls.
+ global.window = {
+ addEventListener: (ev, fn, ...args) => {
+ if (!testingEvent && bufferedEvents.indexOf(ev) !== -1) {
+ testingEvent = true;
+ fn();
+ fn();
+ setTimeout(() => {
+ fn();
+ global.window = initialWindow;
+ global.document = initialDocument;
+ packager.packageLog = initialPackage;
+ expect(callCount).to.equal(2);
+ done();
+ }, rate + 1);
+ }
+ }
+ };
+ attachHandlers({ resolution: rate });
+ });
describe('defineDetails', () => {
+ // TODO: clarify what constitutes "high detail events" and what is "correct"
it('configures high detail events correctly');
});
});
[8/8] incubator-senssoft-useralejs git commit: Added test coverage
for configure_spec and packageLogs
Posted by rf...@apache.org.
Added test coverage for configure_spec and packageLogs
Project: http://git-wip-us.apache.org/repos/asf/incubator-senssoft-useralejs/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-senssoft-useralejs/commit/416450cd
Tree: http://git-wip-us.apache.org/repos/asf/incubator-senssoft-useralejs/tree/416450cd
Diff: http://git-wip-us.apache.org/repos/asf/incubator-senssoft-useralejs/diff/416450cd
Branch: refs/heads/master
Commit: 416450cdbc6324ef90eec3f65d6e8eb22c90832f
Parents: 56f1409
Author: Rob Foley <ro...@gmail.com>
Authored: Tue Sep 20 16:59:28 2016 -0400
Committer: Rob Foley <ro...@gmail.com>
Committed: Tue Sep 20 16:59:28 2016 -0400
----------------------------------------------------------------------
test/configure_spec.js | 38 ++++++++-
test/packageLogs.html | 8 ++
test/packageLogs_spec.js | 180 +++++++++++++++++++++++++++++++++++++++---
3 files changed, 211 insertions(+), 15 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-senssoft-useralejs/blob/416450cd/test/configure_spec.js
----------------------------------------------------------------------
diff --git a/test/configure_spec.js b/test/configure_spec.js
index 9f1d6a0..d31f2b4 100644
--- a/test/configure_spec.js
+++ b/test/configure_spec.js
@@ -1,12 +1,44 @@
import { expect } from 'chai';
import jsdom from 'jsdom';
import fs from 'fs';
+import { getUserIdFromParams, configure } from '../src/configure';
describe('configure', () => {
- it('merges new configs into main config object');
+ it('merges new configs into main config object', (done) => {
+ const config = {};
+ const newConfig = { foo: 'bar' };
+ configure(config, newConfig);
+ expect(config).to.deep.equal({ foo: 'bar' });
+ done();
+ });
+
+ it('includes a userid if present in the window.location', (done) => {
+ const config = {};
+ const newConfig = { foo: 'bar', userFromParams: 'user', };
+ const initialWindow = global.window;
+ global.window = { location: { href: '?user=test&'} };
+ configure(config, newConfig);
+ global.window = initialWindow;
+ expect(config).to.deep.equal({ foo: 'bar', userFromParams: 'user', userId: 'test' });
+ done();
+ });
describe('getUserIdFromParams', () => {
- it('fetches userId from URL params');
- it('returns null if no matching param');
+ it('fetches userId from URL params', (done) => {
+ const initialWindow = global.window;
+ global.window = { location: { href: '?user=foo&'} };
+ const userId = getUserIdFromParams('user');
+ global.window = initialWindow;
+ expect(userId).to.equal('foo');
+ done();
+ });
+ it('returns null if no matching param', (done) => {
+ const initialWindow = global.window;
+ global.window = { location: { href: '?user=foo&'} };
+ const userId = getUserIdFromParams('bar');
+ global.window = initialWindow;
+ expect(userId).to.equal(null);
+ done();
+ });
});
});
http://git-wip-us.apache.org/repos/asf/incubator-senssoft-useralejs/blob/416450cd/test/packageLogs.html
----------------------------------------------------------------------
diff --git a/test/packageLogs.html b/test/packageLogs.html
new file mode 100644
index 0000000..3925545
--- /dev/null
+++ b/test/packageLogs.html
@@ -0,0 +1,8 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+</head>
+<body>
+ <div id="test"></div>
+</body>
+</html>
http://git-wip-us.apache.org/repos/asf/incubator-senssoft-useralejs/blob/416450cd/test/packageLogs_spec.js
----------------------------------------------------------------------
diff --git a/test/packageLogs_spec.js b/test/packageLogs_spec.js
index d651ba4..d5401fa 100644
--- a/test/packageLogs_spec.js
+++ b/test/packageLogs_spec.js
@@ -1,24 +1,180 @@
import { expect } from 'chai';
import jsdom from 'jsdom';
import fs from 'fs';
+import * as mod from '../src/packageLogs';
describe('packageLogs', () => {
- it('packages a log');
+ const url = 'file://' + __dirname + '/packageLogs.html';
+ const html = fs.readFileSync(__dirname + '/packageLogs.html');
- describe('getLocation', function(done) {
- it('returns event page location');
- it('calculates page location if unavailable');
- it('fails to null');
+ describe('packageLog', () => {
+ it('only executes if on', (done) => {
+ mod.initPackager([], { on: true });
+ const evt = { target: {}, type: 'test' };
+ expect(mod.packageLog(evt)).to.equal(true);
+
+ mod.initPackager([], { on: false });
+ expect(mod.packageLog({})).to.equal(false);
+
+ done();
+ });
+ it('calls detailFcn with the event as an argument if provided', (done) => {
+ mod.initPackager([], { on: true });
+ let called = false;
+ const evt = { target: {}, type: 'test' };
+ const detailFcn = (e) => {
+ called = true;
+ expect(e).to.equal(evt);
+ };
+ mod.packageLog(evt, detailFcn);
+ expect(called).to.equal(true);
+ done();
+ });
+ it('packages logs', (done) => {
+ mod.initPackager([], { on: true });
+ const evt = {
+ target: {},
+ type: 'test'
+ };
+ expect(mod.packageLog(evt)).to.equal(true);
+ done();
+ });
});
- describe('getSelector', function(done) {
- it('builds a selector');
- it('identifies window');
- it('fails to Unknown');
+ describe('getLocation', () => {
+ it('returns event page location', (done) => {
+ jsdom.env({
+ url, html,
+ done: (err, window) => {
+ const document = window.document;
+ const ele = document.createElement('div');
+ const evt = new window.MouseEvent('click', {
+ 'view': window,
+ 'bubbles': true,
+ 'cancelable': true
+ });
+ document.body.appendChild(ele);
+ ele.addEventListener('click', (e) => {
+ e.pageX = 0;
+ e.pageY = 0;
+ expect(mod.getLocation(e)).to.deep.equal({ x: 0, y: 0 });
+ done();
+ });
+ ele.dispatchEvent(evt);
+ },
+ });
+ });
+
+ it('calculates page location if unavailable', (done) => {
+ jsdom.env({
+ url, html,
+ done: (err, window) => {
+ const document = window.document;
+ const ele = document.createElement('div');
+ const evt = new window.MouseEvent('click', {
+ 'view': window,
+ 'bubbles': true,
+ 'cancelable': true
+ });
+ document.body.appendChild(ele);
+ ele.addEventListener('click', (e) => {
+ document.documentElement.scrollLeft = 0;
+ document.documentElement.scrollTop = 0;
+ const originalDocument = global.document;
+ global.document = document;
+ expect(mod.getLocation(e)).to.deep.equal({ x: 0, y: 0 });
+ global.document = originalDocument;
+ done();
+ });
+ ele.dispatchEvent(evt);
+ },
+ });
+ });
+
+ it('fails to null', (done) => {
+ let hadError = false;
+ try {
+ mod.getLocation(null);
+ } catch (e) {
+ hadError = true;
+ }
+ expect(hadError).to.equal(true);
+ done();
+ });
});
- describe('buildPath', function(done) {
- it('builds a path');
- it('defaults to path if available');
+ describe('getSelector', () => {
+ it('builds a selector', (done) => {
+ jsdom.env({
+ url, html,
+ done: (err, window) => {
+ const document = window.document;
+ const element = document.createElement('div');
+ expect(mod.getSelector(element)).to.equal('div');
+ element.id = 'bar';
+ expect(mod.getSelector(element)).to.equal('div#bar');
+ element.removeAttribute('id');
+ element.classList.add('baz');
+ expect(mod.getSelector(element)).to.equal('div.baz');
+ element.id = 'bar';
+ expect(mod.getSelector(element)).to.equal('div#bar.baz');
+ done();
+ },
+ });
+ });
+
+ it('identifies window', (done) => {
+ jsdom.env({
+ url, html,
+ done: (err, window) => {
+ expect(mod.getSelector(window)).to.equal('Window');
+ done();
+ },
+ });
+ });
+
+ it('handles a non-null unknown value', (done) => {
+ expect(mod.getSelector('foo')).to.equal('Unknown');
+ done();
+ });
+ });
+
+ describe('buildPath', () => {
+ it('builds a path', (done) => {
+ jsdom.env({
+ url, html,
+ done: (err, window) => {
+ const document = window.document;
+ const ele = document.createElement('div');
+ const evt = document.createEvent('CustomEvent');
+ evt.initEvent('testEvent', true, true);
+ document.body.appendChild(ele);
+ ele.addEventListener('testEvent', (e) => {
+ expect(mod.buildPath(e)).to.deep.equal(['div', 'body', 'html']);
+ done();
+ });
+ ele.dispatchEvent(evt);
+ },
+ });
+ });
+
+ it('defaults to path if available', (done) => {
+ jsdom.env({
+ url, html,
+ done: (err, window) => {
+ const document = window.document;
+ const ele = document.createElement('div');
+ const evt = document.createEvent('CustomEvent');
+ evt.initEvent('testEvent', true, true);
+ document.body.appendChild(ele);
+ ele.addEventListener('testEvent', (e) => {
+ e.path = [ele, ele.parentElement, ele.parentElement.parentElement];
+ expect(mod.buildPath(e)).to.deep.equal(['div', 'body', 'html']);
+ done();
+ });
+ ele.dispatchEvent(evt);
+ },
+ });
+ });
});
});
[7/8] incubator-senssoft-useralejs git commit: Removed unnecessary
console message.
Posted by rf...@apache.org.
Removed unnecessary console message.
Project: http://git-wip-us.apache.org/repos/asf/incubator-senssoft-useralejs/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-senssoft-useralejs/commit/56f1409e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-senssoft-useralejs/tree/56f1409e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-senssoft-useralejs/diff/56f1409e
Branch: refs/heads/master
Commit: 56f1409ef357b8d83dd4035e56ec97c75c7d011a
Parents: 7e52366
Author: Rob Foley <ro...@gmail.com>
Authored: Tue Sep 20 16:58:11 2016 -0400
Committer: Rob Foley <ro...@gmail.com>
Committed: Tue Sep 20 16:58:11 2016 -0400
----------------------------------------------------------------------
src/sendLogs.js | 1 -
1 file changed, 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-senssoft-useralejs/blob/56f1409e/src/sendLogs.js
----------------------------------------------------------------------
diff --git a/src/sendLogs.js b/src/sendLogs.js
index 006693d..41c5798 100644
--- a/src/sendLogs.js
+++ b/src/sendLogs.js
@@ -22,7 +22,6 @@ export function sendOnInterval(logs, config) {
if (logs.length >= config.logCountThreshold) {
var data = logs;
logs = [];
- // console.log(data);
sendLogs(data, config.url, 5);
}
}, config.transmitInterval);
[5/8] incubator-senssoft-useralejs git commit: Added test for
performance timing. Converted most stuff to ES6 syntax.
Posted by rf...@apache.org.
Added test for performance timing. Converted most stuff to ES6 syntax.
Project: http://git-wip-us.apache.org/repos/asf/incubator-senssoft-useralejs/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-senssoft-useralejs/commit/2718a067
Tree: http://git-wip-us.apache.org/repos/asf/incubator-senssoft-useralejs/tree/2718a067
Diff: http://git-wip-us.apache.org/repos/asf/incubator-senssoft-useralejs/diff/2718a067
Branch: refs/heads/master
Commit: 2718a0679b8c5f93db8c241c550cfd578381db2b
Parents: 87b43c7
Author: Rob Foley <ro...@gmail.com>
Authored: Tue Sep 20 12:08:20 2016 -0400
Committer: Rob Foley <ro...@gmail.com>
Committed: Tue Sep 20 12:20:00 2016 -0400
----------------------------------------------------------------------
test/getInitialSettings_spec.js | 45 ++++++++++++++++++++++--------------
1 file changed, 28 insertions(+), 17 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-senssoft-useralejs/blob/2718a067/test/getInitialSettings_spec.js
----------------------------------------------------------------------
diff --git a/test/getInitialSettings_spec.js b/test/getInitialSettings_spec.js
index 68ec3eb..c8dcf51 100644
--- a/test/getInitialSettings_spec.js
+++ b/test/getInitialSettings_spec.js
@@ -8,37 +8,48 @@ import { version } from '../package.json';
describe('getInitialSettings', () => {
describe('timeStampScale', () => {
it('no event.timestamp', () => {
- var e = {};
- var ts = timeStampScale(e);
+ const e = {};
+ const ts = timeStampScale(e);
expect(ts(e.timeStamp)).to.be.closeTo(Date.now(), 50);
});
it('zero', () => {
- var e = { timeStamp : 0 };
- var ts = timeStampScale(e);
+ const e = { timeStamp : 0 };
+ const ts = timeStampScale(e);
expect(ts(e.timeStamp)).to.be.closeTo(Date.now(), 50);
});
it('epoch milliseconds', () => {
- var e = { timeStamp : 1451606400000 };
- var ts = timeStampScale(e);
+ const e = { timeStamp : 1451606400000 };
+ const ts = timeStampScale(e);
expect(ts(e.timeStamp)).to.equal(1451606400000);
});
it('epoch microseconds', () => {
- var e = { timeStamp : 1451606400000000 };
- var ts = timeStampScale(e);
+ const e = { timeStamp : 1451606400000000 };
+ const ts = timeStampScale(e);
expect(ts(e.timeStamp)).to.equal(1451606400000);
});
// Currently unsupported in jsdom
// Chrome specific -- manual testing is clear;
- it('performance navigation time');
+ it('performance navigation time', (done) => {
+ const terriblePolyfill = { timing: { navigationStart: Date.now() } };
+ const originalPerformance = global.performance;
+ global.performance = global.performance === undefined
+ ? terriblePolyfill
+ : originalPerformance;
+ const e = { timeStamp: 1 };
+ const ts = timeStampScale(e);
+ expect(ts(e.timeStamp)).to.equal(performance.timing.navigationStart + e.timeStamp);
+ global.performance = originalPerformance;
+ done();
+ });
});
describe('getInitialSettings', () => {
- it('fetches all settings from a script tag', function(done) {
- var html = fs.readFileSync(__dirname + '/getInitialSettings_fetchAll.html');
+ it('fetches all settings from a script tag', (done) => {
+ const html = fs.readFileSync(__dirname + '/getInitialSettings_fetchAll.html');
jsdom.env({
html : html,
@@ -47,8 +58,8 @@ describe('getInitialSettings', () => {
FetchExternalResources : ['script'],
ProcessExternalResources : ['script']
},
- done : function(err, window) {
- var config = window.userale.options();
+ done : (err, window) => {
+ const config = window.userale.options();
expect(config).to.have.property('autostart', true);
expect(config).to.have.property('url', 'http://test.com');
expect(config).to.have.property('transmitInterval', 100);
@@ -64,8 +75,8 @@ describe('getInitialSettings', () => {
});
});
- it('grabs user id from params', function(done) {
- var html = fs.readFileSync(__dirname + '/getInitialSettings_userParam.html');
+ it('grabs user id from params', (done) => {
+ const html = fs.readFileSync(__dirname + '/getInitialSettings_userParam.html');
jsdom.env({
html : html,
@@ -74,8 +85,8 @@ describe('getInitialSettings', () => {
FetchExternalResources : ['script'],
ProcessExternalResources : ['script']
},
- done : function(err, window) {
- var config = window.userale.options();
+ done : (err, window) => {
+ const config = window.userale.options();
expect(config.userId).to.equal('testuser');
window.close();
done();
[3/8] incubator-senssoft-useralejs git commit: Added test for custom
logs. Finished converting to ES6.
Posted by rf...@apache.org.
Added test for custom logs. Finished converting to ES6.
Project: http://git-wip-us.apache.org/repos/asf/incubator-senssoft-useralejs/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-senssoft-useralejs/commit/bcb96cbc
Tree: http://git-wip-us.apache.org/repos/asf/incubator-senssoft-useralejs/tree/bcb96cbc
Diff: http://git-wip-us.apache.org/repos/asf/incubator-senssoft-useralejs/diff/bcb96cbc
Branch: refs/heads/master
Commit: bcb96cbc9cb569fb28a09f2c0c624acec4f05c86
Parents: 355f4c2
Author: Rob Foley <ro...@gmail.com>
Authored: Tue Sep 20 10:37:02 2016 -0400
Committer: Rob Foley <ro...@gmail.com>
Committed: Tue Sep 20 10:37:02 2016 -0400
----------------------------------------------------------------------
test/main_spec.js | 45 ++++++++++++++++++++++++++++++++-------------
1 file changed, 32 insertions(+), 13 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-senssoft-useralejs/blob/bcb96cbc/test/main_spec.js
----------------------------------------------------------------------
diff --git a/test/main_spec.js b/test/main_spec.js
index 0a820b4..611a06d 100644
--- a/test/main_spec.js
+++ b/test/main_spec.js
@@ -6,7 +6,7 @@ describe('Userale API', () => {
var file = 'file://' + __dirname + '/main.html';
var html = fs.readFileSync(__dirname + '/main.html');
- it('provides configs', function(done) {
+ it('provides configs', (done) => {
jsdom.env({
html : html,
url : file,
@@ -14,8 +14,8 @@ describe('Userale API', () => {
FetchExternalResources : ['script'],
ProcessExternalResources : ['script']
},
- done : function(err, window) {
- var config = window.userale.options();
+ done : (err, window) => {
+ const config = window.userale.options();
expect(config).to.be.an('object');
expect(config).to.have.all.keys([
'on',
@@ -38,7 +38,7 @@ describe('Userale API', () => {
});
});
- it('edits configs', function(done) {
+ it('edits configs', (done) => {
jsdom.env({
html : html,
url : file,
@@ -46,13 +46,13 @@ describe('Userale API', () => {
FetchExternalResources : ['script'],
ProcessExternalResources : ['script']
},
- done : function(err, window) {
- var config = window.userale.options();
- var interval = config.transmitInterval;
+ done : (err, window) => {
+ const config = window.userale.options();
+ const interval = config.transmitInterval;
window.userale.options({
transmitInterval : interval + 10
});
- var newConfig = window.userale.options();
+ const newConfig = window.userale.options();
expect(newConfig.transmitInterval).to.equal(interval + 10);
window.close();
@@ -61,7 +61,7 @@ describe('Userale API', () => {
});
});
- it('starts + stops', function(done) {
+ it('starts + stops', (done) => {
jsdom.env({
html : html,
url : file,
@@ -69,9 +69,9 @@ describe('Userale API', () => {
FetchExternalResources : ['script'],
ProcessExternalResources : ['script']
},
- done : function(err, window) {
- setTimeout(function() {
- var userale = window.userale;
+ done : (err, window) => {
+ setTimeout(() => {
+ const { userale } = window;
expect(userale.options().on).to.equal(true);
userale.stop();
@@ -87,5 +87,24 @@ describe('Userale API', () => {
});
});
- it('sends custom logs');
+ it('sends custom logs', (done) => {
+ jsdom.env({
+ html: html,
+ url: file,
+ features : {
+ FetchExternalResources : ['script'],
+ ProcessExternalResources : ['script']
+ },
+ done: (err, window) => {
+ const { userale } = window;
+
+ expect(userale.log({})).to.equal(true);
+ expect(userale.log()).to.equal(false);
+ expect(userale.log(null)).to.equal(false);
+
+ window.close();
+ done();
+ }
+ });
+ });
});