forked from bluesmoon/boomerang
-
Notifications
You must be signed in to change notification settings - Fork 293
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Check that all beacons pass basic validation
- Loading branch information
1 parent
a2acc34
commit eacde8c
Showing
8 changed files
with
252 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
tests/page-templates/14-errors/28-send-plugin-disabled.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); |
33 changes: 33 additions & 0 deletions
33
tests/page-templates/14-errors/29-boomr-errors-plugin-disabled.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
51
tests/page-templates/14-errors/29-boomr-errors-plugin-disabled.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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\]$/); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"]); | ||
} | ||
|
||
} | ||
}); | ||
}); |