Uh oh!
There was an error while loading. Please reload this page.
PortToDocs: Add methods that either collect files automatically, or allow passing documents manually - #110
Conversation
… method to allow collecting a file manually.
') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); })();
There was an error while loading. Please reload this page.
… method to allow collecting a file manually.
Unit testing is too hard in the PortToDocs project because the only method we currently use requires creating real files and modifying them as they would in a real use case scenario.
We can keep the tests we already have but we should also have the ability to create tests that don't depend on the filesystem and which allow passing the document to read and the document to write.
This is the first iteration. In the next iteration (maybe next commit, or maybe next PR) I will add unit tests using this simplified process.