mirror of
https://github.com/nuxt/nuxt.git
synced 2024-12-04 11:27:13 +00:00
test: coverage for hooks exception
This commit is contained in:
parent
f0ea07ea4b
commit
750db84267
4
test/fixtures/module/modules/hooks/index.js
vendored
4
test/fixtures/module/modules/hooks/index.js
vendored
@ -20,4 +20,8 @@ module.exports = function () {
|
|||||||
this.nuxt.plugin('built', (builder) => {
|
this.nuxt.plugin('built', (builder) => {
|
||||||
this.nuxt.__builder_plugin = builder && ctr++
|
this.nuxt.__builder_plugin = builder && ctr++
|
||||||
})
|
})
|
||||||
|
|
||||||
|
this.nuxt.hook('build:extendRoutes', (builder) => {
|
||||||
|
throw new Error('hook error testing')
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import test from 'ava'
|
import test from 'ava'
|
||||||
|
import stdMocks from 'std-mocks'
|
||||||
import { resolve, normalize } from 'path'
|
import { resolve, normalize } from 'path'
|
||||||
import rp from 'request-promise-native'
|
import rp from 'request-promise-native'
|
||||||
import { Nuxt, Builder } from '../index.js'
|
import { Nuxt, Builder } from '../index.js'
|
||||||
@ -8,6 +9,7 @@ const url = (route) => 'http://localhost:' + port + route
|
|||||||
|
|
||||||
let nuxt = null
|
let nuxt = null
|
||||||
let builder = null
|
let builder = null
|
||||||
|
let builtErr = null
|
||||||
|
|
||||||
// Init nuxt.js and create server listening on localhost:4000
|
// Init nuxt.js and create server listening on localhost:4000
|
||||||
test.before('Init Nuxt.js', async t => {
|
test.before('Init Nuxt.js', async t => {
|
||||||
@ -17,7 +19,14 @@ test.before('Init Nuxt.js', async t => {
|
|||||||
config.dev = false
|
config.dev = false
|
||||||
nuxt = new Nuxt(config)
|
nuxt = new Nuxt(config)
|
||||||
builder = new Builder(nuxt)
|
builder = new Builder(nuxt)
|
||||||
|
|
||||||
|
stdMocks.use({
|
||||||
|
stdout: false,
|
||||||
|
stderr: true
|
||||||
|
})
|
||||||
await builder.build()
|
await builder.build()
|
||||||
|
stdMocks.restore()
|
||||||
|
builtErr = stdMocks.flush().stderr
|
||||||
|
|
||||||
await nuxt.listen(port, 'localhost')
|
await nuxt.listen(port, 'localhost')
|
||||||
})
|
})
|
||||||
@ -49,9 +58,16 @@ test('Hooks - Functional', async t => {
|
|||||||
t.true(builder.__build_done__)
|
t.true(builder.__build_done__)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('Hooks - Error', async t => {
|
||||||
|
const errors = builtErr.filter(value => value.indexOf('build:extendRoutes') >= 0)
|
||||||
|
t.true(errors.length === 1)
|
||||||
|
})
|
||||||
|
|
||||||
// Note: Plugin is deprecated. Please use new hooks system.
|
// Note: Plugin is deprecated. Please use new hooks system.
|
||||||
test('Plugin', async t => {
|
test('Plugin', async t => {
|
||||||
t.is(nuxt.__builder_plugin, 4)
|
t.is(nuxt.__builder_plugin, 4)
|
||||||
|
const error = builtErr.filter(value => value.indexOf('deprecated') >= 0)
|
||||||
|
t.true(error.length === 1)
|
||||||
})
|
})
|
||||||
|
|
||||||
// Close server and ask nuxt to stop listening to file changes
|
// Close server and ask nuxt to stop listening to file changes
|
||||||
|
Loading…
Reference in New Issue
Block a user