const esc = (s:string)=>s; function getHtml() { let pendingFiles = [{name: 'foo'}]; let text = 'bar'; let t = ''; if((t.match(/\`\`\`/g)||[]).length % 2 !== 0) t += '\\\\n\`\`\`'; const displayText=text+(pendingFiles.length>0?'\\\\n\\ud83d\\udcce '+pendingFiles.map(f=>f.name).join(', '):''); return ` `; } const html = getHtml(); const {JSDOM} = require('jsdom'); try { new JSDOM(html, {runScripts:'dangerously'}); console.log('JSDOM OK'); } catch(e) { console.error('ERR:', e.message); }