Procedually clicking on context items to expand them after dom mutation is over to enable auto expand behavier which Mochawesome doesn't plan to support(adamgruber/mochawesome#217)
!(function() {
function postExpand() {
const contextEls = document.querySelectorAll('.with-context');
[...contextEls].forEach(item => {
// expand test items with context
item.querySelector('header').click();
});
}
// wait till the dom mutation is over
const targetNode = document.getElementById('report');
const config = {
childList: true,
subtree: true
};
const maxWait = 5000;
const waitTimeSpan = 1000;
let isDone = false;
let timerRef;
function timer() {
return setTimeout(done, waitTimeSpan);
}
function done() {
observer.disconnect();
postExpand();
isDone = true;
}
const observer = new MutationObserver(mutationsList => {
if (timerRef) {
clearTimeout(timerRef);
}
timerRef = timer();
});
setTimeout(() => {
if (isDone) {
return;
}
if (timerRef) {
clearTimeout(timerRef);
}
done();
}, maxWait);
observer.observe(targetNode, config);
})();