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
let nuxt = null
let logSpy
// Init nuxt.js and create server listening on localhost:4000
test.serial('Init Nuxt.js', async t => {
const options = {
rootDir: resolve(__dirname, 'fixtures/error'),
dev: false,
build: {
stats: false
}
}
const rootDir = resolve(__dirname, 'fixtures/error')
const config = require(resolve(rootDir, 'nuxt.config.js'))
config.rootDir = rootDir
config.dev = false
const logSpy = await interceptLog(async () => {
nuxt = new Nuxt(options)
logSpy = await interceptLog(async () => {
nuxt = new Nuxt(config)
await new Builder(nuxt).build()
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
test.after.always('Closing server and nuxt.js', async t => {
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
}
}