Send everything through the test global function
This commit is contained in:
parent
244bd7b378
commit
71bd808e4f
@ -22,43 +22,55 @@ 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 SC_GET_DATA = "return (window.__CRYPTPAD_TEST__) ? window.__CRYPTPAD_TEST__.getData() : '[]'";
|
||||||
|
|
||||||
|
var failed = false;
|
||||||
var nt = nThen;
|
var nt = nThen;
|
||||||
[
|
[
|
||||||
'/assert/#?test=test',
|
'/assert/#?test=test',
|
||||||
'/auth/#?test=test'
|
'/auth/#?test=test'
|
||||||
].forEach(function (path) {
|
].forEach(function (path) {
|
||||||
|
if (failed) { return; }
|
||||||
var url = 'http://localhost:3000' + path;
|
var url = 'http://localhost:3000' + path;
|
||||||
nt = nThen(function (waitFor) {
|
nt = nt(function (waitFor) {
|
||||||
|
var done = waitFor();
|
||||||
|
console.log('\n\n-----TEST ' + url + ' -----');
|
||||||
driver.get(url);
|
driver.get(url);
|
||||||
var done = false;
|
var waitTo = setTimeout(function () {
|
||||||
var logMore = function (cb) {
|
console.log("no report in 10 seconds, timing out");
|
||||||
if (done) { return; }
|
failed = true;
|
||||||
driver.executeScript(SC_GET_LOGS).then(waitFor(function (logs) {
|
}, 10000);
|
||||||
JSON.parse(logs).forEach(function (l) { console.log('>' + l); });
|
var logMore = function () {
|
||||||
if (cb) { cb(); } else { setTimeout(logMore, 50); }
|
driver.executeScript(SC_GET_DATA).then(waitFor(function (dataS) {
|
||||||
|
var data = JSON.parse(dataS);
|
||||||
|
data.forEach(function (d) {
|
||||||
|
if (d.type !== 'log') { return; }
|
||||||
|
console.log('>' + d.val);
|
||||||
|
});
|
||||||
|
data.forEach(function (d) {
|
||||||
|
if (d.type !== 'report') { return; }
|
||||||
|
console.log('RESULT: ' + d.val);
|
||||||
|
if (d.val !== 'passed') {
|
||||||
|
if (d.error) {
|
||||||
|
console.log(d.error.message);
|
||||||
|
console.log(d.error.stack);
|
||||||
|
}
|
||||||
|
failed = true;
|
||||||
|
}
|
||||||
|
clearTimeout(waitTo);
|
||||||
|
console.log('-----END TEST ' + url + ' -----');
|
||||||
|
done();
|
||||||
|
done = undefined;
|
||||||
|
});
|
||||||
|
if (done) { setTimeout(logMore, 50); }
|
||||||
}));
|
}));
|
||||||
};
|
};
|
||||||
logMore();
|
logMore();
|
||||||
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.getText().then(waitFor(function (text) {
|
|
||||||
logMore(function () { done = true; });
|
|
||||||
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;
|
}).nThen;
|
||||||
});
|
});
|
||||||
|
|
||||||
nt(function () {
|
nt(function (waitFor) {
|
||||||
driver.quit();
|
driver.quit().then(waitFor(function () {
|
||||||
|
if (failed) { process.exit(100); }
|
||||||
|
}));
|
||||||
});
|
});
|
||||||
@ -5,7 +5,7 @@ define([
|
|||||||
'json.sortify',
|
'json.sortify',
|
||||||
'/common/cryptpad-common.js',
|
'/common/cryptpad-common.js',
|
||||||
'/common/test.js'
|
'/common/test.js'
|
||||||
], function ($, Hyperjson, TextPatcher, Sortify, Cryptpad) {
|
], function ($, Hyperjson, TextPatcher, Sortify, Cryptpad, Test) {
|
||||||
window.Hyperjson = Hyperjson;
|
window.Hyperjson = Hyperjson;
|
||||||
window.TextPatcher = TextPatcher;
|
window.TextPatcher = TextPatcher;
|
||||||
window.Sortify = Sortify;
|
window.Sortify = Sortify;
|
||||||
@ -268,6 +268,12 @@ The test returned:
|
|||||||
|
|
||||||
var $report = $('.report');
|
var $report = $('.report');
|
||||||
$report.addClass(failed?'failure':'success');
|
$report.addClass(failed?'failure':'success');
|
||||||
|
|
||||||
|
if (failed) {
|
||||||
|
Test.failed();
|
||||||
|
} else {
|
||||||
|
Test.passed();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|||||||
@ -1,39 +1,13 @@
|
|||||||
define([], function () {
|
define([], function () {
|
||||||
var out = function () { };
|
var out = function () { };
|
||||||
out.passed = out;
|
out.passed = out.failed = 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) {
|
|
||||||
mkReport([
|
|
||||||
msg,
|
|
||||||
url,
|
|
||||||
lineNo,
|
|
||||||
columnNo,
|
|
||||||
e ? e.message : null,
|
|
||||||
e ? e.stack : null
|
|
||||||
]);
|
|
||||||
};
|
|
||||||
require.onError = function (e) {
|
|
||||||
mkReport([
|
|
||||||
e ? e.message : null,
|
|
||||||
e ? e.stack : null
|
|
||||||
]);
|
|
||||||
};
|
|
||||||
out = function (f) { f(); };
|
|
||||||
out.passed = function () { mkReport("Test Passed", true); };
|
|
||||||
|
|
||||||
var cpt = window.__CRYPTPAD_TEST__ = {
|
var cpt = window.__CRYPTPAD_TEST__ = {
|
||||||
logs: [],
|
data: [],
|
||||||
getLogs: function () {
|
getData: function () {
|
||||||
var logs = JSON.stringify(cpt.logs);
|
var data = JSON.stringify(cpt.data);
|
||||||
cpt.logs = [];
|
cpt.data = [];
|
||||||
return logs;
|
return data;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -52,13 +26,47 @@ define([], function () {
|
|||||||
}
|
}
|
||||||
var out = [s];
|
var out = [s];
|
||||||
try { throw new Error(); } catch (e) { out.push(e.stack.split('\n')[3]); }
|
try { throw new Error(); } catch (e) { out.push(e.stack.split('\n')[3]); }
|
||||||
window.__CRYPTPAD_TEST__.logs.push(out);
|
cpt.data.push({ type: 'log', val: out.join('') });
|
||||||
};
|
};
|
||||||
|
|
||||||
window.console._error = window.console.error;
|
window.console._error = window.console.error;
|
||||||
window.console._log = window.console.log;
|
window.console._log = window.console.log;
|
||||||
window.console.error = function (e) { window.console._error(e); doLog(e); };
|
window.console.error = function (e) { window.console._error(e); doLog(e); };
|
||||||
window.console.log = function (l) { window.console._log(l); doLog(l); };
|
window.console.log = function (l) { window.console._log(l); doLog(l); };
|
||||||
|
|
||||||
|
window.onerror = function (msg, url, lineNo, columnNo, e) {
|
||||||
|
cpt.data.push({
|
||||||
|
type: 'report',
|
||||||
|
val: 'failed',
|
||||||
|
error: {
|
||||||
|
message: e ? e.message : msg,
|
||||||
|
stack: e ? e.stack : (url + ":" + lineNo)
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
require.onError = function (e) {
|
||||||
|
cpt.data.push({
|
||||||
|
type: 'report',
|
||||||
|
val: 'failed',
|
||||||
|
error: { message: e.message, stack: e.stack }
|
||||||
|
});
|
||||||
|
};
|
||||||
|
out = function (f) { f(); };
|
||||||
|
out.passed = function () {
|
||||||
|
cpt.data.push({
|
||||||
|
type: 'report',
|
||||||
|
val: 'passed'
|
||||||
|
});
|
||||||
|
};
|
||||||
|
out.failed = function (reason) {
|
||||||
|
var e;
|
||||||
|
try { throw new Error(reason); } catch (err) { e = err; }
|
||||||
|
cpt.data.push({
|
||||||
|
type: 'report',
|
||||||
|
val: 'failed',
|
||||||
|
error: { message: e.message, stack: e.stack }
|
||||||
|
});
|
||||||
|
};
|
||||||
}
|
}
|
||||||
return out;
|
return out;
|
||||||
});
|
});
|
||||||
Loading…
x
Reference in New Issue
Block a user