The main entry and next/middleware re-exported module barrels that also export React client components (LanguageSwitcher, AlternateLinks*, AccessibilityWidget), so payload.config, the CLI and the proxy bundle evaluated React UI. They now import concrete files; i18n client components moved to modules/i18n/client.ts. test/entryGraph guards it. Also lint fixes in tests added on this branch. Co-Authored-By: Claude Opus 5.5 <[email protected]>
35 lines
1.5 KiB
TypeScript
35 lines
1.5 KiB
TypeScript
import type { Config, GlobalConfig } from 'payload'
|
|
|
|
import { afterEach, describe, expect, test, vi } from 'vitest'
|
|
|
|
import { buildGlobalRevalidateHook } from '../src/modules/hooks/buildRevalidateHook.js'
|
|
import { ipalKit } from '../src/plugin.js'
|
|
|
|
const i18n = { defaultLocale: 'pl', locales: [{ code: 'pl', label: 'Polski' }] } as const
|
|
const run = (g: GlobalConfig | undefined, context: object = {}) =>
|
|
g?.hooks?.afterChange?.forEach((h) => h({ context, doc: {}, global: g, previousDoc: {}, req: {} } as never))
|
|
|
|
describe('globals revalidate the site layout on save', () => {
|
|
afterEach(() => vi.unstubAllEnvs())
|
|
|
|
test('ipalKit({ revalidatePath }) wires every plugin global', async () => {
|
|
vi.stubEnv('NEXT_RUNTIME', 'nodejs')
|
|
const revalidatePath = vi.fn()
|
|
const config = await ipalKit({ i18n, revalidatePath, twoFactor: false })({ collections: [], secret: 'x' } as unknown as Config)
|
|
for (const slug of ['site-settings', 'site-integrations', 'cookie-settings', 'notifications']) {
|
|
revalidatePath.mockClear()
|
|
run(config.globals?.find((g) => g.slug === slug))
|
|
expect(revalidatePath, slug).toHaveBeenCalledWith('/', 'layout')
|
|
}
|
|
})
|
|
|
|
test('outside a Next server, or with disableRevalidate, nothing happens', () => {
|
|
const revalidatePath = vi.fn()
|
|
const hook = buildGlobalRevalidateHook({ revalidatePath })
|
|
hook({ context: {}, doc: {} } as never)
|
|
vi.stubEnv('NEXT_RUNTIME', 'nodejs')
|
|
hook({ context: { disableRevalidate: true }, doc: {} } as never)
|
|
expect(revalidatePath).not.toHaveBeenCalled()
|
|
})
|
|
})
|