Skip to content

Commit

Permalink
Fix custom timers for SPA navigations
Browse files Browse the repository at this point in the history
  • Loading branch information
querymetrics authored and nicjansma committed Apr 4, 2018
1 parent 721ceb3 commit f35f912
Show file tree
Hide file tree
Showing 33 changed files with 1,156 additions and 115 deletions.
10 changes: 6 additions & 4 deletions tests/boomerang-test-framework.js
Original file line number Diff line number Diff line change
Expand Up @@ -370,10 +370,12 @@
t.parseTimers = function(timers) {
var timerValues = {};

var timersSplit = timers.split(",");
for (var i = 0; i < timersSplit.length; i++) {
var timerSplit = timersSplit[i].split("|");
timerValues[timerSplit[0]] = timerSplit[1];
if (timers) {
var timersSplit = timers.split(",");
for (var i = 0; i < timersSplit.length; i++) {
var timerSplit = timersSplit[i].split("|");
timerValues[timerSplit[0]] = parseInt(timerSplit[1], 10);
}
}

return timerValues;
Expand Down
21 changes: 17 additions & 4 deletions tests/page-templates/05-angular/support/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ var app = angular.module("app", modules)

$scope.rnd = Math.random();

$scope.carttotal = 444.44;

window.custom_timer_1 = 11;
window.custom_timer_2 = function() {
return 22;
Expand All @@ -54,6 +56,19 @@ var app = angular.module("app", modules)

var wid = parseInt($routeParams.widgetId);

$scope.carttotal = 11.11 * wid;

// these overwrite what was in the HTML
window.custom_metric_1 = wid;
window.custom_metric_2 = function() {
return 10 * wid;
};

window.custom_timer_1 = wid;
window.custom_timer_2 = function() {
return 10 * wid;
};

for (var i = 0; i < widgets.length; i++) {
if (widgets[i].id === wid) {
$scope.widget = widgets[i];
Expand Down Expand Up @@ -137,10 +152,8 @@ app.run(["$rootScope", "$location", "$timeout", function($rootScope, $location,
}
}


if (typeof window.angular_nav_routes !== "undefined" &&
Object.prototype.toString.call(window.angular_nav_routes) === "[object Array]") {
BOOMR.subscribe("beacon", function(beacon) {
if (typeof window.angular_nav_routes !== "undefined" && BOOMR.utils.isArray(window.angular_nav_routes)) {
BOOMR.subscribe("onbeacon", function(beacon) {
// only continue for SPA beacons
if (!BOOMR.utils.inArray(beacon["http.initiator"], BOOMR.constants.BEACON_TYPE_SPAS)) {
return;
Expand Down
2 changes: 1 addition & 1 deletion tests/page-templates/05-angular/support/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<h1>Home</h1>
<img ng-if="hide_imgs != true" ng-repeat="delay in imgs" ng-src="/delay?delay={{delay}}&amp;file=pages/05-angular/support/img.jpg&amp;id=home&amp;rnd={{rnd}}" style="width: 300px; height: auto;"/>
<div class="cart-container" style="display: none">
<div id="cart-total">$444.44</div>
<div id="cart-total">${{carttotal}}</div>
</div>
<ul>
<li ng-repeat="widget in widgets"><a ng-href="widgets/{{widget.id}}">{{widget.name}}</a></li>
Expand Down
3 changes: 3 additions & 0 deletions tests/page-templates/05-angular/support/widget.html
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
<h1>{{widget.name}}</h1>
<img ng-src="/delay?delay={{widget.id}}000&amp;file=pages/05-angular/support/img.jpg&amp;id={{widget.id}}&amp;rnd={{rnd}}" style="width: 300px; height: auto;" />
<div class="cart-container" style="display: none">
<div id="cart-total">${{carttotal}}</div>
</div>
243 changes: 243 additions & 0 deletions tests/page-templates/08-ember/26-page-params-spa-nav.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,243 @@
<%= header %>
<%= boomerangScript %>
<base href="/pages/08-ember/26-page-params-spa-nav.html" />

<script src="../../vendor/jquery/dist/jquery.min.js"></script>
<script src="../../vendor/ember/ember.prod.js"></script>
<script src="../../vendor/handlebars/handlebars.min.js"></script>
<script src="../../vendor/ember/ember-template-compiler.js"></script>
<script>
// Force navigation to TYPE_NAVIGATE
if (window.performance) {
window.performance.__defineGetter__("navigation", function() {
return {type: 0, redirectCount: 0};
});
}

window.ember_nav_routes = ["/widgets/1", ""];
window.html5_mode = true;
window.imgs = [3000];
</script>
<script src="support/app.js"></script>

<!-- Handlebars templates for our application. -->
<script type="text/x-handlebars">
<div class="container">
{{outlet}}
</div>
</script>

<script src="/test-templates/spa/26-page-params-spa-nav.js" type="text/javascript"></script>
<script src="26-page-params-spa-nav.js" type="text/javascript"></script>
<script>
var img, xhr, beaconCount = 0;
BOOMR.subscribe("onbeacon", function(vars) {
beaconCount++;
if (beaconCount === 3) {
setTimeout(function() {
xhr = new XMLHttpRequest();
xhr.open("GET", "/delay?delay=100&file=/pages/05-angular/support/widgets.json");
xhr.addEventListener("load", function() {
img = document.createElement("img");
img.src = "/delay?delay=1000&id=xhr&file=/pages/05-angular/support/img.jpg";
document.body.appendChild(img);
});
xhr.send(null);
}, 100);
}
});

// these will be overwritten by the app
custom_metric_1 = 111;
custom_metric_2 = function() {
return 222;
};

BOOMR_test.init({
testAfterOnBeacon: 4,
Ember: {
enabled: true
},
PageParams: {
pageGroups: [
{
type: "Regexp",
parameter1: ".*/widgets/1",
parameter2: "widget1"
},
{
type: "Regexp",
parameter1: ".*/26-page-params-spa-nav.html",
parameter2: "home"
}
],
customMetrics: [
{
varName: "custom_metric_1",
label: "cmet1",
type: "JavaScriptVar"
},
{
varName: "custom_metric_2",
label: "cmet2",
type: "JavaScriptVar"
},
{
varName: "missing_metric",
label: "cmet3",
type: "JavaScriptVar"
},
{
parameter1: "",
parameter2: "//div[@id='cart-total']",
label: "cmet4",
type: "URLPatternType"
},
{
parameter1: "*",
parameter2: "",
label: "cmet5",
type: "URLPatternType"
}
],
customTimers: [
{
name: "Timer NavigationTiming",
index: 0,
type: "NavigationTiming",
label: "custom0",
"start": "navigationStart",
"end": "responseEnd"
},
{
name: "Timer JavaScript Variable",
index: 1,
type: "Custom",
label: "custom1",
parameter1: "custom_timer_1"
},
{
name: "Timer JavaScript Function",
index: 2,
type: "Custom",
label: "custom2",
parameter1: "custom_timer_2"
},
{
name: "Timer UserTiming",
index: 3,
type: "UserTiming",
label: "custom3",
parameter1: "",
parameter2: "mark_usertiming"
},
{
name: "Missing Timer JavaScript Variable",
index: 4,
type: "Custom",
label: "custom4",
parameter1: "custom_timer_missing"
},
{
name: "Missing Timer UserTiming",
index: 5,
type: "UserTiming",
label: "custom5",
parameter1: "",
parameter2: "missing_mark_usertiming"
},
{
name: "ResourceGroup Element after spa_hard",
index: 6,
label: "custom6",
type: "ResourceGroup",
value: {
"*/26-page-params-spa-nav.html*": {
on: ["spa_hard"],
resources: [{
type: "resource",
value: "*id=home*"
}]
}
}
},
{
name: "ResourceGroup on spa",
index: 7,
label: "custom7",
type: "ResourceGroup",
value: {
"*/26-page-params-spa-nav.html*": {
on: ["spa"],
resources: [{
type: "resource",
value: "*id=1*"
}]
}
}
},
{
name: "Resource Group nav-start defined as start and ResTiming",
index: 8,
label: "custom8",
type: "ResourceGroup",
value: {
"*/26-page-params-spa-nav.html*": {
on: ["spa"],
resources: [{
type: "resource",
value: "*id=1*",
start: "navigationStart"
}]
}
}
},
{
name: "ResourceGroup on xhr",
index: 9,
label: "custom9",
type: "ResourceGroup",
value: {
"*/26-page-params-spa-nav.html*": {
on: ["xhr"],
resources: [{
type: "resource",
value: "*id=xhr*"
}]
}
}
},
{
name: "Timer ResourceTiming",
index: 10,
type: "ResourceTiming",
label: "custom10",
start: "requestStart",
end: "responseEnd",
url: "*id=home*"
},
{
name: "Timer ResourceTiming nav start",
index: 11,
type: "ResourceTiming",
label: "custom11",
start: "navigationStart",
end: "responseEnd",
url: "*id=home*"
},
{
name: "Missing Timer ResourceTiming",
index: 12,
type: "ResourceTiming",
label: "custom12",
start: "requestStart",
end: "responseEnd",
url: "*id=doesnotexist*"
}
]
},
instrument_xhr: true,
autorun: false
});
</script>
<%= footer %>
6 changes: 6 additions & 0 deletions tests/page-templates/08-ember/26-page-params-spa-nav.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/*eslint-env mocha*/
/*global BOOMR_test*/

describe("e2e/08-ember/26-page-params-spa-nav", function() {
BOOMR_test.templates.SPA["26-page-params-spa-nav"]();
});
Loading

0 comments on commit f35f912

Please sign in to comment.