mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-14 01:53:55 +00:00
Fix hot-update.json & add tests
This commit is contained in:
parent
51618bef29
commit
54dec8e4b5
@ -49,10 +49,9 @@ export async function render (req, res) {
|
|||||||
/* istanbul ignore next */
|
/* istanbul ignore next */
|
||||||
req.url = url
|
req.url = url
|
||||||
}
|
}
|
||||||
/* istanbul ignore next */
|
|
||||||
if (this.dev && req.url.indexOf(self.options.build.publicPath) === 0 && req.url.includes('.hot-update.json')) {
|
if (this.dev && req.url.indexOf(self.options.build.publicPath) === 0 && req.url.includes('.hot-update.json')) {
|
||||||
res.statusCode = 404
|
res.statusCode = 404
|
||||||
return {html: ''}
|
return res.end()
|
||||||
}
|
}
|
||||||
const { html, error, redirected } = await this.renderRoute(req.url, context)
|
const { html, error, redirected } = await this.renderRoute(req.url, context)
|
||||||
if (redirected) {
|
if (redirected) {
|
||||||
@ -66,7 +65,6 @@ export async function render (req, res) {
|
|||||||
res.end(html, 'utf8')
|
res.end(html, 'utf8')
|
||||||
return html
|
return html
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
/* istanbul ignore next */
|
|
||||||
if (context.redirected) {
|
if (context.redirected) {
|
||||||
console.error(err) // eslint-disable-line no-console
|
console.error(err) // eslint-disable-line no-console
|
||||||
return err
|
return err
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import test from 'ava'
|
import test from 'ava'
|
||||||
import { resolve } from 'path'
|
import { resolve } from 'path'
|
||||||
|
import rp from 'request-promise-native'
|
||||||
const port = 4005
|
const port = 4005
|
||||||
const url = (route) => 'http://localhost:' + port + route
|
const url = (route) => 'http://localhost:' + port + route
|
||||||
|
|
||||||
@ -25,6 +26,15 @@ test('/stateless', async t => {
|
|||||||
t.true(html.includes('<h1>My component!</h1>'))
|
t.true(html.includes('<h1>My component!</h1>'))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('/_nuxt/test.hot-update.json should returns empty html', async t => {
|
||||||
|
try {
|
||||||
|
await rp(url('/_nuxt/test.hot-update.json'))
|
||||||
|
} catch (err) {
|
||||||
|
t.is(err.statusCode, 404)
|
||||||
|
t.is(err.response.body, '')
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
// Close server and ask nuxt to stop listening to file changes
|
// Close server and ask nuxt to stop listening to file changes
|
||||||
test.after('Closing server and nuxt.js', t => {
|
test.after('Closing server and nuxt.js', t => {
|
||||||
server.close()
|
server.close()
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
import test from 'ava'
|
import test from 'ava'
|
||||||
import { resolve } from 'path'
|
import { resolve } from 'path'
|
||||||
import rp from 'request-promise-native'
|
import rp from 'request-promise-native'
|
||||||
|
import stdMocks from 'std-mocks'
|
||||||
|
|
||||||
const port = 4000
|
const port = 4000
|
||||||
const url = (route) => 'http://localhost:' + port + route
|
const url = (route) => 'http://localhost:' + port + route
|
||||||
|
|
||||||
@ -128,11 +130,20 @@ test('/error2 status code', async t => {
|
|||||||
try {
|
try {
|
||||||
await rp(url('/error2'))
|
await rp(url('/error2'))
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
t.true(err.statusCode === 500)
|
t.is(err.statusCode, 500)
|
||||||
t.true(err.response.body.includes('Custom error'))
|
t.true(err.response.body.includes('Custom error'))
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('/redirect2 status code', async t => {
|
||||||
|
stdMocks.use()
|
||||||
|
await rp(url('/redirect2')) // Should console.error
|
||||||
|
stdMocks.restore()
|
||||||
|
const output = stdMocks.flush()
|
||||||
|
t.true(output.stderr.length >= 1)
|
||||||
|
t.true(output.stderr[0].includes('Error: NOPE!'))
|
||||||
|
})
|
||||||
|
|
||||||
// Close server and ask nuxt to stop listening to file changes
|
// Close server and ask nuxt to stop listening to file changes
|
||||||
test.after('Closing server and nuxt.js', t => {
|
test.after('Closing server and nuxt.js', t => {
|
||||||
server.close()
|
server.close()
|
||||||
|
3
test/fixtures/basic/middleware/redirect.js
vendored
Normal file
3
test/fixtures/basic/middleware/redirect.js
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
export default function ({ redirect }) {
|
||||||
|
redirect('/')
|
||||||
|
}
|
10
test/fixtures/basic/pages/redirect2.vue
vendored
Normal file
10
test/fixtures/basic/pages/redirect2.vue
vendored
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
<template></template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
export default {
|
||||||
|
middleware: 'redirect',
|
||||||
|
created () {
|
||||||
|
throw new Error('NOPE!')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
Loading…
Reference in New Issue
Block a user