test(module): add tests for tapable

This commit is contained in:
Pooya Parsa 2017-07-18 00:08:02 +04:30
parent b5ca6b7975
commit f317b70fd5
4 changed files with 27 additions and 1 deletions

View File

@ -0,0 +1,18 @@
module.exports = function () {
let ctr = 1
// Add hook for module
this.nuxt.plugin('module', async moduleContainer => {
this.nuxt.__module_hook = moduleContainer && ctr++
})
// Add hook for renderer
this.nuxt.plugin('renderer', async renderer => {
this.nuxt.__renderer_hook = renderer && ctr++
})
// Add hook for build
this.nuxt.plugin('build', async builder => {
this.nuxt.__builder_hook = builder && ctr++
})
}

View File

@ -3,6 +3,7 @@ const path = require('path')
module.exports = function () {
// Disable parsing pages/
this.nuxt.options.build.createRoutes = () => {}
// Add /api endpoint
this.addTemplate({
fileName: 'router.js',

View File

@ -1,7 +1,8 @@
module.exports = {
loading: true,
modules: [
'~/modules/basic', // Use ~ for deprication warning coverage
'~/modules/basic',
'~/modules/tapable',
{
src: '~/modules/middleware',
options: {

View File

@ -37,6 +37,12 @@ test('Middleware', async t => {
t.is(response, 'It works!', '/api response is correct')
})
test('Tapable', async t => {
t.is(nuxt.__module_hook, 1)
t.is(nuxt.__renderer_hook, 2)
t.is(nuxt.__builder_hook, 3)
})
// Close server and ask nuxt to stop listening to file changes
test.after('Closing server and nuxt.js', t => {
nuxt.close()