|
| 1 | +import type { ClerkOptions } from '@clerk/shared/types'; |
| 2 | +import { describe, expect, it } from 'vitest'; |
| 3 | + |
| 4 | +import { buildBeforeHydrationSnippet, buildPageLoadSnippet } from '../snippets'; |
| 5 | + |
| 6 | +const buildSnippetOptions = (internalParams: ClerkOptions) => ({ |
| 7 | + command: 'build', |
| 8 | + packageName: '@clerk/astro', |
| 9 | + buildImportPath: '@clerk/astro/internal', |
| 10 | + internalParams, |
| 11 | +}); |
| 12 | + |
| 13 | +describe('integration snippets', () => { |
| 14 | + it('imports bundled Clerk UI instead of serializing the constructor for before-hydration scripts', () => { |
| 15 | + class ClerkUI {} |
| 16 | + |
| 17 | + const snippet = buildBeforeHydrationSnippet( |
| 18 | + buildSnippetOptions({ |
| 19 | + publishableKey: 'pk_test_123', |
| 20 | + ui: { |
| 21 | + __brand: '__clerkUI', |
| 22 | + version: '1.2.3', |
| 23 | + ClerkUI, |
| 24 | + }, |
| 25 | + } as unknown as ClerkOptions), |
| 26 | + ); |
| 27 | + |
| 28 | + expect(snippet).toContain('import { ui as __internal_clerkAstroUi } from "@clerk/ui";'); |
| 29 | + expect(snippet).toContain( |
| 30 | + 'await runInjectionScript({ ...{"publishableKey":"pk_test_123","ui":{"__brand":"__clerkUI","version":"1.2.3"}}, ui: __internal_clerkAstroUi });', |
| 31 | + ); |
| 32 | + }); |
| 33 | + |
| 34 | + it('imports bundled Clerk UI for page-load scripts including view-transition reinitialization', () => { |
| 35 | + class ClerkUI {} |
| 36 | + |
| 37 | + const snippet = buildPageLoadSnippet( |
| 38 | + buildSnippetOptions({ |
| 39 | + publishableKey: 'pk_test_123', |
| 40 | + ui: { |
| 41 | + __brand: '__clerkUI', |
| 42 | + version: '1.2.3', |
| 43 | + ClerkUI, |
| 44 | + }, |
| 45 | + } as unknown as ClerkOptions), |
| 46 | + ); |
| 47 | + |
| 48 | + expect(snippet).toContain('import { ui as __internal_clerkAstroUi } from "@clerk/ui";'); |
| 49 | + expect(snippet).toContain( |
| 50 | + '...{ ...{"publishableKey":"pk_test_123","ui":{"__brand":"__clerkUI","version":"1.2.3"}}, ui: __internal_clerkAstroUi },', |
| 51 | + ); |
| 52 | + expect(snippet).toContain( |
| 53 | + 'await runInjectionScript({ ...{"publishableKey":"pk_test_123","ui":{"__brand":"__clerkUI","version":"1.2.3"}}, ui: __internal_clerkAstroUi });', |
| 54 | + ); |
| 55 | + }); |
| 56 | + |
| 57 | + it('keeps default snippets free of the bundled UI import', () => { |
| 58 | + const snippet = buildBeforeHydrationSnippet( |
| 59 | + buildSnippetOptions({ |
| 60 | + publishableKey: 'pk_test_123', |
| 61 | + } as unknown as ClerkOptions), |
| 62 | + ); |
| 63 | + |
| 64 | + expect(snippet).not.toContain('@clerk/ui'); |
| 65 | + expect(snippet).toContain('await runInjectionScript({"publishableKey":"pk_test_123"});'); |
| 66 | + }); |
| 67 | +}); |
0 commit comments