test: useMiddleware string handler

This commit is contained in:
Clark Du 2017-12-07 16:09:49 +08:00 committed by Pooya Parsa
parent 65d5fcd91c
commit 2c52a8bc5a
3 changed files with 15 additions and 0 deletions

View File

@ -0,0 +1,3 @@
module.exports = function (req, res, next) {
res.end('Use external middleware')
}

View File

@ -21,5 +21,12 @@ module.exports = {
hook('build:done', builder => {
builder.__build_done__ = true
})
// Add hook for renderer
hook('render:before', (renderer) => {
renderer.useMiddleware({
path: '/use-middleware',
handler: '~/modules/middleware/use-middleware'
})
})
}
}

View File

@ -63,6 +63,11 @@ test('Hooks - Error', async t => {
t.true(errors.length === 1)
})
test('Hooks - Use external middleware before render', async t => {
let response = await rp(url('/use-middleware'))
t.is(response, 'Use external middleware')
})
// Close server and ask nuxt to stop listening to file changes
test.after('Closing server and nuxt.js', t => {
nuxt.close()