mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-30 09:27:13 +00:00
Fix hot-update.json & add tests
This commit is contained in:
parent
51618bef29
commit
54dec8e4b5
@ -49,12 +49,11 @@ export async function render (req, res) {
|
||||
/* istanbul ignore next */
|
||||
req.url = url
|
||||
}
|
||||
/* istanbul ignore next */
|
||||
if (this.dev && req.url.indexOf(self.options.build.publicPath) === 0 && req.url.includes('.hot-update.json')) {
|
||||
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) {
|
||||
return html
|
||||
}
|
||||
@ -66,7 +65,6 @@ export async function render (req, res) {
|
||||
res.end(html, 'utf8')
|
||||
return html
|
||||
} catch (err) {
|
||||
/* istanbul ignore next */
|
||||
if (context.redirected) {
|
||||
console.error(err) // eslint-disable-line no-console
|
||||
return err
|
||||
|
@ -1,5 +1,6 @@
|
||||
import test from 'ava'
|
||||
import { resolve } from 'path'
|
||||
import rp from 'request-promise-native'
|
||||
const port = 4005
|
||||
const url = (route) => 'http://localhost:' + port + route
|
||||
|
||||
@ -25,6 +26,15 @@ test('/stateless', async t => {
|
||||
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
|
||||
test.after('Closing server and nuxt.js', t => {
|
||||
server.close()
|
||||
|
@ -1,6 +1,8 @@
|
||||
import test from 'ava'
|
||||
import { resolve } from 'path'
|
||||
import rp from 'request-promise-native'
|
||||
import stdMocks from 'std-mocks'
|
||||
|
||||
const port = 4000
|
||||
const url = (route) => 'http://localhost:' + port + route
|
||||
|
||||
@ -128,11 +130,20 @@ test('/error2 status code', async t => {
|
||||
try {
|
||||
await rp(url('/error2'))
|
||||
} catch (err) {
|
||||
t.true(err.statusCode === 500)
|
||||
t.is(err.statusCode, 500)
|
||||
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
|
||||
test.after('Closing server and nuxt.js', t => {
|
||||
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