(callback)
| 69 | }); |
| 70 | |
| 71 | async function serverAct(callback) { |
| 72 | await callback(); |
| 73 | // Await one turn around the event loop. |
| 74 | // This assumes that we'll flush everything we have so far. |
| 75 | await new Promise(resolve => { |
| 76 | setImmediate(resolve); |
| 77 | }); |
| 78 | if (hasErrored) { |
| 79 | throw fatalError; |
| 80 | } |
| 81 | // JSDOM doesn't support stream HTML parser so we need to give it a proper fragment. |
| 82 | // We also want to execute any scripts that are embedded. |
| 83 | // We assume that we have now received a proper fragment of HTML. |
| 84 | const bufferedContent = buffer; |
| 85 | buffer = ''; |
| 86 | const fakeBody = document.createElement('body'); |
| 87 | fakeBody.innerHTML = bufferedContent; |
| 88 | while (fakeBody.firstChild) { |
| 89 | const node = fakeBody.firstChild; |
| 90 | if (node.nodeName === 'SCRIPT') { |
| 91 | const script = document.createElement('script'); |
| 92 | script.textContent = node.textContent; |
| 93 | fakeBody.removeChild(node); |
| 94 | container.appendChild(script); |
| 95 | } else { |
| 96 | container.appendChild(node); |
| 97 | } |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | function normalizeTreeIdForTesting(id) { |
| 102 | const result = id.match(/_(R|r)_([a-z0-9]*)(H([0-9]*))?_/); |
no test coverage detected