From 2aeaf2ae3ccb95a1721d8a39d1d35bf83a581152 Mon Sep 17 00:00:00 2001 From: Oliver Rumbelow Date: Fri, 29 Jul 2016 22:11:11 +0100 Subject: [PATCH 1/4] Metrics for page resources --- README.md | 1 + dist/barometer.min.js | 2 +- lib/barometer.js | 1 + lib/pageResources.js | 52 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 lib/pageResources.js diff --git a/README.md b/README.md index 13194a3..77be737 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,7 @@ Metrics are gathered in the format used by a statsd / graphite / grafana stack - * PageChange - When the page loads, or whenever a navigation event occurs, we log a counter for the page visit and a gauge for how long the page load took. The page load is a measure of the time between the navigation event firing, the event loop lagging for over 25ms and finally the event loop freeing up for 125ms. Basically we wait for the page to get busy, then we wait for it to finish being busy. * PageLoad - We use `window.performance` to get details of the initial page load. * XhrStats - We monkey-patch over `XMLHttpRequest` in order to identify every AJAX request, the destination, the transition between states, final response size and timing. +* PageResources - `connectEnd`, `connectStart`, `domainLookupEnd`, `domainLookupStart`, `duration`, `fetchStart`, `redirectEnd`, `redirectStart`, `requestStart`, `responseEnd`, `responseStart`, `secureConnectionStart`, `startTime`, `workerStart`. ### How are the metrics transmitted? diff --git a/dist/barometer.min.js b/dist/barometer.min.js index 30d5972..c4f1d92 100644 --- a/dist/barometer.min.js +++ b/dist/barometer.min.js @@ -1,2 +1,2 @@ /*! barometer v1.0.0 */ -_='!e t(na) a;r=a={œ:{id:n,„ed:!1}; e.call(r,r,r,tr.„ed=!0,r}a={}; t.m=%.c=a,t.p="Kt(0)}([%,ae#1)=‚2Qa(6a(3a(7š‘,n =r ,=r.3u#1Qš="XXXXXKe={’s:{ers:{}=0e(e8=8||0,8++ Ke)n %†=†||[],†.push(t) ’K%)};o‘;toW<100W…oo=a,5e3)ae0›Wu.šoW(…oo‘Qt=;e(Qa=u.š;if(€)€(a,@Qelse{i=new r.n;i.op("POSTKa,!ei.RHeader("C`tt-TypeK"applicFi`/js`"i.sd(@i.timeout=4e3}}~n=ƒ;i=["UNSENTK"OPENEDK"HEADERS_RECEIVEDK"LOADINGK"DONE"];re"xhr."+eu%,an={“:a}rŽe)"_"›r[0]W0›e[r]W(n[r]=e[r]-tQ no,a,r=o(ši=u(Times,off,“)sŽi)t="timing$‡ (a,i[s]Qt="žs .(at="size (a,(r.žText•.lgth)ƒe=new n;try{t={a=op,u=sd;opu,otry{s=;r(e,"readystFechangeKt[i[]]=!1r(e,"„dKa o({type:u,š:o,Times:t,off:s,“:-s,r:e})!1)}cFch(c} a,sd u}cFch(o} e,aZ?Z(t,a,!1):ˆWˆ("`"+t,a)a=(e•YŠ^https?:\\/\\//i,"")\\/*;(t•.mFch(/\\?/)W(a+=tYslice(1)\\/*a~u={a=™;e=toJSON()nŽe)"™"›nW0›eW(t=e-aQ tr=o(‰ref,‰ashQ"page„."+t”e*i%=.timing||{a=u(t)rŽa)e=r(ru (e,a[r]Qo=(.i`||{}).—Count||0;e=r("—s"u (e,o)"object"==typeof W("complete"===documt.?i():r(,"„Ki,!1)),r,u=e={o#4i#6s#2c=0;u.ss (r,-n)u.fs.(–visits")nWu.s(c++;e=,t=c,a=0,o=[9,9,9,9,9],f=!1,g=25,l=–dynamic"p…dn=,r=–gagemt"Qt=125;s (l,-e-t)d=f=!06e3ve=;n=,r=n-e-g;if(r>aW(a=r!ft›c) p(Qo.shift(o.push(r)u=0,i=0;i<5;i++)u+=o[i]; u<5Wa>25?p():void v,g)}g)};v()u.f(Œ?(o(,"popstF˜e=‹;‹ u.f(t}}(Œ)):o(,"hashchang˜)}]Q(%,aknbuffervar .œreturnwindownew DFe .’ $r.stFu‡ ,t(++,‚.debugWc`sollog("Timeout(.apply(e,argumts)}){),count.Š[^a-z0-9-n.=e={r#readyStFe}%ke%},equestnavigF.performancee.en;for(=#=a($."+type”r”%e,t*]/gi,"_")8.ers[e]@JSON.stringify(t)FatK",Q);W&&Y.split("?")[0].ZaddEvtLister`onk"use strict";~}4u#2o#5Q[n]€or.sdBeac`Size‚.barometerƒ.XMLHttpR„load…clear† s[e]‡s,a=r(tuˆFtachEvt‰.locFiohŠreplace(/‹pushStFeŒ.historysetŽ in if(et‘=null’gauge“total”+"."+•||"")–i.r("—redirect˜eKu.f,!1™i`Startšurl›!==œexportsfuncti`žresp`se';for(Y in $='žœ›š™˜—–•”“’‘ŽŒ‹Š‰ˆ‡†…„ƒ‚€~k`ZYWQKF@8*%$# ')with(_.split($[Y]))_=join(pop());eval(_) \ No newline at end of file +_='!e£ t(n“r~) r~;a=r~={ª:{id:n,ˆed:!1}; e~.call(a,a,a,t a.ˆed=!0,a}r={}; t.m=#.c=r,t.p="",t(0)}([#,re1)=Qa2`r(6 r(3 r(7 r(8 ©=,n =a ,=a.a3 u1`©="XXXXX",eF={žs:{ers:{}†=0e( Fe=||0,++,",e)n F#Œ=Œ||[],Œ.push(t ž",#)};o=;tFoW†<100W‹o o=œr,5e3)rFe“0”†Wu.©oW(‹o o=`t=;e(`r=u.©;“„)„(r,€`else{i=new a.n;i.op@("POST",r,!e i.œRHeader("Cont@t-Type","applicYion/json" i.s@d(€ i.timeout=4e3}}‚n=‡;i=["UNSENT","OPENED","HEADERS_RECEIVED","LOADING","DONE"];aFe"xhr."+euF#,rn={Ÿ:r}a‰e)"_"”a[0]W0”e[a]W(n[a]=e[a]-t` noFet,r,a=o(© i=u(Times,offœ,Ÿ)s‰i)t="timingšŽ (r,i[s]`t="¤s.(r t="size (r,(r.¤Text .¢)‡Fe=new n;try{t={r=op@,u=s@d;op@Fu,otry{s=;a(e,"readystYechange",t[i[]]=!1 a(e,"ˆ@d",r o({…:u,©:o,Times:t,offœ:s,Ÿ:-s,r:e})!1)}cŠc} r,s@dF u}cŠo} e›,rƒ?ƒ(t,r,!1):W("on"+t,r)›r=(e  ^Z\\/*;(t .mŠ/\\?/)W(r+=t.slice(1)Z\\/* r‚uF{r=˜;e=toJSON()n‰e)"˜"”nW0”e~W(t~=e~-r` taFo(‘ref,‘ash`"pageˆ."+tKeZ*iF#=.timing||{r=u(t)a‰r)e=a(a u (e,r[a]`o=(.$ion||{}).¦Count||0;e=a("¦s" u (e,o)"object"==…of W("complete"===docum@t.?i():a(,"ˆ",i,!1)),a,uo4 i6 s2 c=0;u.sFs (a,-n)u.fFs.(¡visits") nWu.s( c++;e=,t=c,r=0,o=[9,9,9,9,9],f=!1,g=25,l=¡dynamic" pF‹d n=,a=¡@gagem@t"`t=125;s (l,-e-t)d=œf=!06e3 vFe=;œn=,a=n-e-g;“a>rW(r=a !f“t”c) p(`o¨o.push(a)u=0,i=0;i<5;i++)u+=o[i]; u<5Wr>25?p():void œv,g)}g)};v()u.f( —?(o(,"popstY• e“–;–F u.f( t}}(—)):o(,"hashchang•),au7 o2 i=0,s=;u.onPageChange(i=-se=.getEntries(`n++;n<¢)(e~)} F(e`tW«(#)FQ.r%s;“tfor(’¥/" n=r¨a=r.join("/" u=0;u Date: Sun, 31 Jul 2016 10:55:49 +0100 Subject: [PATCH 2/4] Metrics for page resources --- README.md | 44 ++++++++++++++++++++++++++++++++++++++++---- lib/pageResources.js | 23 ++++++++++++++--------- 2 files changed, 54 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 77be737..a23ecd9 100644 --- a/README.md +++ b/README.md @@ -42,10 +42,19 @@ Metrics are gathered in the format used by a statsd / graphite / grafana stack - ### What metrics are gathered? -* PageChange - When the page loads, or whenever a navigation event occurs, we log a counter for the page visit and a gauge for how long the page load took. The page load is a measure of the time between the navigation event firing, the event loop lagging for over 25ms and finally the event loop freeing up for 125ms. Basically we wait for the page to get busy, then we wait for it to finish being busy. -* PageLoad - We use `window.performance` to get details of the initial page load. -* XhrStats - We monkey-patch over `XMLHttpRequest` in order to identify every AJAX request, the destination, the transition between states, final response size and timing. -* PageResources - `connectEnd`, `connectStart`, `domainLookupEnd`, `domainLookupStart`, `duration`, `fetchStart`, `redirectEnd`, `redirectStart`, `requestStart`, `responseEnd`, `responseStart`, `secureConnectionStart`, `startTime`, `workerStart`. +#### PageChanged +When the page loads, or whenever a navigation event occurs, we log a counter for the page visit and a gauge for how long the page load took. The page load is a measure of the time between the navigation event firing, the event loop lagging for over 25ms and finally the event loop freeing up for 125ms. Basically we wait for the page to get busy, then we wait for it to finish being busy. This provides a measure for how efficient single page applications are whilst out in the wild. The approach is framework agnostic. + +#### PageLoad +When the HTML document has loaded, we use `window.performance.{timing,navigation}` for details of the initial page load. They provide measures of network performance and initial DOM performance out in the wild. + +#### XhrStats +By subtly altering the behavious of `window.XMLHttpRequest` we can identify every AJAX request made, the destination, the transitioning between states and final response size. This provides a measure of real world API performance, as seen by end users. + +#### PageResources +Whenever the page has finished changing (see PageChanged above) we look back through all the new `PerformanceEntry` objects in `window.performance`, filter out the entries that match a user-defined rule set on (domain, path and/or type) and generate metrics for the user-defined events of interest. This provides adjustable measures of real-world performance sliced up in many different ways. Keep reading for how to configure this functionality. + +Timings are measured as an offset against the most recent `PageChanged` event, which occurs *after* the page has mutated, and as such all timings will be negative. The recorded values should be interpreted with `0` being the point at which the end user thinks the page is ready. This enables us to fairly measure metrics of all resources across a single page application. ### How are the metrics transmitted? @@ -69,6 +78,33 @@ window.barometer = { ``` Other scripts on the page can use this, drastically reducing the barriers to entry for logging application metrics. +### Configuring PageResource metrics + +At it's heart, simply attach an array to `window.barometer.resources`. Each object in the array is a filter which details which resources to match on, and which metrics to gather. + +``` +window.barometer.resources = [ + { + domain: 'example.com', + path: /\.js$/, + type: /.*/, + metrics: [ 'startTime', 'duration' ] + } +] +``` + +#### Filtering + +The following properties are all optional, you can include as many or as few as you like: + + * domain - A string or RegEx of the domain as seen by the end user. + * path - A string or RegEx of the URL path as seen by the end user. + * type - A string or RegEx of the type of `PerformanceEntry` object. + +#### Gathering + +The `metrics` property controls which metrics should be gathered. Possible options are: `connectEnd`, `connectStart`, `domainLookupEnd`, `domainLookupStart`, `duration`, `fetchStart`, `redirectEnd`, `redirectStart`, `requestStart`, `responseEnd`, `responseStart`, `secureConnectionStart`, `startTime`, `workerStart`. + ### What could a complete metrics stack look like? 1. [barometer](https://github.com/holidayextras/barometer) - client-side metric gathering tool diff --git a/lib/pageResources.js b/lib/pageResources.js index 7624492..95d23eb 100644 --- a/lib/pageResources.js +++ b/lib/pageResources.js @@ -8,14 +8,6 @@ var lastIndex var timingOffset = 0 var pageStart = new Date() -pageChange.onPageChange(function () { - timingOffset = (new Date() - pageStart) - var entries = window.performance.getEntries() - for (; lastIndex++; lastIndex < entries.length) { - pageResources.handleResource(entries[lastIndex]) - } -}) - pageResources.handleResource = function (entry) { var metrics = pageResources.findRule(entry) if (!metrics) return @@ -33,7 +25,7 @@ pageResources.findRule = function (entry) { for (var i = 0; i < config.length; i++) { var rule = config[i] if (rule.domain && !domain.match(rule.domain)) continue - if (rule.resourceRegex && !path.match(rule.resourceRegex)) continue + if (rule.path && !path.match(rule.path)) continue if (rule.type && entry.entryType !== rule.type) continue return rule.metrics } @@ -50,3 +42,16 @@ pageResources.track = function (entry, metrics) { transport.gauge(prefix + '.' + i, value) } } + +pageResources.initialise = function () { + if (!window.performance || !window.performance.getEntries) return + + pageChange.onPageChange(function () { + timingOffset = (new Date() - pageStart) + var entries = window.performance.getEntries() + for (; lastIndex++; lastIndex < entries.length) { + pageResources.handleResource(entries[lastIndex]) + } + }) +} +pageResources.initialise() From 1178d4007cf0c49734dc609561ad98a3c065cc44 Mon Sep 17 00:00:00 2001 From: Oliver Rumbelow Date: Sun, 31 Jul 2016 17:11:47 +0100 Subject: [PATCH 3/4] Metrics for page resources --- dist/barometer-test.js | 237 ++++++++++++++++++++++++++++++-------- dist/barometer.min.js | 2 +- lib/pageResources.js | 14 ++- test/testPageResources.js | 73 ++++++++++++ 4 files changed, 273 insertions(+), 53 deletions(-) create mode 100644 test/testPageResources.js diff --git a/dist/barometer-test.js b/dist/barometer-test.js index ab5a6d6..63ad9c8 100644 --- a/dist/barometer-test.js +++ b/dist/barometer-test.js @@ -4,16 +4,17 @@ var tracker = window.barometer = module.exports = {} var transport = require('./transport.js') +var pageChange = require('./pageChange') require('./pageLoadStats.js') require('./xhrStats.js') -var pageChange = require('./pageChange') +require('./pageResources') tracker.url = null tracker.gauge = transport.gauge tracker.count = transport.count tracker.onPageChange = pageChange.onPageChange -},{"./pageChange":3,"./pageLoadStats.js":4,"./transport.js":5,"./xhrStats.js":7}],2:[function(require,module,exports){ +},{"./pageChange":3,"./pageLoadStats.js":4,"./pageResources":5,"./transport.js":6,"./xhrStats.js":8}],2:[function(require,module,exports){ /* global */ 'use strict' module.exports = function (obj, evt, fn) { @@ -109,7 +110,7 @@ pageChange.onPageChange = function (cb) { onPageChange.push(cb) } -},{"./event.js":2,"./pageLoadStats.js":4,"./transport.js":5}],4:[function(require,module,exports){ +},{"./event.js":2,"./pageLoadStats.js":4,"./transport.js":6}],4:[function(require,module,exports){ /* global document window */ 'use strict' var pageLoadStats = module.exports = {} @@ -160,7 +161,72 @@ if (typeof window.performance === 'object') { } } -},{"./event.js":2,"./transport.js":5,"./urlSanitiser.js":6}],5:[function(require,module,exports){ +},{"./event.js":2,"./transport.js":6,"./urlSanitiser.js":7}],5:[function(require,module,exports){ +/* global window */ +'use strict' +var pageResources = module.exports = {} + +var pageChange = require('./pageChange.js') +var transport = require('./transport.js') +var lastIndex = 0 +var timingOffset = 0 +var pageStart + +pageResources.handleResource = function (entry) { + var metrics = pageResources.findRule(entry) + if (!metrics) return + pageResources.track(entry, metrics) +} + +pageResources.findRule = function (entry) { + var config = window.barometer.resources + if (!config) return + + var name = entry.name.replace(/https?:\/\//i, '').split('/') + var domain = name.shift() + var path = name.join('/') + + for (var i = 0; i < config.length; i++) { + var rule = config[i] + if (rule.domain && !domain.match(rule.domain)) continue + if (rule.path && !path.match(rule.path)) continue + if (rule.type && entry.entryType !== rule.type) continue + return rule.metrics + } + return null +} + +pageResources.track = function (entry, metrics) { + var parts = entry.name.replace(/https?:\/\//i, '').split('/') + var prefix = 'resources.' + entry.entryType + '.' + prefix += parts.shift().replace(/[^a-z0-9_]/gi, '_') + prefix += '.' + prefix += parts.join('/').split('?')[0].replace(/[^a-z0-9_]/gi, '_') + + for (var i in metrics) { + i = metrics[i] + var value = entry[i] + if (value === 0) continue + if (i !== 'duration') value = timingOffset - value + transport.gauge(prefix + '.' + i, value) + } +} + +pageResources.initialise = function () { + if (!window.performance || !window.performance.getEntries) return + + pageStart = new Date() + pageChange.onPageChange(function () { + timingOffset = (new Date() - pageStart) + var entries = window.performance.getEntries() + for (; lastIndex < entries.length; lastIndex++) { + pageResources.handleResource(entries[lastIndex]) + } + }) +} +pageResources.initialise() + +},{"./pageChange.js":3,"./transport.js":6}],6:[function(require,module,exports){ /* global window document */ 'use strict' var transport = module.exports = {} @@ -228,7 +294,7 @@ transport._flushBuffer = function (pageEnd) { } } -},{"./barometer.js":1,"./xhrStats":7}],6:[function(require,module,exports){ +},{"./barometer.js":1,"./xhrStats":8}],7:[function(require,module,exports){ 'use strict' module.exports = function (href, hash) { var safeUrl = (href || '').split('?')[0].replace(/^https?:\/\//i, '').replace(/[^a-z0-9-\/]/gi, '_') @@ -238,7 +304,7 @@ module.exports = function (href, hash) { return safeUrl // .replace(/\/\//g, '/') } -},{}],7:[function(require,module,exports){ +},{}],8:[function(require,module,exports){ /* global window */ 'use strict' var xhrStats = module.exports = {} @@ -328,7 +394,7 @@ window.XMLHttpRequest = function () { return req } -},{"./event.js":2,"./transport.js":5,"./urlSanitiser.js":6}],8:[function(require,module,exports){ +},{"./event.js":2,"./transport.js":6,"./urlSanitiser.js":7}],9:[function(require,module,exports){ // http://wiki.commonjs.org/wiki/Unit_Testing/1.0 // // THIS IS NOT TESTED NOR LIKELY TO WORK OUTSIDE V8! @@ -689,7 +755,7 @@ var objectKeys = Object.keys || function (obj) { return keys; }; -},{"util/":12}],9:[function(require,module,exports){ +},{"util/":13}],10:[function(require,module,exports){ if (typeof Object.create === 'function') { // implementation from standard node.js 'util' module module.exports = function inherits(ctor, superCtor) { @@ -714,7 +780,7 @@ if (typeof Object.create === 'function') { } } -},{}],10:[function(require,module,exports){ +},{}],11:[function(require,module,exports){ // shim for using process in browser var process = module.exports = {}; @@ -835,14 +901,14 @@ process.chdir = function (dir) { }; process.umask = function() { return 0; }; -},{}],11:[function(require,module,exports){ +},{}],12:[function(require,module,exports){ module.exports = function isBuffer(arg) { return arg && typeof arg === 'object' && typeof arg.copy === 'function' && typeof arg.fill === 'function' && typeof arg.readUInt8 === 'function'; } -},{}],12:[function(require,module,exports){ +},{}],13:[function(require,module,exports){ (function (process,global){ // Copyright Joyent, Inc. and other Node contributors. // @@ -1432,7 +1498,7 @@ function hasOwnProperty(obj, prop) { } }).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) -},{"./support/isBuffer":11,"_process":10,"inherits":9}],13:[function(require,module,exports){ +},{"./support/isBuffer":12,"_process":11,"inherits":10}],14:[function(require,module,exports){ /** * Sinon core utilities. For internal use only. * @@ -1481,7 +1547,7 @@ var sinon = (function () { // eslint-disable-line no-unused-vars return sinonModule; }()); -},{"./sinon/assert":14,"./sinon/behavior":15,"./sinon/call":16,"./sinon/collection":17,"./sinon/extend":18,"./sinon/format":19,"./sinon/log_error":20,"./sinon/match":21,"./sinon/mock":22,"./sinon/sandbox":23,"./sinon/spy":24,"./sinon/stub":25,"./sinon/test":26,"./sinon/test_case":27,"./sinon/times_in_words":28,"./sinon/typeOf":29,"./sinon/util/core":30,"./sinon/walk":37}],14:[function(require,module,exports){ +},{"./sinon/assert":15,"./sinon/behavior":16,"./sinon/call":17,"./sinon/collection":18,"./sinon/extend":19,"./sinon/format":20,"./sinon/log_error":21,"./sinon/match":22,"./sinon/mock":23,"./sinon/sandbox":24,"./sinon/spy":25,"./sinon/stub":26,"./sinon/test":27,"./sinon/test_case":28,"./sinon/times_in_words":29,"./sinon/typeOf":30,"./sinon/util/core":31,"./sinon/walk":38}],15:[function(require,module,exports){ (function (global){ /** * @depend times_in_words.js @@ -1711,7 +1777,7 @@ var sinon = (function () { // eslint-disable-line no-unused-vars )); }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) -},{"./format":19,"./match":21,"./util/core":30}],15:[function(require,module,exports){ +},{"./format":20,"./match":22,"./util/core":31}],16:[function(require,module,exports){ (function (process){ /** * @depend util/core.js @@ -2086,7 +2152,7 @@ var sinon = (function () { // eslint-disable-line no-unused-vars )); }).call(this,require('_process')) -},{"./extend":18,"./util/core":30,"_process":10}],16:[function(require,module,exports){ +},{"./extend":19,"./util/core":31,"_process":11}],17:[function(require,module,exports){ /** * @depend util/core.js * @depend match.js @@ -2327,7 +2393,7 @@ var sinon = (function () { // eslint-disable-line no-unused-vars typeof sinon === "object" && sinon // eslint-disable-line no-undef )); -},{"./format":19,"./match":21,"./util/core":30}],17:[function(require,module,exports){ +},{"./format":20,"./match":22,"./util/core":31}],18:[function(require,module,exports){ /** * @depend util/core.js * @depend spy.js @@ -2502,7 +2568,7 @@ var sinon = (function () { // eslint-disable-line no-unused-vars typeof sinon === "object" && sinon // eslint-disable-line no-undef )); -},{"./mock":22,"./spy":24,"./stub":25,"./util/core":30}],18:[function(require,module,exports){ +},{"./mock":23,"./spy":25,"./stub":26,"./util/core":31}],19:[function(require,module,exports){ /** * @depend util/core.js */ @@ -2615,7 +2681,7 @@ var sinon = (function () { // eslint-disable-line no-unused-vars typeof sinon === "object" && sinon // eslint-disable-line no-undef )); -},{"./util/core":30}],19:[function(require,module,exports){ +},{"./util/core":31}],20:[function(require,module,exports){ /** * @depend util/core.js */ @@ -2711,7 +2777,7 @@ var sinon = (function () { // eslint-disable-line no-unused-vars typeof formatio === "object" && formatio // eslint-disable-line no-undef )); -},{"./util/core":30,"formatio":38,"util":12}],20:[function(require,module,exports){ +},{"./util/core":31,"formatio":39,"util":13}],21:[function(require,module,exports){ /** * @depend util/core.js */ @@ -2797,7 +2863,7 @@ var sinon = (function () { // eslint-disable-line no-unused-vars typeof sinon === "object" && sinon // eslint-disable-line no-undef )); -},{"./util/core":30}],21:[function(require,module,exports){ +},{"./util/core":31}],22:[function(require,module,exports){ /** * @depend util/core.js * @depend typeOf.js @@ -3060,7 +3126,7 @@ var sinon = (function () { // eslint-disable-line no-unused-vars typeof sinon === "object" && sinon // eslint-disable-line no-undef )); -},{"./typeOf":29,"./util/core":30}],22:[function(require,module,exports){ +},{"./typeOf":30,"./util/core":31}],23:[function(require,module,exports){ /** * @depend times_in_words.js * @depend util/core.js @@ -3553,7 +3619,7 @@ var sinon = (function () { // eslint-disable-line no-unused-vars typeof sinon === "object" && sinon // eslint-disable-line no-undef )); -},{"./call":16,"./extend":18,"./format":19,"./match":21,"./spy":24,"./stub":25,"./times_in_words":28,"./util/core":30}],23:[function(require,module,exports){ +},{"./call":17,"./extend":19,"./format":20,"./match":22,"./spy":25,"./stub":26,"./times_in_words":29,"./util/core":31}],24:[function(require,module,exports){ /** * @depend util/core.js * @depend extend.js @@ -3725,7 +3791,7 @@ var sinon = (function () { // eslint-disable-line no-unused-vars typeof sinon === "object" && sinon // eslint-disable-line no-undef )); -},{"./collection":17,"./extend":18,"./util/core":30,"./util/fake_server_with_clock":33,"./util/fake_timers":34}],24:[function(require,module,exports){ +},{"./collection":18,"./extend":19,"./util/core":31,"./util/fake_server_with_clock":34,"./util/fake_timers":35}],25:[function(require,module,exports){ /** * @depend times_in_words.js * @depend util/core.js @@ -4190,7 +4256,7 @@ var sinon = (function () { // eslint-disable-line no-unused-vars typeof sinon === "object" && sinon // eslint-disable-line no-undef )); -},{"./call":16,"./extend":18,"./format":19,"./times_in_words":28,"./util/core":30}],25:[function(require,module,exports){ +},{"./call":17,"./extend":19,"./format":20,"./times_in_words":29,"./util/core":31}],26:[function(require,module,exports){ /** * @depend util/core.js * @depend extend.js @@ -4392,7 +4458,7 @@ var sinon = (function () { // eslint-disable-line no-unused-vars typeof sinon === "object" && sinon // eslint-disable-line no-undef )); -},{"./behavior":15,"./extend":18,"./spy":24,"./util/core":30}],26:[function(require,module,exports){ +},{"./behavior":16,"./extend":19,"./spy":25,"./util/core":31}],27:[function(require,module,exports){ /** * @depend util/core.js * @depend sandbox.js @@ -4492,7 +4558,7 @@ var sinon = (function () { // eslint-disable-line no-unused-vars } }(typeof sinon === "object" && sinon || null)); // eslint-disable-line no-undef -},{"./sandbox":23,"./util/core":30}],27:[function(require,module,exports){ +},{"./sandbox":24,"./util/core":31}],28:[function(require,module,exports){ /** * @depend util/core.js * @depend test.js @@ -4600,7 +4666,7 @@ var sinon = (function () { // eslint-disable-line no-unused-vars typeof sinon === "object" && sinon // eslint-disable-line no-undef )); -},{"./test":26,"./util/core":30}],28:[function(require,module,exports){ +},{"./test":27,"./util/core":31}],29:[function(require,module,exports){ /** * @depend util/core.js */ @@ -4651,7 +4717,7 @@ var sinon = (function () { // eslint-disable-line no-unused-vars typeof sinon === "object" && sinon // eslint-disable-line no-undef )); -},{"./util/core":30}],29:[function(require,module,exports){ +},{"./util/core":31}],30:[function(require,module,exports){ /** * @depend util/core.js */ @@ -4706,7 +4772,7 @@ var sinon = (function () { // eslint-disable-line no-unused-vars typeof sinon === "object" && sinon // eslint-disable-line no-undef )); -},{"./util/core":30}],30:[function(require,module,exports){ +},{"./util/core":31}],31:[function(require,module,exports){ /** * @depend ../../sinon.js */ @@ -5109,7 +5175,7 @@ var sinon = (function () { // eslint-disable-line no-unused-vars typeof sinon === "object" && sinon // eslint-disable-line no-undef )); -},{}],31:[function(require,module,exports){ +},{}],32:[function(require,module,exports){ /** * Minimal Event interface implementation * @@ -5222,7 +5288,7 @@ if (typeof sinon === "undefined") { } }()); -},{"./core":30}],32:[function(require,module,exports){ +},{"./core":31}],33:[function(require,module,exports){ /** * @depend fake_xdomain_request.js * @depend fake_xml_http_request.js @@ -5471,7 +5537,7 @@ if (typeof sinon === "undefined") { } }()); -},{"../format":19,"./core":30,"./fake_xdomain_request":35,"./fake_xml_http_request":36}],33:[function(require,module,exports){ +},{"../format":20,"./core":31,"./fake_xdomain_request":36,"./fake_xml_http_request":37}],34:[function(require,module,exports){ /** * @depend fake_server.js * @depend fake_timers.js @@ -5574,7 +5640,7 @@ if (typeof sinon === "undefined") { } }()); -},{"./core":30,"./fake_server":32,"./fake_timers":34}],34:[function(require,module,exports){ +},{"./core":31,"./fake_server":33,"./fake_timers":35}],35:[function(require,module,exports){ /** * Fake timer API * setTimeout @@ -5649,7 +5715,7 @@ if (typeof sinon === "undefined") { } }()); -},{"./core":30,"lolex":39}],35:[function(require,module,exports){ +},{"./core":31,"lolex":40}],36:[function(require,module,exports){ (function (global){ /** * @depend core.js @@ -5892,7 +5958,7 @@ if (typeof sinon === "undefined") { })(typeof global !== "undefined" ? global : self); }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) -},{"../extend":18,"../log_error":20,"./core":30,"./event":31}],36:[function(require,module,exports){ +},{"../extend":19,"../log_error":21,"./core":31,"./event":32}],37:[function(require,module,exports){ (function (global){ /** * @depend core.js @@ -6621,7 +6687,7 @@ if (typeof sinon === "undefined") { )); }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) -},{"../extend":18,"../log_error":20,"./core":30,"./event":31}],37:[function(require,module,exports){ +},{"../extend":19,"../log_error":21,"./core":31,"./event":32}],38:[function(require,module,exports){ /** * @depend util/core.js */ @@ -6702,7 +6768,7 @@ if (typeof sinon === "undefined") { typeof sinon === "object" && sinon // eslint-disable-line no-undef )); -},{"./util/core":30}],38:[function(require,module,exports){ +},{"./util/core":31}],39:[function(require,module,exports){ (function (global){ ((typeof define === "function" && define.amd && function (m) { define("formatio", ["samsam"], m); @@ -6919,7 +6985,7 @@ if (typeof sinon === "undefined") { }); }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) -},{"samsam":40}],39:[function(require,module,exports){ +},{"samsam":41}],40:[function(require,module,exports){ (function (global){ /*global global, window*/ /** @@ -7442,7 +7508,7 @@ if (typeof sinon === "undefined") { }(global || this)); }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) -},{}],40:[function(require,module,exports){ +},{}],41:[function(require,module,exports){ ((typeof define === "function" && define.amd && function (m) { define("samsam", m); }) || (typeof module === "object" && function (m) { module.exports = m(); }) || // Node @@ -7843,7 +7909,7 @@ if (typeof sinon === "undefined") { }; }); -},{}],41:[function(require,module,exports){ +},{}],42:[function(require,module,exports){ (function (global){ require('sinon') if (typeof window === 'undefined') { @@ -7934,7 +8000,7 @@ require('../') window.barometer.url = 'https://localhost:16006' }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) -},{"../":1,"sinon":13}],42:[function(require,module,exports){ +},{"../":1,"sinon":14}],43:[function(require,module,exports){ 'use strict' var assert = require('assert') var sinon = require('sinon') @@ -7979,7 +8045,7 @@ describe('Testing event', function () { }) }) -},{"../lib/event.js":2,"./_fakeDom.js":41,"assert":8,"sinon":13}],43:[function(require,module,exports){ +},{"../lib/event.js":2,"./_fakeDom.js":42,"assert":9,"sinon":14}],44:[function(require,module,exports){ /* global window */ 'use strict' var sinon = require('sinon') @@ -8023,7 +8089,7 @@ describe('Testing pageChange', function () { }) }) -},{"../lib/pageChange.js":3,"../lib/transport.js":5,"./_fakeDom.js":41,"assert":8,"sinon":13}],44:[function(require,module,exports){ +},{"../lib/pageChange.js":3,"../lib/transport.js":6,"./_fakeDom.js":42,"assert":9,"sinon":14}],45:[function(require,module,exports){ /* global window */ 'use strict' var assert = require('assert') @@ -8067,7 +8133,7 @@ describe('Testing pageLoadStats', function () { }) }) -},{"../lib/pageLoadStats.js":4,"../lib/transport.js":5,"./_fakeDom.js":41,"assert":8,"sinon":13}],45:[function(require,module,exports){ +},{"../lib/pageLoadStats.js":4,"../lib/transport.js":6,"./_fakeDom.js":42,"assert":9,"sinon":14}],46:[function(require,module,exports){ /* global window */ 'use strict' var assert = require('assert') @@ -8082,7 +8148,82 @@ describe('Testing barometer', function () { }) }) -},{"../lib/barometer.js":1,"./_fakeDom.js":41,"assert":8}],46:[function(require,module,exports){ +},{"../lib/barometer.js":1,"./_fakeDom.js":42,"assert":9}],47:[function(require,module,exports){ +/* global window */ +'use strict' +var sinon = require('sinon') +var assert = require('assert') +require('./_fakeDom.js') +var pageChange = require('../lib/pageChange.js') +var transport = require('../lib/transport.js') +var pageResources = require('../lib/pageResources.js') + +describe('Testing pageResources', function () { + before(function () { + sinon.stub(transport, 'gauge') + sinon.stub(pageChange, 'onPageChange', function (callback) { + setTimeout(callback, 500) + return callback() + }) + window.clock = sinon.useFakeTimers() + var getEntries = sinon.stub() + window.performance.getEntries = getEntries + var entries = [ + { + name: 'http://foo.com/bar.js?blarg', + entryType: 'type1', + stat1: 123 + }, + { + name: 'http://bar.com/foo.js', + entryType: 'type2', + stat2: 223 + }, + { + name: 'http://example.com/bar.js', + entryType: 'type3', + stat2: 100 + } + ] + var subsequentEntries = [ + { + name: 'http://foo.com/bar.js', + entryType: 'type1', + stat1: 723 + }, + { + name: 'http://bar.com/foo.js', + entryType: 'type2', + stat2: 823 + } + ] + getEntries.onFirstCall().returns(entries) + getEntries.onSecondCall().returns(entries.concat(subsequentEntries)) + window.barometer.resources = [ + { domain: 'foo.com', metrics: [ 'stat1' ] }, + { path: /foo\.js$/, metrics: [ 'stat2' ] } + ] + pageResources.initialise() + }) + after(function () { + transport.gauge.restore() + pageChange.onPageChange.restore() + window.performance.getEntries = null + window.clock.restore() + }) + + it('should measure resource timings', function () { + sinon.assert.calledWith(transport.gauge, 'resources.type1.foo_com.bar_js.stat1', -123) + sinon.assert.calledWith(transport.gauge, 'resources.type2.bar_com.foo_js.stat2', -223) + assert.equal(transport.gauge.callCount, 2) + window.clock.tick(600) + sinon.assert.calledWith(transport.gauge, 'resources.type1.foo_com.bar_js.stat1', -223) + sinon.assert.calledWith(transport.gauge, 'resources.type2.bar_com.foo_js.stat2', -323) + assert.equal(transport.gauge.callCount, 4) + }) +}) + +},{"../lib/pageChange.js":3,"../lib/pageResources.js":5,"../lib/transport.js":6,"./_fakeDom.js":42,"assert":9,"sinon":14}],48:[function(require,module,exports){ /* global window */ 'use strict' var assert = require('assert') @@ -8193,7 +8334,7 @@ describe('Testing transport', function () { }) }) -},{"../lib/transport.js":5,"./_fakeDom.js":41,"assert":8,"sinon":13}],47:[function(require,module,exports){ +},{"../lib/transport.js":6,"./_fakeDom.js":42,"assert":9,"sinon":14}],49:[function(require,module,exports){ /* global window */ 'use strict' var assert = require('assert') @@ -8221,7 +8362,7 @@ describe('Testing urlSanitiser', function () { }) }) -},{"../lib/urlSanitiser.js":6,"./_fakeDom.js":41,"assert":8}],48:[function(require,module,exports){ +},{"../lib/urlSanitiser.js":7,"./_fakeDom.js":42,"assert":9}],50:[function(require,module,exports){ /* global window */ 'use strict' var sinon = require('sinon') @@ -8255,4 +8396,4 @@ describe('Testing xhrStats', function () { }) }) -},{"../lib/transport.js":5,"../lib/xhrStats.js":7,"./_fakeDom.js":41,"sinon":13}]},{},[41,42,43,44,45,46,47,48]); +},{"../lib/transport.js":6,"../lib/xhrStats.js":8,"./_fakeDom.js":42,"sinon":14}]},{},[42,43,44,45,46,47,48,49,50]); diff --git a/dist/barometer.min.js b/dist/barometer.min.js index a49c7e9..e5e5b2c 100644 --- a/dist/barometer.min.js +++ b/dist/barometer.min.js @@ -1,2 +1,2 @@ /*! barometer v1.0.0 */ -_='!e« t(a˜n) n;r=n={¨:{id:a,Žed:!1}; e.call(r,r,r~r.Žed=!0,r}n={}; t.m=e~.c=n~.p=""~(0)}([e~,ne1)=Y$r2i6);n(7n(3n(8§=ž,a =r ,=r.,a=i$r3i1);§="XXXXX",eK={Ÿs:{ers:{}Š=0e(=||0,++,",e)a ~’=’||[],’.(tŸ",e~)};o=ž;tKoFŠ<100F‘oo=n,5e3)n˜0™ŠFi.§oF(‘oo=ž);t=;e();n=i.§;˜‡)‡(n,ƒ);else{u=new r.a;u.op%("POST",n,!eu.R#Header("C`t%t-Type","applici`/js`"u.s%d(ƒu.timeout=4e3}}€a=Œ;u=["UNSENT","OPENED","HEADERS_RECEIVED","LOADING","DONE"];r"xhr."+ei~,na={total:n}r  e)"_"™r[0]F0™e[r]F(a[r]=e[r]-t); aot,n,r=o(§u=i(@Times,off,total)s  u)t="timgœ“ (n,u[s]);t="¬s.(nt="size (n,(r#.¬Text¡.‰)ŒKe=new a;try{t={n=op%,i=s%d;op%=i,otry{s=;r(e,"readystec ",t[u[@]]=}r(e,"Ž%d",n o({…:i,§:o,@Times:t,off:s~otal:-s,r#:e})})}cc} n,s%dK i}co} e—,n„?„(t,n,!1):”F”("`"+t,n)—n=(e¡ ^Z\\/*;(t¡.m/\\?/)F(n+=t.slice(1)Z\\/*n},r,i$o4u7s2c=0,f=[];i.uKs (r,-a)i.sKs.(¢visits")aFi.u(c++;e=~=c,n=0,o=[9,9,9,9,9],g=!1,l=25,p=¢dynamic"dK‘va=,r=¢%gagem%t");t=125;s (p,-e-t)n=0;nnF(n=r!g˜t™c) d();o¥o.(r)i=0,u=0;u<5;u++)i+=o[u]; i<5Fn>25?d():void w,l)}l)};w()i.s(›?(o(,"popste",i.se˜et=¯;¯K i.s(t}}(›)):o(,"hashc ",i.sif.(e)€i‹{n=¦;e=toJSON()a  e)"¦"™aF0™eF(t=e-n); tr‹o(•ref,•ash);"pageŽ."+tQeZ*fKe~= .timg||{n=i(t)r  n)e=r(ri (e,n[r]);o=( .Wi`||{}).¤Count||0;e=r("¤s"i (e,o)"object"==…of F("complete"===docum%t.@?f():r(,"Ž",f)),r$i6o2u=0,s=;‚‹š(e);tFª(e~)š‹Y.r©s;˜tfor(–£/"a=n¥r=n.jo("/"i=0;i Date: Mon, 1 Aug 2016 10:38:27 +0000 Subject: [PATCH 4/4] Fixing merge issue --- dist/barometer-test.js | 80 +++++++++++++++++++++++++++++---------- lib/pageResources.js | 2 +- test/testPageResources.js | 4 +- 3 files changed, 63 insertions(+), 23 deletions(-) diff --git a/dist/barometer-test.js b/dist/barometer-test.js index 55489ef..fe86839 100644 --- a/dist/barometer-test.js +++ b/dist/barometer-test.js @@ -232,7 +232,7 @@ pageResources.initialise = function () { if (!window.performance || !window.performance.getEntries) return pageStart = new Date() - pageChange.onPageChange(function () { + pageChange.onPageChanged(function () { timingOffset = (new Date() - pageStart) var entries = window.performance.getEntries() for (; lastIndex < entries.length; lastIndex++) { @@ -849,7 +849,7 @@ function drainQueue() { if (draining) { return; } - var timeout = cachedSetTimeout(cleanUpNextTick); + var timeout = cachedSetTimeout.call(null, cleanUpNextTick); draining = true; var len = queue.length; @@ -866,7 +866,7 @@ function drainQueue() { } currentQueue = null; draining = false; - cachedClearTimeout(timeout); + cachedClearTimeout.call(null, timeout); } process.nextTick = function (fun) { @@ -878,7 +878,7 @@ process.nextTick = function (fun) { } queue.push(new Item(fun, args)); if (queue.length === 1 && !draining) { - cachedSetTimeout(drainQueue, 0); + cachedSetTimeout.call(null, drainQueue, 0); } }; @@ -1612,6 +1612,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; @@ -1628,6 +1646,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") { @@ -5011,7 +5031,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)) { @@ -5025,7 +5045,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; } } @@ -6103,7 +6123,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) { @@ -6437,12 +6457,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"; } @@ -6535,6 +6559,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; @@ -6598,6 +6631,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); }, @@ -8018,6 +8052,12 @@ window.barometer.url = 'https://localhost:16006' }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) },{"../":1,"sinon":14}],43:[function(require,module,exports){ 'use strict' + +var context = require.context('./', true, /test/) +context.keys().forEach(context) + +},{}],44:[function(require,module,exports){ +'use strict' var assert = require('assert') var sinon = require('sinon') require('./_fakeDom.js') @@ -8061,7 +8101,7 @@ describe('Testing event', function () { }) }) -},{"../lib/event.js":2,"./_fakeDom.js":42,"assert":9,"sinon":14}],44:[function(require,module,exports){ +},{"../lib/event.js":2,"./_fakeDom.js":42,"assert":9,"sinon":14}],45:[function(require,module,exports){ /* global window */ 'use strict' var sinon = require('sinon') @@ -8111,7 +8151,7 @@ describe('Testing pageChange', function () { }) }) -},{"../lib/pageChange.js":3,"../lib/transport.js":6,"./_fakeDom.js":42,"assert":9,"sinon":14}],45:[function(require,module,exports){ +},{"../lib/pageChange.js":3,"../lib/transport.js":6,"./_fakeDom.js":42,"assert":9,"sinon":14}],46:[function(require,module,exports){ /* global window */ 'use strict' var assert = require('assert') @@ -8155,7 +8195,7 @@ describe('Testing pageLoadStats', function () { }) }) -},{"../lib/pageLoadStats.js":4,"../lib/transport.js":6,"./_fakeDom.js":42,"assert":9,"sinon":14}],46:[function(require,module,exports){ +},{"../lib/pageLoadStats.js":4,"../lib/transport.js":6,"./_fakeDom.js":42,"assert":9,"sinon":14}],47:[function(require,module,exports){ /* global window */ 'use strict' var assert = require('assert') @@ -8170,7 +8210,7 @@ describe('Testing barometer', function () { }) }) -},{"../lib/barometer.js":1,"./_fakeDom.js":42,"assert":9}],47:[function(require,module,exports){ +},{"../lib/barometer.js":1,"./_fakeDom.js":42,"assert":9}],48:[function(require,module,exports){ /* global window */ 'use strict' var sinon = require('sinon') @@ -8183,7 +8223,7 @@ var pageResources = require('../lib/pageResources.js') describe('Testing pageResources', function () { before(function () { sinon.stub(transport, 'gauge') - sinon.stub(pageChange, 'onPageChange', function (callback) { + sinon.stub(pageChange, 'onPageChanged', function (callback) { setTimeout(callback, 500) return callback() }) @@ -8229,7 +8269,7 @@ describe('Testing pageResources', function () { }) after(function () { transport.gauge.restore() - pageChange.onPageChange.restore() + pageChange.onPageChanged.restore() window.performance.getEntries = null window.clock.restore() }) @@ -8245,7 +8285,7 @@ describe('Testing pageResources', function () { }) }) -},{"../lib/pageChange.js":3,"../lib/pageResources.js":5,"../lib/transport.js":6,"./_fakeDom.js":42,"assert":9,"sinon":14}],48:[function(require,module,exports){ +},{"../lib/pageChange.js":3,"../lib/pageResources.js":5,"../lib/transport.js":6,"./_fakeDom.js":42,"assert":9,"sinon":14}],49:[function(require,module,exports){ /* global window */ 'use strict' var assert = require('assert') @@ -8356,7 +8396,7 @@ describe('Testing transport', function () { }) }) -},{"../lib/transport.js":6,"./_fakeDom.js":42,"assert":9,"sinon":14}],49:[function(require,module,exports){ +},{"../lib/transport.js":6,"./_fakeDom.js":42,"assert":9,"sinon":14}],50:[function(require,module,exports){ /* global window */ 'use strict' var assert = require('assert') @@ -8384,7 +8424,7 @@ describe('Testing urlSanitiser', function () { }) }) -},{"../lib/urlSanitiser.js":7,"./_fakeDom.js":42,"assert":9}],50:[function(require,module,exports){ +},{"../lib/urlSanitiser.js":7,"./_fakeDom.js":42,"assert":9}],51:[function(require,module,exports){ /* global window */ 'use strict' var sinon = require('sinon') @@ -8418,4 +8458,4 @@ describe('Testing xhrStats', function () { }) }) -},{"../lib/transport.js":6,"../lib/xhrStats.js":8,"./_fakeDom.js":42,"sinon":14}]},{},[42,43,44,45,46,47,48,49,50]); +},{"../lib/transport.js":6,"../lib/xhrStats.js":8,"./_fakeDom.js":42,"sinon":14}]},{},[42,43,44,45,46,47,48,49,50,51]); diff --git a/lib/pageResources.js b/lib/pageResources.js index e67af79..ddbd4f2 100644 --- a/lib/pageResources.js +++ b/lib/pageResources.js @@ -52,7 +52,7 @@ pageResources.initialise = function () { if (!window.performance || !window.performance.getEntries) return pageStart = new Date() - pageChange.onPageChange(function () { + pageChange.onPageChanged(function () { timingOffset = (new Date() - pageStart) var entries = window.performance.getEntries() for (; lastIndex < entries.length; lastIndex++) { diff --git a/test/testPageResources.js b/test/testPageResources.js index 903f64e..0529874 100644 --- a/test/testPageResources.js +++ b/test/testPageResources.js @@ -10,7 +10,7 @@ var pageResources = require('../lib/pageResources.js') describe('Testing pageResources', function () { before(function () { sinon.stub(transport, 'gauge') - sinon.stub(pageChange, 'onPageChange', function (callback) { + sinon.stub(pageChange, 'onPageChanged', function (callback) { setTimeout(callback, 500) return callback() }) @@ -56,7 +56,7 @@ describe('Testing pageResources', function () { }) after(function () { transport.gauge.restore() - pageChange.onPageChange.restore() + pageChange.onPageChanged.restore() window.performance.getEntries = null window.clock.restore() })