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 <rob.foley...@gmail.com>
Authored: Tue Sep 20 12:08:20 2016 -0400
Committer: Rob Foley <rob.foley...@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();

Reply via email to