From 2c52a8bc5ace881fb050efa588440ce270f8e32d Mon Sep 17 00:00:00 2001 From: Clark Du Date: Thu, 7 Dec 2017 16:09:49 +0800 Subject: [PATCH] test: useMiddleware string handler --- test/fixtures/module/modules/middleware/use-middleware.js | 3 +++ test/fixtures/module/nuxt.config.js | 7 +++++++ test/module.test.js | 5 +++++ 3 files changed, 15 insertions(+) create mode 100644 test/fixtures/module/modules/middleware/use-middleware.js 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()