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/21 21:04:00 UTC
[1/2] incubator-senssoft-useralejs git commit: Added tests for
sendLogs.
Repository: incubator-senssoft-useralejs
Updated Branches:
refs/heads/master f25b9cb00 -> fbdbcb9c1
Added tests for sendLogs.
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/c610177f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-senssoft-useralejs/tree/c610177f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-senssoft-useralejs/diff/c610177f
Branch: refs/heads/master
Commit: c610177f156a9d2f71c32cc7991ae7aa4b24d846
Parents: f25b9cb
Author: Rob Foley <ro...@gmail.com>
Authored: Wed Sep 21 17:03:02 2016 -0400
Committer: Rob Foley <ro...@gmail.com>
Committed: Wed Sep 21 17:03:02 2016 -0400
----------------------------------------------------------------------
test/sendLogs_spec.js | 97 ++++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 94 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-senssoft-useralejs/blob/c610177f/test/sendLogs_spec.js
----------------------------------------------------------------------
diff --git a/test/sendLogs_spec.js b/test/sendLogs_spec.js
index 477147e..5da5157 100644
--- a/test/sendLogs_spec.js
+++ b/test/sendLogs_spec.js
@@ -16,9 +16,100 @@
*/
import { expect } from 'chai';
import jsdom from 'jsdom';
-import fs from 'fs';
+import sinon from 'sinon';
+import { sendOnInterval, sendOnClose } from '../src/sendLogs';
describe('sendLogs', () => {
- it('sends logs on an interval');
- it('sends logs on page exit');
+ it('sends logs on an interval', (done) => {
+ let requests = 0;
+ const originalXMLHttpRequest = global.XMLHttpRequest;
+ const conf = { transmitInterval: 500, url: 'test', logCountThreshold: 2 };
+ const logs = [];
+ const clock = sinon.useFakeTimers();
+ const xhr = sinon.useFakeXMLHttpRequest();
+ global.XMLHttpRequest = xhr;
+ xhr.onCreate = () => { requests++; };
+
+ sendOnInterval(logs, conf);
+
+ clock.tick(conf.transmitInterval * 2);
+ // Make sure it doesn't make requests for no raisin
+ expect(requests).to.equal(0);
+
+ // Make sure it respects the logCountThreshold
+ logs.push({ foo: 'bar1' });
+ clock.tick(conf.transmitInterval);
+ expect(logs.length).to.equal(1);
+
+ // Make sure it sends the logs and clears the array
+ logs.push({ foo: 'bar2' });
+ clock.tick(conf.transmitInterval);
+ expect(logs.length).to.equal(0);
+ expect(requests).to.equal(1);
+
+ xhr.restore();
+ clock.restore();
+ global.XMLHttpRequest = originalXMLHttpRequest;
+ done();
+ });
+ it('sends logs on page exit with navigator', (done) => {
+ const html = `<html><head></head><body></body></html>`;
+ jsdom.env({
+ html,
+ done: (err, window) => {
+ const originalNavigator = global.navigator;
+ const originalWindow = global.window;
+ let called = false;
+ global.window = window;
+ global.navigator = {
+ sendBeacon: () => {
+ called = true;
+ },
+ };
+
+ const evt = window.document.createEvent('CustomEvent');
+ evt.initEvent('unload', true, true);
+ sendOnClose([{ foo: 'bar' }], { url: 'test' });
+
+ window.dispatchEvent(evt);
+ window.close();
+
+ expect(called).to.equal(true);
+ global.window = originalWindow;
+ global.navigator = originalNavigator;
+ done();
+ }
+ });
+ });
+ it('sends logs on page exit without navigator', (done) => {
+ const html = `<html><head></head><body></body></html>`;
+ jsdom.env({
+ html,
+ done: (err, window) => {
+ const originalNavigator = global.navigator;
+ const originalXMLHttpRequest = global.XMLHttpRequest;
+ const originalWindow = global.window;
+ let requests = 0;
+ const xhr = sinon.useFakeXMLHttpRequest();
+ global.XMLHttpRequest = xhr;
+ global.window = window;
+ global.XMLHttpRequest = xhr;
+ global.navigator = { sendBeacon: false, };
+ xhr.onCreate = () => { requests++; };
+
+ const evt = window.document.createEvent('CustomEvent');
+ evt.initEvent('beforeunload', true, true);
+ sendOnClose([{ foo: 'bar' }], { url: 'test' });
+
+ window.dispatchEvent(evt);
+ window.close();
+
+ expect(requests).to.equal(1);
+ global.window = originalWindow;
+ global.navigator = originalNavigator;
+ global.XMLHttpRequest = originalXMLHttpRequest;
+ done();
+ }
+ });
+ });
});
[2/2] incubator-senssoft-useralejs git commit: Added dependency for
sinon
Posted by rf...@apache.org.
Added dependency for sinon
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/fbdbcb9c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-senssoft-useralejs/tree/fbdbcb9c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-senssoft-useralejs/diff/fbdbcb9c
Branch: refs/heads/master
Commit: fbdbcb9c176ad53312919195a293e06b16730bdb
Parents: c610177
Author: Rob Foley <ro...@gmail.com>
Authored: Wed Sep 21 17:03:20 2016 -0400
Committer: Rob Foley <ro...@gmail.com>
Committed: Wed Sep 21 17:03:20 2016 -0400
----------------------------------------------------------------------
package.json | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-senssoft-useralejs/blob/fbdbcb9c/package.json
----------------------------------------------------------------------
diff --git a/package.json b/package.json
index c44669f..419feac 100644
--- a/package.json
+++ b/package.json
@@ -44,6 +44,7 @@
"jsdom": "^8.4.0",
"nodemon": "^1.9.2",
"rollup": "^0.26.0",
- "rollup-plugin-json": "^2.0.1"
+ "rollup-plugin-json": "^2.0.1",
+ "sinon": "^1.17.6"
}
}