fork-openpgpjs/test/unittests.html
Daniel Huigens f3b16386dc Use dynamic import in lightweight build
Instead of dynamically loading a <script> tag.

This also removes the non-module lightweight build.
2021-02-09 19:25:20 +01:00

51 lines
1.6 KiB
HTML

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>OpenPGPJS Unit Tests</title>
<link rel="stylesheet" href="../node_modules/mocha/mocha.css" />
<!-- libs -->
<script src="../node_modules/mocha/mocha.js"></script>
<script>
mocha.setup('bdd');
mocha.timeout(240000);
</script>
</head>
<body>
<div id="mocha"></div>
<script type="module">
(async () => {
const openpgp = await import(
window.location.search.includes('lightweight=') ?
'../dist/lightweight/openpgp.mjs' :
'../dist/openpgp.mjs'
);
window.openpgp = openpgp;
await import('./lib/unittests-bundle.js');
if (typeof openpgp !== 'undefined') {
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>
</html>