mirror of
https://github.com/nuxt/nuxt.git
synced 2025-01-30 23:32:38 +00:00
test: useMiddleware string handler
This commit is contained in:
parent
65d5fcd91c
commit
2c52a8bc5a
3
test/fixtures/module/modules/middleware/use-middleware.js
vendored
Normal file
3
test/fixtures/module/modules/middleware/use-middleware.js
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
module.exports = function (req, res, next) {
|
||||||
|
res.end('Use external middleware')
|
||||||
|
}
|
7
test/fixtures/module/nuxt.config.js
vendored
7
test/fixtures/module/nuxt.config.js
vendored
@ -21,5 +21,12 @@ module.exports = {
|
|||||||
hook('build:done', builder => {
|
hook('build:done', builder => {
|
||||||
builder.__build_done__ = true
|
builder.__build_done__ = true
|
||||||
})
|
})
|
||||||
|
// Add hook for renderer
|
||||||
|
hook('render:before', (renderer) => {
|
||||||
|
renderer.useMiddleware({
|
||||||
|
path: '/use-middleware',
|
||||||
|
handler: '~/modules/middleware/use-middleware'
|
||||||
|
})
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -63,6 +63,11 @@ test('Hooks - Error', async t => {
|
|||||||
t.true(errors.length === 1)
|
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
|
// 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 => {
|
||||||
nuxt.close()
|
nuxt.close()
|
||||||
|
Loading…
Reference in New Issue
Block a user