mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-27 08:02:01 +00:00
test: error hook
This commit is contained in:
parent
7bea248fe4
commit
833f23ca76
@ -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
13
test/fixtures/error/nuxt.config.js
vendored
Executable 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
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user