fix(nuxt): register override hooks separately (#24833)

This commit is contained in:
Daniel Roe 2023-12-19 21:26:13 +01:00 committed by GitHub
parent b443de230e
commit 8d5c274aab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 0 deletions

View File

@ -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' })
}

View 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)
})
})