Skip to content

Commit

Permalink
Track barometer request times
Browse files Browse the repository at this point in the history
  • Loading branch information
slavcho-slavchev-hx committed Jul 29, 2016
1 parent eeb6600 commit 7b717bd
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 12 deletions.
54 changes: 44 additions & 10 deletions dist/barometer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ transport._flushBuffer = function (pageEnd) {
if (navigator.sendBeacon) {
navigator.sendBeacon(url, JSON.stringify(bufferToSend))
} else {
var xhr = new xhrStats._XMLHttpRequest()
var xhr = new window.XMLHttpRequest()
xhr.open('POST', url, !pageEnd)
xhr.setRequestHeader('Content-Type', 'application/json')
xhr.send(JSON.stringify(bufferToSend))
Expand Down Expand Up @@ -1498,7 +1498,7 @@ function drainQueue() {
if (draining) {
return;
}
var timeout = cachedSetTimeout(cleanUpNextTick);
var timeout = cachedSetTimeout.call(null, cleanUpNextTick);
draining = true;

var len = queue.length;
Expand All @@ -1515,7 +1515,7 @@ function drainQueue() {
}
currentQueue = null;
draining = false;
cachedClearTimeout(timeout);
cachedClearTimeout.call(null, timeout);
}

process.nextTick = function (fun) {
Expand All @@ -1527,7 +1527,7 @@ process.nextTick = function (fun) {
}
queue.push(new Item(fun, args));
if (queue.length === 1 && !draining) {
cachedSetTimeout(drainQueue, 0);
cachedSetTimeout.call(null, drainQueue, 0);
}
};

Expand Down Expand Up @@ -2065,6 +2065,24 @@ var sinon = (function () { // eslint-disable-line no-unused-vars
}
}

function verifyIsValidAssertion(assertionMethod, assertionArgs) {
switch (assertionMethod) {
case "notCalled":
case "called":
case "calledOnce":
case "calledTwice":
case "calledThrice":
if (assertionArgs.length !== 0) {
assert.fail(assertionMethod +
" takes 1 argument but was called with " +
(assertionArgs.length + 1) + " arguments");
}
break;
default:
break;
}
}

function failAssertion(object, msg) {
object = object || global;
var failMethod = object.fail || assert.fail;
Expand All @@ -2081,6 +2099,8 @@ var sinon = (function () { // eslint-disable-line no-unused-vars
verifyIsStub(fake);

var args = slice.call(arguments, 1);
verifyIsValidAssertion(name, args);

var failed = false;

if (typeof method === "function") {
Expand Down Expand Up @@ -5464,7 +5484,7 @@ var sinon = (function () { // eslint-disable-line no-unused-vars
}

for (prop in a) {
if (a.hasOwnProperty(prop)) {
if (hasOwn.call(a, prop)) {
aLength += 1;

if (!(prop in b)) {
Expand All @@ -5478,7 +5498,7 @@ var sinon = (function () { // eslint-disable-line no-unused-vars
}

for (prop in b) {
if (b.hasOwnProperty(prop)) {
if (hasOwn.call(b, prop)) {
bLength += 1;
}
}
Expand Down Expand Up @@ -6556,7 +6576,7 @@ if (typeof sinon === "undefined") {
}

var xhr = this;
var events = ["loadstart", "load", "abort", "loadend"];
var events = ["loadstart", "load", "abort", "error", "loadend"];

function addEventListener(eventName) {
xhr.addEventListener(eventName, function (event) {
Expand Down Expand Up @@ -6890,12 +6910,16 @@ if (typeof sinon === "undefined") {
}

if (this.readyState === FakeXMLHttpRequest.DONE) {
if (this.status < 200 || this.status > 299) {
progress = {loaded: 0, total: 0};
// ensure loaded and total are numbers
progress = {
loaded: this.progress || 0,
total: this.progress || 0
};

if (this.status === 0) {
event = this.aborted ? "abort" : "error";
}
else {
progress = {loaded: 100, total: 100};
event = "load";
}

Expand Down Expand Up @@ -6988,6 +7012,15 @@ if (typeof sinon === "undefined") {
this.readyState = FakeXMLHttpRequest.UNSENT;
},

error: function error() {
clearResponse(this);
this.errorFlag = true;
this.requestHeaders = {};
this.responseHeaders = {};

this.readyStateChange(FakeXMLHttpRequest.DONE);
},

getResponseHeader: function getResponseHeader(header) {
if (this.readyState < FakeXMLHttpRequest.HEADERS_RECEIVED) {
return null;
Expand Down Expand Up @@ -7051,6 +7084,7 @@ if (typeof sinon === "undefined") {
} else if (this.responseType === "" && isXmlContentType(contentType)) {
this.responseXML = FakeXMLHttpRequest.parseXML(this.responseText);
}
this.progress = body.length;
this.readyStateChange(FakeXMLHttpRequest.DONE);
},

Expand Down
2 changes: 1 addition & 1 deletion dist/barometer.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/transport.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ transport._flushBuffer = function (pageEnd) {
if (navigator.sendBeacon) {
navigator.sendBeacon(url, JSON.stringify(bufferToSend))
} else {
var xhr = new xhrStats._XMLHttpRequest()
var xhr = new window.XMLHttpRequest()
xhr.open('POST', url, !pageEnd)
xhr.setRequestHeader('Content-Type', 'application/json')
xhr.send(JSON.stringify(bufferToSend))
Expand Down

0 comments on commit 7b717bd

Please sign in to comment.