diff --git a/test/fixtures/module/modules/middleware/use-middleware.js b/test/fixtures/module/modules/middleware/use-middleware.js new file mode 100644 index 0000000000..f6156520c3 --- /dev/null +++ b/test/fixtures/module/modules/middleware/use-middleware.js @@ -0,0 +1,3 @@ +module.exports = function (req, res, next) { + res.end('Use external middleware') +} diff --git a/test/fixtures/module/nuxt.config.js b/test/fixtures/module/nuxt.config.js index 63b3a2f62a..60ff0fecee 100755 --- a/test/fixtures/module/nuxt.config.js +++ b/test/fixtures/module/nuxt.config.js @@ -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' + }) + }) } } diff --git a/test/module.test.js b/test/module.test.js index d8fceedfb1..109d279c09 100755 --- a/test/module.test.js +++ b/test/module.test.js @@ -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()