mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-30 09:27:13 +00:00
test: coverage for hooks
This commit is contained in:
parent
377416a7ef
commit
f0ea07ea4b
5
test/fixtures/module/modules/hooks/index.js
vendored
5
test/fixtures/module/modules/hooks/index.js
vendored
@ -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++
|
||||
})
|
||||
}
|
||||
|
12
test/fixtures/module/nuxt.config.js
vendored
12
test/fixtures/module/nuxt.config.js
vendored
@ -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
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user