test: coverage for hooks

This commit is contained in:
Clark Du 2017-11-19 22:35:11 +08:00 committed by Pooya Parsa
parent 377416a7ef
commit f0ea07ea4b
3 changed files with 28 additions and 3 deletions

View File

@ -15,4 +15,9 @@ module.exports = function () {
this.nuxt.hook('build:done', (builder) => {
this.nuxt.__builder_hook = builder && ctr++
})
// Note: Plugin is deprecated. Please use new hooks system.
this.nuxt.plugin('built', (builder) => {
this.nuxt.__builder_plugin = builder && ctr++
})
}

View File

@ -1,7 +1,7 @@
module.exports = {
loading: true,
modules: [
'~/modules/basic',
'~~/modules/basic',
'~/modules/hooks',
{
src: '~/modules/middleware',
@ -13,5 +13,13 @@ module.exports = {
],
serverMiddleware: [
'./modules/middleware/midd2'
]
],
hooks(hook) {
hook('ready', nuxt => {
nuxt.__ready_called__ = true
})
hook('build:done', builder => {
builder.__build_done__ = true
})
}
}

View File

@ -7,6 +7,7 @@ const port = 4006
const url = (route) => 'http://localhost:' + port + route
let nuxt = null
let builder = null
// Init nuxt.js and create server listening on localhost:4000
test.before('Init Nuxt.js', async t => {
@ -15,7 +16,8 @@ test.before('Init Nuxt.js', async t => {
config.rootDir = rootDir
config.dev = false
nuxt = new Nuxt(config)
await new Builder(nuxt).build()
builder = new Builder(nuxt)
await builder.build()
await nuxt.listen(port, 'localhost')
})
@ -42,6 +44,16 @@ test('Hooks', async t => {
t.is(nuxt.__builder_hook, 3)
})
test('Hooks - Functional', async t => {
t.true(nuxt.__ready_called__)
t.true(builder.__build_done__)
})
// Note: Plugin is deprecated. Please use new hooks system.
test('Plugin', async t => {
t.is(nuxt.__builder_plugin, 4)
})
// Close server and ask nuxt to stop listening to file changes
test.after('Closing server and nuxt.js', t => {
nuxt.close()