test: error hook

This commit is contained in:
Clark Du 2018-01-27 23:29:42 +08:00
parent 7bea248fe4
commit 833f23ca76
2 changed files with 24 additions and 9 deletions

View File

@ -8,19 +8,17 @@ const port = 4005
const url = route => 'http://localhost:' + port + route const url = route => 'http://localhost:' + port + route
let nuxt = null let nuxt = null
let logSpy
// Init nuxt.js and create server listening on localhost:4000 // Init nuxt.js and create server listening on localhost:4000
test.serial('Init Nuxt.js', async t => { test.serial('Init Nuxt.js', async t => {
const options = { const rootDir = resolve(__dirname, 'fixtures/error')
rootDir: resolve(__dirname, 'fixtures/error'), const config = require(resolve(rootDir, 'nuxt.config.js'))
dev: false, config.rootDir = rootDir
build: { config.dev = false
stats: false
}
}
const logSpy = await interceptLog(async () => { logSpy = await interceptLog(async () => {
nuxt = new Nuxt(options) nuxt = new Nuxt(config)
await new Builder(nuxt).build() await new Builder(nuxt).build()
await nuxt.listen(port, 'localhost') await nuxt.listen(port, 'localhost')
}) })
@ -76,6 +74,10 @@ test.serial('/ with text/json content', async t => {
) )
}) })
test.serial('Deprecated: dev in build.extend()', async t => {
t.true(logSpy.calledWith('[build:done]: hook error'))
})
// Close server and ask nuxt to stop listening to file changes // Close server and ask nuxt to stop listening to file changes
test.after.always('Closing server and nuxt.js', async t => { test.after.always('Closing server and nuxt.js', async t => {
await nuxt.close() await nuxt.close()

13
test/fixtures/error/nuxt.config.js vendored Executable file
View File

@ -0,0 +1,13 @@
module.exports = {
hooks(hook) {
hook('build:done', nuxt => {
throw new Error('hook error')
})
hook('error', ({message}, from) => {
console.log(`[${from}]: ${message}`) // eslint-disable-line no-console
})
},
build: {
stats: false
}
}