a new and more horrible way of sniffing the logs out of the instance
This commit is contained in:
@@ -22,17 +22,30 @@ if (process.env.SAUCE_USERNAME !== undefined) {
|
|||||||
driver = new WebDriver.Builder().withCapabilities({ browserName: "chrome" }).build();
|
driver = new WebDriver.Builder().withCapabilities({ browserName: "chrome" }).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var SC_GET_LOGS = "return (window.__CRYPTPAD_TEST__) ? window.__CRYPTPAD_TEST__.getLogs() : '[]'";
|
||||||
|
|
||||||
var nt = nThen;
|
var nt = nThen;
|
||||||
[
|
[
|
||||||
'/assert/',
|
'/assert/#?test=test',
|
||||||
'/auth/#?test=test'
|
'/auth/#?test=test'
|
||||||
].forEach(function (path) {
|
].forEach(function (path) {
|
||||||
var url = 'http://localhost:3000' + path;
|
var url = 'http://localhost:3000' + path;
|
||||||
nt = nThen(function (waitFor) {
|
nt = nThen(function (waitFor) {
|
||||||
driver.get(url);
|
driver.get(url);
|
||||||
|
var done = false;
|
||||||
|
var logMore = function (cb) {
|
||||||
|
if (done) { return; }
|
||||||
|
driver.executeScript(SC_GET_LOGS).then(waitFor(function (logs) {
|
||||||
|
JSON.parse(logs).forEach(function (l) { console.log('>' + l); });
|
||||||
|
if (cb) { cb(); } else { setTimeout(logMore, 50); }
|
||||||
|
}));
|
||||||
|
};
|
||||||
|
logMore();
|
||||||
|
driver.wait(WebDriver.until.elementLocated(WebDriver.By.className("report")), 5000);
|
||||||
var report = driver.wait(WebDriver.until.elementLocated(WebDriver.By.className("report")), 5000);
|
var report = driver.wait(WebDriver.until.elementLocated(WebDriver.By.className("report")), 5000);
|
||||||
report.getAttribute("class").then(waitFor(function (cls) {
|
report.getAttribute("class").then(waitFor(function (cls) {
|
||||||
report.getText().then(waitFor(function (text) {
|
report.getText().then(waitFor(function (text) {
|
||||||
|
logMore(function () { done = true; });
|
||||||
console.log("\n-----\n" + url + ' ' + text + "\n-----");
|
console.log("\n-----\n" + url + ' ' + text + "\n-----");
|
||||||
if (!cls) {
|
if (!cls) {
|
||||||
throw new Error("cls is null");
|
throw new Error("cls is null");
|
||||||
@@ -48,4 +61,4 @@ var nt = nThen;
|
|||||||
|
|
||||||
nt(function () {
|
nt(function () {
|
||||||
driver.quit();
|
driver.quit();
|
||||||
});
|
})
|
||||||
@@ -4,6 +4,7 @@ define([
|
|||||||
'/bower_components/textpatcher/TextPatcher.amd.js',
|
'/bower_components/textpatcher/TextPatcher.amd.js',
|
||||||
'json.sortify',
|
'json.sortify',
|
||||||
'/common/cryptpad-common.js',
|
'/common/cryptpad-common.js',
|
||||||
|
'/common/test.js'
|
||||||
], function ($, Hyperjson, TextPatcher, Sortify, Cryptpad) {
|
], function ($, Hyperjson, TextPatcher, Sortify, Cryptpad) {
|
||||||
window.Hyperjson = Hyperjson;
|
window.Hyperjson = Hyperjson;
|
||||||
window.TextPatcher = TextPatcher;
|
window.TextPatcher = TextPatcher;
|
||||||
|
|||||||
@@ -1,30 +1,64 @@
|
|||||||
define([], function () {
|
define([], function () {
|
||||||
var out = function () { };
|
var out = function () { };
|
||||||
|
out.passed = out;
|
||||||
|
var mkReport = function (list, pass) {
|
||||||
|
var rpt = document.createElement('div');
|
||||||
|
rpt.textContent = JSON.stringify(list);
|
||||||
|
rpt.setAttribute('class', 'report ' + (pass ? 'success' : 'failure'));
|
||||||
|
rpt.setAttribute('style', 'display:none;');
|
||||||
|
document.body.appendChild(rpt);
|
||||||
|
}
|
||||||
if (window.location.hash.indexOf("?test=test") > -1) {
|
if (window.location.hash.indexOf("?test=test") > -1) {
|
||||||
window.onerror = function (msg, url, lineNo, columnNo, e) {
|
window.onerror = function (msg, url, lineNo, columnNo, e) {
|
||||||
document.body.innerHTML = '<div class="report fail">' +
|
mkReport([
|
||||||
JSON.stringify([
|
msg,
|
||||||
msg,
|
url,
|
||||||
url,
|
lineNo,
|
||||||
lineNo,
|
columnNo,
|
||||||
columnNo,
|
e ? e.message : null,
|
||||||
e ? e.message : null,
|
e ? e.stack : null
|
||||||
e ? e.stack : null
|
]);
|
||||||
]).replace(/</g, '') +
|
|
||||||
'</div>';
|
|
||||||
};
|
};
|
||||||
require.onError = function (e) {
|
require.onError = function (e) {
|
||||||
document.body.innerHTML = '<div class="report fail">' +
|
mkReport([
|
||||||
JSON.stringify([
|
e ? e.message : null,
|
||||||
e ? e.message : null,
|
e ? e.stack : null
|
||||||
e ? e.stack : null
|
]);
|
||||||
]).replace(/</g, '') +
|
|
||||||
'</div>';
|
|
||||||
};
|
};
|
||||||
out = function (f) { f(); };
|
out = function (f) { f(); };
|
||||||
|
out.passed = function () { mkReport("Test Passed", true); };
|
||||||
|
|
||||||
|
var cpt = window.__CRYPTPAD_TEST__ = {
|
||||||
|
logs: [],
|
||||||
|
getLogs: function () {
|
||||||
|
var logs = JSON.stringify(cpt.logs);
|
||||||
|
cpt.logs = [];
|
||||||
|
return logs;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// jshint -W103
|
||||||
|
var errProto = (new Error()).__proto__;
|
||||||
|
var doLog = function (o) {
|
||||||
|
var s;
|
||||||
|
if (typeof(o) === 'object' && o.__proto__ === errProto) {
|
||||||
|
s = JSON.stringify([ o.message, o.stack ]);
|
||||||
|
} else if (typeof(s) !== 'string') {
|
||||||
|
try {
|
||||||
|
s = JSON.stringify(o);
|
||||||
|
} catch (e) {
|
||||||
|
s = String(o);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var out = [s];
|
||||||
|
try { throw new Error(); } catch (e) { out.push(e.stack.split('\n')[3]); }
|
||||||
|
window.__CRYPTPAD_TEST__.logs.push(out);
|
||||||
|
};
|
||||||
|
|
||||||
|
window.console._error = window.console.error;
|
||||||
|
window.console._log = window.console.log;
|
||||||
|
window.console.error = function (e) { window.console._error(e); doLog(e); };
|
||||||
|
window.console.log = function (l) { window.console._log(l); doLog(l); };
|
||||||
}
|
}
|
||||||
out.passed = function () {
|
|
||||||
document.body.innerHTML = '<div class="report success">Test Passed</div>';
|
|
||||||
};
|
|
||||||
return out;
|
return out;
|
||||||
});
|
});
|
||||||
Reference in New Issue
Block a user