Skip to content

Commit

Permalink
Misc changes for Boomerang
Browse files Browse the repository at this point in the history
  • Loading branch information
andreas-marschke authored and nicjansma committed Apr 4, 2018
1 parent f253d1b commit a2acc34
Show file tree
Hide file tree
Showing 38 changed files with 305 additions and 88 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ tests/page-templates/12-react/support/app.js
*#*
*~
.idea/
*.DS_Store
53 changes: 48 additions & 5 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,28 @@ var fse = require("fs-extra");
var stripJsonComments = require("strip-json-comments");
var grunt = require("grunt");


//
// Constants
//

//
// Domains for test purposes
//
var DEFAULT_TEST_MAIN_DOMAIN = "boomerang-test.local";
var DEFAULT_TEST_SECONDARY_DOMAIN = "boomerang-test2.local";

var boomerangE2ETestDomain = grunt.option("main-domain") || DEFAULT_TEST_MAIN_DOMAIN;
var boomerangE2ESecondDomain = grunt.option("secondary-domain") || DEFAULT_TEST_SECONDARY_DOMAIN;

var BUILD_PATH = "build";
var TEST_BUILD_PATH = path.join("tests", "build");
var TEST_RESULTS_PATH = path.join("tests", "results");
var TEST_DEBUG_PORT = 4002;
var TEST_URL_BASE = grunt.option("test-url") || "http://localhost:4002";
var TEST_URL_BASE = grunt.option("test-url") || "http://" + boomerangE2ETestDomain + ":4002";

var SELENIUM_ADDRESS = "http://" + boomerangE2ETestDomain + ":4444/wd/hub";
var E2E_BASE_URL = "http://" + boomerangE2ETestDomain + ":4002/";

var DEFAULT_UGLIFY_BOOMERANGJS_OPTIONS = {
preserveComments: false,
Expand Down Expand Up @@ -119,7 +133,7 @@ module.exports = function() {
// Build configuration
//
var buildConfig = {
server: grunt.option("server") || "localhost"
server: grunt.option("server") || DEFAULT_TEST_MAIN_DOMAIN || "localhost"
};

var bannerFilePathRelative = "./lib/banner.txt";
Expand Down Expand Up @@ -548,13 +562,42 @@ module.exports = function() {
keepAlive: false
},
phantomjs: {
configFile: "tests/protractor.config.phantom.js"
options: {
configFile: "tests/protractor.config.phantom.js",
args: {
seleniumAddress: SELENIUM_ADDRESS,
specs: ["tests/e2e/e2e.js"],
baseUrl: E2E_BASE_URL,
capabilities: {
"browserName": "phantomjs",
"phantomjs.binary.path": require("phantomjs").path
}
}
}
},
chrome: {
configFile: "tests/protractor.config.chrome.js"
options: {
configFile: "tests/protractor.config.chrome.js",
args: {
seleniumAddress: SELENIUM_ADDRESS,
specs: ["e2e/*.js"],
baseUrl: E2E_BASE_URL
}
}
},
debug: {
configFile: "tests/protractor.config.debug.js"
options: {
configFile: "tests/protractor.config.debug.js",
args: {
seleniumAddress: SELENIUM_ADDRESS,
specs: ["e2e/e2e-debug.js"],
baseUrl: E2E_BASE_URL,
capabilities: {
"browserName": "phantomjs",
"phantomjs.binary.path": require("phantomjs").path
}
}
}
}
},
protractor_webdriver: {
Expand Down
2 changes: 1 addition & 1 deletion boomerang.js
Original file line number Diff line number Diff line change
Expand Up @@ -2052,7 +2052,7 @@ BOOMR_check_doc_domain();
var make_logger;

if (typeof console === "object" && console.log !== undefined) {
boomr.log = function(m, l, s) { console.log(BOOMR.now() + ": " + s + ": [" + l + "] " + m); };
boomr.log = function(m, l, s) { console.log("(" + BOOMR.now() + ") " + "{" + BOOMR.pageId + "}" + ": " + s + ": [" + l + "] " + m); };
}

make_logger = function(l) {
Expand Down
6 changes: 5 additions & 1 deletion plugins/rt.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@

// These timers are added directly as beacon variables
basic_timers: { t_done: 1, t_resp: 1, t_page: 1},

crossdomain_sending: false,
// Vars that were added to the beacon that we can remove after beaconing
addedVars: [],

Expand Down Expand Up @@ -730,6 +730,10 @@
w = BOOMR.window;
}

if (config && config.CrossDomain && config.CrossDomain.sending) {
impl.crossdomain_sending = true;
}

// protect against undefined window/document
if (!w || !w.document) {
return;
Expand Down
28 changes: 25 additions & 3 deletions tests/builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,15 @@ module.exports = function() {
var e2eDir = path.join(testsDir, "e2e");
var e2eJsonPath = path.join(e2eDir, "e2e.json");

//
// Domains for test purposes
//
var DEFAULT_TEST_MAIN_DOMAIN = "boomerang-test.local";
var DEFAULT_TEST_SECONDARY_DOMAIN = "boomerang-test2.local";

var boomerangE2ETestDomain = grunt.option("main-domain") || DEFAULT_TEST_MAIN_DOMAIN;
var boomerangE2ESecondDomain = grunt.option("secondary-domain") || DEFAULT_TEST_SECONDARY_DOMAIN;

//make grunt know this task is async.
var done = this.async();

Expand All @@ -86,7 +95,10 @@ module.exports = function() {
});
},
function(opts, cb) {
opts.vars = {};
opts.vars = {
mainServer: boomerangE2ETestDomain,
secondaryServer: boomerangE2ESecondDomain
};

// Set all template vars to their file name
opts.snippetFiles.forEach(function(file) {
Expand Down Expand Up @@ -223,9 +235,19 @@ module.exports = function() {
// write root index
grunt.log.ok("index.html");
grunt.file.write(rootIndexFile, rootIndexHtml);

var testConfiguration = {
server: {
main: boomerangE2ETestDomain,
second: boomerangE2ESecondDomain
},
ports: {
main: 4002,
second: 4003
},
tests: testDefinitions
};
// test definitions
grunt.file.write(e2eJsonPath, JSON.stringify(testDefinitions, null, 2));
grunt.file.write(e2eJsonPath, JSON.stringify(testConfiguration, null, 2));

cb(err, opts);
});
Expand Down
15 changes: 5 additions & 10 deletions tests/e2e/e2e-debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,9 @@ var assert = chai.assert;
var path = require("path");

var testsFile = path.join(__dirname, "e2e-debug.json");
var tests = require(testsFile).tests;
var servers = require(testsFile).server;

var tests = [];

if (fs.existsSync(testsFile)) {
tests = require(testsFile);
}

var i;

//
// Functions
Expand All @@ -28,12 +23,12 @@ function run(testPath, file) {
it("Should pass " + testPath + "/" + fileName, function(done) {
var logCount = 0;

browser.driver.get("http://localhost:4002/pages/" + testPath + "/" + fileName);
browser.driver.get("http://" + servers.main + ":" + ports.main + "/pages/" + path + "/" + fileName);

setInterval(function() {
browser.manage().logs().get("browser").then(function(browserLog) {
if (browserLog.length > logCount) {
for (i = logCount; i < browserLog.length; i++) {
for (var i = logCount; i < browserLog.length; i++) {
var log = browserLog[i];
console.log("[" + new Date(log.timestamp).toLocaleTimeString() + "] " + log.message);
}
Expand Down Expand Up @@ -67,7 +62,7 @@ function run(testPath, file) {
//
// Run the tests in e2e-debug.json
//
for (i = 0; i < tests.length; i++) {
for (var i = 0; i < tests.length; i++) {
var data = tests[i];

console.log("Running " + data.path + "/" + data.file);
Expand Down
14 changes: 10 additions & 4 deletions tests/e2e/e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
var chai = require("chai");
var assert = chai.assert;

var tests = require("./e2e.json");
var tests = require("./e2e.json").tests;
var servers = require("./e2e.json").server;
var ports = require("./e2e.json").ports;
var disabledTests = require("./e2e.disabled.json");

//
Expand All @@ -16,16 +18,20 @@ var disabledTests = require("./e2e.disabled.json");
function run(path, file) {
describe(path, function() {
var fileName = file + ".html";

it("Should pass " + path + "/" + fileName, function(done) {
browser.driver.get("http://localhost:4002/pages/" + path + "/" + fileName);

browser.driver.get("http://" + servers.main + ":" + ports.main + "/pages/" + path + "/" + fileName);

browser.driver.wait(function() {
return browser.driver.isElementPresent(by.css("#BOOMR_test_complete"));
});

browser.driver.executeScript("return BOOMR_test.isComplete()").then(function(complete){
browser.driver.executeScript("return BOOMR_test.isComplete()").then(function(complete) {

assert.equal(complete, true, "BOOMR_test.isComplete()");
browser.driver.executeScript("return BOOMR_test.getTestFailureMessages()").then(function(testFailures){

browser.driver.executeScript("return BOOMR_test.getTestFailureMessages()").then(function(testFailures) {
if (testFailures.length > 0) {
throw new Error(testFailures);
}
Expand Down
17 changes: 17 additions & 0 deletions tests/page-template-snippets/header.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,23 @@
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="../../vendor/mocha/mocha.css" />
<script type="text/javascript">
// Clear localstorage
if (typeof window.localStorage === "object" && typeof window.localStorage.clear === "function") {
window.localStorage.clear();
}
// Set RT Cookie to empty, preventing navigation related issues with session tests
document.cookie = "RT=\"\";domain=.<%= mainServer %>;path=/";
// Prevent Boomerang from setting a cookie on unload so as to prevent cookies to show up when we load the next E2E test
window.addEventListener("beforeunload", function (e) {
if (BOOMR) {
BOOMR.disable();
}
e.preventDefault();
});
</script>
<script src="../../vendor/mocha/mocha.js"></script>
<script src="../../vendor/assertive-chai/dist/assertive-chai.js"></script>
<script src="../../vendor/lodash/lodash.js"></script>
Expand Down
1 change: 1 addition & 0 deletions tests/page-templates/00-basic/01-onunload.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<iframe id="boomer_test_frame" src="support/generic.html" style="display: none"></iframe>
<script>
BOOMR_test.init({
site_domain: "<%= mainServer %>",
ResourceTiming: {
enabled: false
},
Expand Down
2 changes: 1 addition & 1 deletion tests/page-templates/00-basic/01-onunload.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ describe("e2e/00-basic/01-onunload", function() {

var testFrame = document.getElementById("boomer_test_frame");
testFrame.contentWindow.BOOMR.subscribe("onbeacon", unloadBeaconHandler, null, this);
testFrame.src = "support/generic.html?2";
testFrame.src = "about:blank";
});

});
28 changes: 28 additions & 0 deletions tests/page-templates/00-basic/11-local-domains.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<%= header %>
<%= boomerangSnippet %>
<script type="text/javascript">
window.mainServer = "<%= mainServer %>";
window.secondaryServer = "<%= secondaryServer %>";

window.mainPort = (parseInt(window.location.port) || 4002);
window.secondaryPort = (parseInt(window.location.port) || 4002) + 1;

</script>
<script src="11-local-domains.js" type="text/javascript"></script>

<pre> Why is this test here?
======================

Some tests require us to have a proper domain and port assigned and requesting resources from those domains+ports
as this is the only way we can ensure a cookie is created and session details can be validated.

In this set of tests we ensure that both the port and domain are setup as expected in our environment.
</pre>

<script type="text/javascript">
BOOMR_test.init({
testAfterOnBeacon: true
});
</script>

<%= footer %>
44 changes: 44 additions & 0 deletions tests/page-templates/00-basic/11-local-domains.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*eslint-env mocha*/
/*global BOOMR,BOOMR_test,describe,it*/

/*
Why is this test here?
======================
Some tests require us to have a proper domain and port assigned and requesting resources from those domains+ports
as this is the only way we can ensure a cookie is created and session details can be validated.
In this set of tests we ensure that both the port and domain are setup as expected in our environment.
*/

describe("e2e/00-basic/11-local-domains", function() {
var tf = BOOMR.plugins.TestFramework;
var t = BOOMR_test;

it("Should have successfully requested a resource from it's main server domain (--main-domain in grunt)", function(done){
var xhr1 = new XMLHttpRequest();

xhr1.open("GET", "http://" + window.mainServer + ":" + (window.mainPort) + "/pages/00-basic/support/generic.html");
xhr1.send(null);

xhr1.addEventListener("load", function() {
if (xhr1.readyState === XMLHttpRequest.DONE) {
done();
}
});
});

it("Should have successfully requested a resource from it's secondary server domain (--secondary-domain in grunt)", function(done){
var xhr2 = new XMLHttpRequest();

xhr2.open("GET", "http://" + window.secondaryServer + ":" + (window.secondaryPort) + "/pages/00-basic/support/generic.html");
xhr2.send(null);

xhr2.addEventListener("load", function() {
if (xhr2.readyState === XMLHttpRequest.DONE) {
done();
}
});
});
});

16 changes: 12 additions & 4 deletions tests/page-templates/00-basic/support/generic-autorun-false.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,23 @@
<title>Generic Page w/ Boomerang</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script type="text/javascript">
document.cookie = "RT=\"\";domain=.boomerang-test.local;path=/";
</script>
<script src="../../../vendor/mocha/mocha.js"></script>
<script src="../../../vendor/assertive-chai/dist/assertive-chai.js"></script>
<script src="../../../vendor/lodash/lodash.js"></script>

<script src="../../../build/boomerang-latest-debug.js" type="text/javascript"></script>
<script src="../../../boomerang-test-framework.js" type="text/javascript"></script>
</head>
<body>
<div id="output"></div>
<script>
window.BOOMR_config = { autorun: false };
BOOMR.init();
document.getElementById("output").innerHTML = "Generic Page w/ Boomerang Autorun: False";
document.getElementById("output").innerHTML += " " + document.location;
window.BOOMR_config = { autorun: false };
BOOMR_test.init({ site_domain: "boomerang-test.local" });
document.getElementById("output").innerHTML = "Generic Page w/ Boomerang Autorun: False";
document.getElementById("output").innerHTML += " " + document.location;
</script>
</body>
</html>
Loading

0 comments on commit a2acc34

Please sign in to comment.