Unit tests: Fix autoscroll with skipped tests

This commit is contained in:
Daniel Huigens 2020-02-18 18:43:34 +01:00
parent 35c13212dd
commit 29f29f6c6e
2 changed files with 17 additions and 8 deletions

View File

@ -19,7 +19,23 @@
<script src="lib/unittests-bundle.js"></script>
<script>
if (typeof openpgp !== 'undefined') {
mocha.run();
const runner = mocha.run();
var wasScrolledDown = true;
function beforeTestReport() {
wasScrolledDown = document.documentElement.scrollHeight - document.documentElement.scrollTop - document.documentElement.clientHeight < 50;
}
function afterTestReport() {
if (wasScrolledDown || openpgp.config.ci) {
window.scrollTo(0, document.documentElement.scrollHeight);
}
}
runner._events['suite'].unshift(beforeTestReport);
runner._events['pass'].unshift(beforeTestReport);
runner._events['fail'].unshift(beforeTestReport);
runner._events['pending'].unshift(beforeTestReport);
document.addEventListener('scroll', beforeTestReport);
runner.on('suite', afterTestReport);
runner.on('test end', afterTestReport);
}
</script>
</body>

View File

@ -36,13 +36,6 @@ describe('Unit Tests', function () {
openpgp.config.s2k_iteration_count_byte = 0;
openpgp.config.indutny_elliptic_path = '../dist/elliptic.min.js';
afterEach(function () {
if (window.scrollY >= document.body.scrollHeight - window.innerHeight - 100
|| openpgp.config.ci) {
window.scrollTo(0, document.body.scrollHeight);
}
});
window.location.search.substr(1).split('&').forEach(param => {
const [key, value] = param.split('=');
if (key && key !== 'grep') {