diff --git a/examples/full/.testRun.ts b/examples/full/.testRun.ts index b1cd5bd8..3dd29f0f 100644 --- a/examples/full/.testRun.ts +++ b/examples/full/.testRun.ts @@ -5,6 +5,8 @@ import assert from 'node:assert' let isProd: boolean const titleDefault = 'My Vike + React App' +// Set by inside the component of /images +const descriptionImages = 'Logo created by Romuald Brillout' const pages = { '/': { title: titleDefault, @@ -30,6 +32,7 @@ const pages = { }, '/without-ssr': { title: 'No SSR', + description: 'Page rendered only in the browser', text: 'This page is rendered only in the browser', counter: true, noSSR: true, @@ -48,6 +51,7 @@ function testRun(cmd: `pnpm run ${'dev' | 'preview'}`) { testPages() testPageNavigation_betweenWithSSRAndWithout() testPageNavigation_titleUpdate() + testPageNavigation_descriptionUpdate() testUseConfig() testReactSetting() testClientOnly() @@ -123,9 +127,43 @@ async function expectTitle(title: string) { await autoRetry(async () => { const titleActual = await page.evaluate(() => window.document.title) expect(titleActual).toBe(title) + expect(await getMetaContent('meta[property="og:title"]')).toBe(title) }) } +// The description tags are updated upon client-side navigation. https://github.com/vikejs/vike/issues/3524 +function testPageNavigation_descriptionUpdate() { + test('description update client-side page navigation', async () => { + await page.goto(getServerUrl() + '/') + await testCounter() + await expectDescription(null) + // Set by +description + await page.click('a:has-text("Without SSR")') + await testCounter() + await expectDescription(pages['/without-ssr'].description) + // Set by useConfig() inside +data() + await page.click('a[href="/star-wars"]') + await expectDescription(pages['/star-wars'].description) + // Set by inside UI components + await page.click('a:has-text("useConfig()")') + await testCounter() + await expectDescription(descriptionImages) + await page.click('a:has-text("Without SSR")') + await testCounter() + await expectDescription(pages['/without-ssr'].description) + await ensureWasClientSideRouted('/pages/index') + }) +} +async function expectDescription(description: string | null) { + await autoRetry(async () => { + expect(await getMetaContent('meta[name="description"]')).toBe(description) + expect(await getMetaContent('meta[property="og:description"]')).toBe(description) + }) +} +async function getMetaContent(selector: string) { + return await page.evaluate((selector) => document.querySelector(selector)?.getAttribute('content') ?? null, selector) +} + function testPages() { Object.entries(pages).forEach(([url, pageInfo]) => { testPage({ url, ...pageInfo }) @@ -202,6 +240,8 @@ function testUseConfig() { test('useConfig() HTML', async () => { const html = await fetchHtml('/images') expect(getTitle(html)).toBe(titleImages) + expect(html).toContain(``) + expect(html).toContain(``) expect(html).toMatch( partRegex`