From 24f37ea414801a345d40c761b1459213b55994a9 Mon Sep 17 00:00:00 2001 From: Caleb James DeLisle Date: Wed, 31 May 2017 19:40:17 +0200 Subject: [PATCH] Delicious testing --- TestSelenium.js | 41 +++++++++++++++++++++++++++-------------- www/auth/main.js | 8 +++++++- www/common/test.js | 30 ++++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+), 15 deletions(-) create mode 100644 www/common/test.js diff --git a/TestSelenium.js b/TestSelenium.js index 9623577b5..dcbeacaef 100644 --- a/TestSelenium.js +++ b/TestSelenium.js @@ -1,5 +1,6 @@ /* global process */ var WebDriver = require("selenium-webdriver"); +var nThen = require('nthen'); if (process.env.TRAVIS_PULL_REQUEST && process.env.TRAVIS_PULL_REQUEST !== 'false') { // We can't do saucelabs on pull requests so don't fail. @@ -21,18 +22,30 @@ if (process.env.SAUCE_USERNAME !== undefined) { driver = new WebDriver.Builder().withCapabilities({ browserName: "chrome" }).build(); } -driver.get('http://localhost:3000/assert/'); -var report = driver.wait(WebDriver.until.elementLocated(WebDriver.By.className("report")), 5000); -report.getAttribute("class").then(function (cls) { - report.getText().then(function (text) { - console.log("\n-----\n" + text + "\n-----"); - driver.quit(); - if (!cls) { - throw new Error("cls is null"); - } else if (cls.indexOf("failure") !== -1) { - throw new Error("cls contains the word failure"); - } else if (cls.indexOf("success") === -1) { - throw new Error("cls does not contain the word success"); - } - }); +var nt = nThen; +[ + '/assert/', + '/auth/#?test=test' +].forEach(function (path) { + var url = 'http://localhost:3000' + path; + nt = nThen(function (waitFor) { + driver.get(url); + var report = driver.wait(WebDriver.until.elementLocated(WebDriver.By.className("report")), 5000); + report.getAttribute("class").then(waitFor(function (cls) { + report.getText().then(waitFor(function (text) { + console.log("\n-----\n" + url + ' ' + text + "\n-----"); + if (!cls) { + throw new Error("cls is null"); + } else if (cls.indexOf("failure") !== -1) { + throw new Error("cls contains the word failure"); + } else if (cls.indexOf("success") === -1) { + throw new Error("cls does not contain the word success"); + } + })); + })); + }).nThen; }); + +nt(function () { + driver.quit(); +}) \ No newline at end of file diff --git a/www/auth/main.js b/www/auth/main.js index 747434c23..577e1e966 100644 --- a/www/auth/main.js +++ b/www/auth/main.js @@ -1,8 +1,9 @@ define([ 'jquery', '/common/cryptpad-common.js', + '/common/test.js', '/bower_components/tweetnacl/nacl-fast.min.js' -], function ($, Cryptpad) { +], function ($, Cryptpad, Test) { var Nacl = window.nacl; var signMsg = function (msg, privKey) { @@ -23,6 +24,11 @@ define([ Cryptpad.ready(function () { console.log('IFRAME READY'); + Test(function () { + // This is only here to maybe trigger an error. + window.drive = Cryptpad.getStore().getProxy().proxy['drive']; + Test.passed(); + }); $(window).on("message", function (jqe) { var evt = jqe.originalEvent; var data = JSON.parse(evt.data); diff --git a/www/common/test.js b/www/common/test.js new file mode 100644 index 000000000..2536f0733 --- /dev/null +++ b/www/common/test.js @@ -0,0 +1,30 @@ +define([], function () { + var out = function () { }; + if (window.location.hash.indexOf("?test=test") > -1) { + window.onerror = function (msg, url, lineNo, columnNo, e) { + document.body.innerHTML = '
' + + JSON.stringify([ + msg, + url, + lineNo, + columnNo, + e ? e.message : null, + e ? e.stack : null + ]).replace(/'; + }; + require.onError = function (e) { + document.body.innerHTML = '
' + + JSON.stringify([ + e ? e.message : null, + e ? e.stack : null + ]).replace(/'; + }; + out = function (f) { f(); } + } + out.passed = function () { + document.body.innerHTML = '
Test Passed
'; + } + return out; +}); \ No newline at end of file