mirror of
https://github.com/nuxt/nuxt.git
synced 2025-03-09 03:03:18 +00:00
fix(nuxt): register override hooks separately (#24833)
This commit is contained in:
parent
b443de230e
commit
8d5c274aab
@ -509,6 +509,11 @@ export async function loadNuxt (opts: LoadNuxtOptions): Promise<Nuxt> {
|
||||
|
||||
const nuxt = createNuxt(options)
|
||||
|
||||
// We register hooks layer-by-layer so any overrides need to be registered separately
|
||||
if (opts.overrides?.hooks) {
|
||||
nuxt.hooks.addHooks(opts.overrides.hooks)
|
||||
}
|
||||
|
||||
if (nuxt.options.debug) {
|
||||
createDebugger(nuxt.hooks, { tag: 'nuxt' })
|
||||
}
|
||||
|
26
packages/nuxt/test/load-nuxt.test.ts
Normal file
26
packages/nuxt/test/load-nuxt.test.ts
Normal file
@ -0,0 +1,26 @@
|
||||
import { fileURLToPath } from 'node:url'
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { normalize } from 'pathe'
|
||||
import { withoutTrailingSlash } from 'ufo'
|
||||
import { loadNuxt } from '../src'
|
||||
|
||||
const repoRoot = withoutTrailingSlash(normalize(fileURLToPath(new URL('../../../', import.meta.url))))
|
||||
|
||||
describe('loadNuxt', () => {
|
||||
it('respects hook overrides', async () => {
|
||||
let hookRan = false
|
||||
const nuxt = await loadNuxt({
|
||||
cwd: repoRoot,
|
||||
ready: true,
|
||||
overrides: {
|
||||
hooks: {
|
||||
ready() {
|
||||
hookRan = true
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
await nuxt.close()
|
||||
expect(hookRan).toBe(true)
|
||||
})
|
||||
})
|
Loading…
Reference in New Issue
Block a user