Admin link-preview hook never throws without a Payload instance
syncAdminMeta returned to payload.logger in its catch even when payload was
undefined, so the Site settings afterChange hook threw with req: {} (an
unhandled rejection that made vitest, and npm publish for 1.14.5, exit 1).
Return early without payload, log through payload?.logger, skip the call in the
hook without req.payload; the fillEmptyLocales hooks get the same guard. Tests:
sync without payload, and every plugin global afterChange hook with req: {}.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
838a2f70b2
commit
71f7108cb8
@@ -88,6 +88,11 @@ describe('admin meta defaults', () => {
|
||||
await expect(syncAdminMeta(payload, resolved)).resolves.toBeUndefined()
|
||||
expect(warn).toHaveBeenCalled()
|
||||
})
|
||||
|
||||
test('sync without a Payload instance resolves (no logger to call)', async () => {
|
||||
const { resolved } = buildAdminMeta({ agency: DEFAULT_AGENCY })
|
||||
await expect(syncAdminMeta(undefined as unknown as Payload, resolved)).resolves.toBeUndefined()
|
||||
})
|
||||
})
|
||||
|
||||
describe('plugin wiring', () => {
|
||||
@@ -102,6 +107,15 @@ describe('plugin wiring', () => {
|
||||
expect(credit.serverProps).toMatchObject({ agency: 'Intecion.com', url: 'https://intecion.com', variant: 'login' })
|
||||
})
|
||||
|
||||
test('every plugin global afterChange hook resolves with req: {} (no Payload instance)', async () => {
|
||||
const config = await ipalKit({ cookieScanner: { crawl: true }, i18n, twoFactor: false, whiteLabel: true } as never)(base())
|
||||
const calls = (config.globals ?? []).flatMap((g) =>
|
||||
(g.hooks?.afterChange ?? []).map((h) => h({ context: {}, doc: {}, global: g, previousDoc: {}, req: {} } as never)),
|
||||
)
|
||||
expect(calls.length).toBeGreaterThan(0)
|
||||
await expect(Promise.all(calls)).resolves.toBeDefined()
|
||||
})
|
||||
|
||||
test('adminMeta: false and agency: false switch the pieces off', async () => {
|
||||
const config = await ipalKit({ adminMeta: false, agency: false, i18n, twoFactor: false, whiteLabel: true } as never)(base())
|
||||
expect(config.admin?.meta?.robots).toBeUndefined()
|
||||
|
||||
Reference in New Issue
Block a user