Skip to content

Commit

Permalink
Check that all beacons pass basic validation
Browse files Browse the repository at this point in the history
  • Loading branch information
querymetrics authored and nicjansma committed Apr 4, 2018
1 parent a2acc34 commit eacde8c
Show file tree
Hide file tree
Showing 8 changed files with 252 additions and 8 deletions.
9 changes: 7 additions & 2 deletions tests/boomerang-test-framework.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@

var beaconsSeen = 0;

var doNotTestErrorsParam = false;

// test framework
var assert;

Expand Down Expand Up @@ -121,7 +123,8 @@
beacon_url: t.BEACON_URL,
ResourceTiming: {
enabled: false
}
},
doNotTestErrorsParam: false
};

t.flattenTestTitles = function(test) {
Expand Down Expand Up @@ -192,6 +195,8 @@
});
}

t.doNotTestErrorsParam = config.doNotTestErrorsParam;

if (window.BOOMR_LOGN_always !== true) {
// initialize boomerang if LOGN is disabled
BOOMR.addVar("h.cr", "test");
Expand Down Expand Up @@ -354,7 +359,7 @@

assert.isObject(tf.lastBeacon(), "ensure the data was sent to 'onbeacon'");

assert.isString(tf.lastBeacon().v, "ensure the beacon has basic properties");
assert.equal(tf.lastBeacon().v, BOOMR.version, "ensure the beacon has the boomerang version");

done();
};
Expand Down
1 change: 1 addition & 0 deletions tests/page-template-snippets/header.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,4 @@
<script>
mocha.setup("bdd");
</script>
<script src="../../test-templates/common.js" type="text/javascript"></script>
17 changes: 17 additions & 0 deletions tests/page-templates/14-errors/28-send-plugin-disabled.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<%= header %>
<%= boomerangScriptMin %>
<script src="28-send-plugin-disabled.js" type="text/javascript"></script>
<script>
function errorFunction() {
BOOMR.plugins.Errors.send("ERROR!");
}
errorFunction();

BOOMR_test.init({
testAfterOnBeacon: true,
Errors: {
enabled: false
}
});
</script>
<%= footer %>
16 changes: 16 additions & 0 deletions tests/page-templates/14-errors/28-send-plugin-disabled.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*eslint-env mocha*/
/*global BOOMR_test,assert*/

describe("e2e/14-errors/28-send-plugin-disabled", function() {
var tf = BOOMR.plugins.TestFramework;
var t = BOOMR_test;

it("Should have sent a single beacon validation", function(done) {
t.validateBeaconWasSent(done);
});

it("Should not have put the err on the beacon", function() {
var b = tf.lastBeacon();
assert.isUndefined(b.err);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<%= header %>
<%= boomerangScriptMin %>
<script src="29-boomr-errors-plugin-disabled.js" type="text/javascript"></script>
<script>
BOOMR_test.init({
testAfterOnBeacon: true,
doNotTestErrorsParam: true,
Errors: {
enabled: false
}
});

// Send a Boomerang error with an exception and a source
function errorFunction() {
try {
a.bad = 1;
}
catch (e) {
BOOMR.addError(e, "BOOMRtest");
}
}
errorFunction();

// Send a textual error
BOOMR.addError("Fault 2", "BOOMRtest2");

// Send a textual error with some extra string
BOOMR.addError("Fault 3", "BOOMRtest3", "Extra stuff");

// Send a textual error with an extra object
BOOMR.addError("Fault 4", "BOOMRtest4", {a: true, b: "EXTRASTRING"});
</script>
<%= footer %>
51 changes: 51 additions & 0 deletions tests/page-templates/14-errors/29-boomr-errors-plugin-disabled.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*eslint-env mocha*/
/*global BOOMR_test,assert*/

describe("e2e/14-errors/29-boomr-errors-plugin-disabled", function() {
var tf = BOOMR.plugins.TestFramework;
var t = BOOMR_test;

it("Should have sent a single beacon", function(done) {
t.validateBeaconWasSent(done);
});

it("Should not have put the err on the beacon", function() {
var b = tf.lastBeacon();
assert.isUndefined(b.err);
});

it("Should have put the errors on the beacon", function() {
var b = tf.lastBeacon();
assert.isDefined(b.errors);
});

it("Should have had 4 errors", function() {
var b = tf.lastBeacon();
assert.equal(b.errors.split("\n").length, 4);
});

// the expected message in this test is browser specific and might need tweaking
it("Should have error #1 match expected", function() {
var b = tf.lastBeacon();
var err = b.errors.split("\n")[0];
assert.match(err, /^\[BOOMRtest:\d{13}\] ReferenceError: (?:a is not defined|Can't find variable: a)$/);
});

it("Should have error #2 match expected", function() {
var b = tf.lastBeacon();
var err = b.errors.split("\n")[1];
assert.match(err, /^\[BOOMRtest2:\d{13}\] Fault 2$/);
});

it("Should have error #3 match expected", function() {
var b = tf.lastBeacon();
var err = b.errors.split("\n")[2];
assert.match(err, /^\[BOOMRtest3:\d{13}\] Fault 3:: Extra stuff$/);
});

it("Should have error #4 match expected", function() {
var b = tf.lastBeacon();
var err = b.errors.split("\n")[3];
assert.match(err, /^\[BOOMRtest4:\d{13}\] Fault 4:: \[object Object\]$/);
});
});
12 changes: 6 additions & 6 deletions tests/page-templates/17-memory/00-dom-counts.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@ describe("e2e/17-memory/00-dom-counts", function() {
assert.equal(tf.lastBeacon()["dom.img.uniq"], 1);
});

it("Should have found 10 scripts", function() {
assert.equal(tf.lastBeacon()["dom.script"], 10);
it("Should have found 11 scripts", function() {
assert.equal(tf.lastBeacon()["dom.script"], 11);
});

it("Should have found 6 external scripts", function() {
assert.equal(tf.lastBeacon()["dom.script.ext"], 6);
it("Should have found 7 external scripts", function() {
assert.equal(tf.lastBeacon()["dom.script.ext"], 7);
});

it("Should have found 5 unique external scripts", function() {
assert.equal(tf.lastBeacon()["dom.script.uniq"], 5);
it("Should have found 6 unique external scripts", function() {
assert.equal(tf.lastBeacon()["dom.script.uniq"], 6);
});

it("Should have found 3 iframes", function() {
Expand Down
121 changes: 121 additions & 0 deletions tests/test-templates/common.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
/*eslint-env mocha*/
/*global BOOMR,BOOMR_test,assert*/

describe("common", function() {
var t = BOOMR_test;
var tf = BOOMR.plugins.TestFramework;

function testSpaHardBeacon(b, prefix) {
assert.isUndefined(b.api, prefix + "does not have the api param");
}

function testSpaSoftBeacon(b, prefix) {
assert.isUndefined(b.api, prefix + "does not have the api param");
}

it("Should have sent beacons that pass basic validation", function() {
for (var i = 0; i < tf.beacons.length; i++) {
var b = tf.beacons[i], tm, now = BOOMR.now();
var prefix = "ensure beacon " + (i + 1) + " ";

assert.equal(b.v, BOOMR.version, prefix + "has the boomerang version");

assert.isDefined(b["h.d"], prefix + "has the domain (h.d) param");

assert.isDefined(b["h.t"], prefix + "has the time (h.t) param");
tm = parseInt(b["h.t"], 10);
assert.isTrue(tm > now - (60 * 1000), prefix + "time is greater than a minute ago");
assert.isTrue(tm < now, prefix + "time is less than now");

if (window.BOOMR_LOGN_always !== true) {
assert.equal(b["h.cr"], "abc", prefix + "has the correct crumb (h.cr)");
}
else {
assert.isDefined(b["h.cr"], prefix + "has the crumb (h.cr)");
}

assert.lengthOf(b.pid, 8, prefix + "has a page ID (pid) with a length equal to 8");

if (!t.doNotTestErrorsParam) {
assert.isUndefined(b.errors, prefix + "does not have the errors param");
}

if (b["rt.start"] === "navigation") {
// page load beacon
}
else if (b["rt.start"] === "manual") {
if (b["http.initiator"] === "spa_hard") {
// spa hard beacon
testSpaHardBeacon(b, prefix);
}
else if (b["http.initiator"] === "spa") {
// spa soft beacon
testSpaSoftBeacon(b, prefix);
}
else if (b["http.initiator"] === "xhr") {
// xhr beacon
assert.isUndefined(b.api, prefix + "does not have the api param");
assert.isDefined(b.pgu, prefix + "has the pgu param");
}
else if (b["http.initiator"] === "api_custom_metric") {
// send metric beacon
assert.equal(b.api, "1", prefix + "has the api param value equal to 1");
assert.equal(b["api.v"], "2", prefix + "has api version equal to 2");
assert.equal(b["api.l"], "boomr", prefix + "has the api source equal to boomr");
}
else if (b["http.initiator"] === "api_custom_timer") {
// send timer beacon
assert.equal(b.api, "1", prefix + "has the api param value equal to 1");
assert.equal(b["api.v"], "2", prefix + "has api version equal to 2");
assert.equal(b["api.l"], "boomr", prefix + "has the api source equal to boomr");
}
else if (b["http.initiator"] === "error") {
// error beacon
assert.equal(b.api, "1", prefix + "has the api param value equal to 1");
}
else if (typeof b["http.initiator"] === "undefined") {
// requestStart and/or responseEnd initiated beacon
// TODO
}
else {
// invalid
assert.fail(prefix + "with a rt.start=manual has a valid http.initiator, was:" + b["http.initiator"]);
}
}
else if (b["rt.start"] === "none") {
if (b["http.initiator"] === "spa_hard") {
// spa hard beacon
testSpaHardBeacon(b, prefix);
}
else if (b["http.initiator"] === "spa") {
// spa soft beacon
testSpaSoftBeacon(b, prefix);
}
else {
// TODO
}
}
else if (b["rt.start"] === "cookie") {
// TODO
}
else if (typeof b["rt.start"] === "undefined") {
if (b["http.initiator"] === "error") {
// error beacon
assert.equal(b.api, "1", prefix + "has the api param value equal to 1");
}
else if (b["rt.quit"] !== "undefined") {
// unload beacon
}
else {
// invalid
assert.fail(prefix + "has a valid rt.start, was:" + b["rt.start"]);
}
}
else {
// invalid
assert.fail(prefix + "has a valid rt.start, was: " + b["rt.start"]);
}

}
});
});

0 comments on commit eacde8c

Please sign in to comment.