Merge pull request #2950 from clarkdo/jsdomError

fix: throw jsdomError to avoid renderAndGetWindow hanging
This commit is contained in:
Sébastien Chopin 2018-03-06 10:17:07 +01:00 committed by GitHub
commit bb5a604c1b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -421,8 +421,11 @@ module.exports = class Renderer {
window.scrollTo = () => {}
}
}
const jsdomErrHandler = err => { throw err }
if (opts.virtualConsole !== false) {
options.virtualConsole = new jsdom.VirtualConsole().sendTo(console)
// throw error when window creation failed
options.virtualConsole.on('jsdomError', jsdomErrHandler)
}
url = url || 'http://localhost:3000'
const { window } = await jsdom.JSDOM.fromURL(url, options)
@ -440,6 +443,10 @@ module.exports = class Renderer {
await new Promise(resolve => {
window._onNuxtLoaded = () => resolve(window)
})
if (opts.virtualConsole !== false) {
// after window initialized successfully
options.virtualConsole.removeListener('jsdomError', jsdomErrHandler)
}
// Send back window object
return window
}