mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-27 16:12:12 +00:00
Update JSDOM logic
This commit is contained in:
parent
2bb5cca1d5
commit
979e15db2a
@ -153,7 +153,7 @@ export async function renderAndGetWindow (url, opts = {}) {
|
|||||||
let options = {
|
let options = {
|
||||||
resources: 'usable', // load subresources (https://github.com/tmpvar/jsdom#loading-subresources)
|
resources: 'usable', // load subresources (https://github.com/tmpvar/jsdom#loading-subresources)
|
||||||
runScripts: 'dangerously',
|
runScripts: 'dangerously',
|
||||||
beforeParse(window) {
|
beforeParse (window) {
|
||||||
// Mock window.scrollTo
|
// Mock window.scrollTo
|
||||||
window.scrollTo = () => {}
|
window.scrollTo = () => {}
|
||||||
}
|
}
|
||||||
@ -164,9 +164,10 @@ export async function renderAndGetWindow (url, opts = {}) {
|
|||||||
url = url || 'http://localhost:3000'
|
url = url || 'http://localhost:3000'
|
||||||
const { window } = await jsdom.JSDOM.fromURL(url, options)
|
const { window } = await jsdom.JSDOM.fromURL(url, options)
|
||||||
// If Nuxt could not be loaded (error from the server-side)
|
// If Nuxt could not be loaded (error from the server-side)
|
||||||
if (!window.__NUXT__) {
|
const nuxtExists = window.document.body.innerHTML.includes('window.__NUXT__')
|
||||||
|
if (!nuxtExists) {
|
||||||
let error = new Error('Could not load the nuxt app')
|
let error = new Error('Could not load the nuxt app')
|
||||||
error.body = window.document.getElementsByTagName('body')[0].innerHTML
|
error.body = window.document.body.innerHTML
|
||||||
throw error
|
throw error
|
||||||
}
|
}
|
||||||
// Used by nuxt.js to say when the components are loaded and the app ready
|
// Used by nuxt.js to say when the components are loaded and the app ready
|
||||||
|
@ -33,12 +33,8 @@ test('/404 should display an error too', async t => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
test('/ with renderAndGetWindow()', async t => {
|
test('/ with renderAndGetWindow()', async t => {
|
||||||
try {
|
const err = await t.throws(nuxt.renderAndGetWindow(url('/')))
|
||||||
await nuxt.renderAndGetWindow(url('/'))
|
t.is(err.response.statusCode, 500)
|
||||||
} catch (e) {
|
|
||||||
t.true(e.message.includes('Could not load the nuxt app'))
|
|
||||||
t.true(e.body.includes('render function or template not defined in component'))
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
// Close server and ask nuxt to stop listening to file changes
|
// Close server and ask nuxt to stop listening to file changes
|
||||||
|
2
test/fixtures/with-config/app.html
vendored
2
test/fixtures/with-config/app.html
vendored
@ -4,7 +4,7 @@
|
|||||||
{{ HEAD }}
|
{{ HEAD }}
|
||||||
</head>
|
</head>
|
||||||
<body {{ BODY_ATTRS }}>
|
<body {{ BODY_ATTRS }}>
|
||||||
{{ APP }}
|
|
||||||
<p>Made by Nuxt.js team</p>
|
<p>Made by Nuxt.js team</p>
|
||||||
|
{{ APP }}
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
2
test/fixtures/with-config/pages/error.vue
vendored
2
test/fixtures/with-config/pages/error.vue
vendored
@ -5,7 +5,7 @@
|
|||||||
<script>
|
<script>
|
||||||
export default {
|
export default {
|
||||||
fetch ({ error }) {
|
fetch ({ error }) {
|
||||||
error({ message: 'Nuxt Error', statusCode: 300 })
|
error({ message: 'Nuxt Error', statusCode: 200 })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
@ -78,7 +78,7 @@ test('/test/error', async t => {
|
|||||||
test('/test/user-agent', async t => {
|
test('/test/user-agent', async t => {
|
||||||
const window = await nuxt.renderAndGetWindow(url('/test/user-agent'))
|
const window = await nuxt.renderAndGetWindow(url('/test/user-agent'))
|
||||||
const html = window.document.body.innerHTML
|
const html = window.document.body.innerHTML
|
||||||
t.true(html.includes('<pre>Node.js'))
|
t.true(html.includes('<pre>Mozilla'))
|
||||||
})
|
})
|
||||||
|
|
||||||
test('/test/about-bis (added with extendRoutes)', async t => {
|
test('/test/about-bis (added with extendRoutes)', async t => {
|
||||||
|
Loading…
Reference in New Issue
Block a user