From 0af505081968c2519e5d028d15d4c18e7a215240 Mon Sep 17 00:00:00 2001 From: Chris Swithinbank Date: Thu, 16 Nov 2023 22:27:18 +0100 Subject: [PATCH] Expand testing (#1045) --- .../__tests__/basics/sitemap.test.ts | 40 ++++++++ .../__tests__/remark-rehype/asides.test.ts | 87 ++++++++++++++++++ .../remark-rehype/asides/generates-aside.html | 1 + .../asides/handles-complex-children.html | 2 + .../remark-rehype/asides/nested-asides.html | 1 + .../remark-rehype/rehype-tabs.test.ts | 91 +++++++++++++++++++ packages/starlight/integrations/sitemap.ts | 18 ++-- packages/starlight/package.json | 1 + pnpm-lock.yaml | 3 + 9 files changed, 237 insertions(+), 7 deletions(-) create mode 100644 packages/starlight/__tests__/basics/sitemap.test.ts create mode 100644 packages/starlight/__tests__/remark-rehype/asides.test.ts create mode 100644 packages/starlight/__tests__/remark-rehype/asides/generates-aside.html create mode 100644 packages/starlight/__tests__/remark-rehype/asides/handles-complex-children.html create mode 100644 packages/starlight/__tests__/remark-rehype/asides/nested-asides.html create mode 100644 packages/starlight/__tests__/remark-rehype/rehype-tabs.test.ts diff --git a/packages/starlight/__tests__/basics/sitemap.test.ts b/packages/starlight/__tests__/basics/sitemap.test.ts new file mode 100644 index 00000000000..d33820402be --- /dev/null +++ b/packages/starlight/__tests__/basics/sitemap.test.ts @@ -0,0 +1,40 @@ +import { describe, expect, test } from 'vitest'; +import { getSitemapConfig, starlightSitemap } from '../../integrations/sitemap'; +import type { StarlightConfig } from '../../types'; +import { StarlightConfigSchema, type StarlightUserConfig } from '../../utils/user-config'; + +describe('starlightSitemap', () => { + test('returns @astrojs/sitemap integration', () => { + const integration = starlightSitemap({} as StarlightConfig); + expect(integration.name).toBe('@astrojs/sitemap'); + }); +}); + +describe('getSitemapConfig', () => { + test('configures i18n config', () => { + const config = getSitemapConfig( + StarlightConfigSchema.parse({ + title: 'i18n test', + locales: { root: { lang: 'en', label: 'English' }, fr: { label: 'French' } }, + } satisfies StarlightUserConfig) + ); + expect(config).toMatchInlineSnapshot(` + { + "i18n": { + "defaultLocale": "root", + "locales": { + "fr": "fr", + "root": "en", + }, + }, + } + `); + }); + + test('no config for monolingual sites', () => { + const config = getSitemapConfig( + StarlightConfigSchema.parse({ title: 'i18n test' } satisfies StarlightUserConfig) + ); + expect(config).toMatchInlineSnapshot('{}'); + }); +}); diff --git a/packages/starlight/__tests__/remark-rehype/asides.test.ts b/packages/starlight/__tests__/remark-rehype/asides.test.ts new file mode 100644 index 00000000000..57fe4191840 --- /dev/null +++ b/packages/starlight/__tests__/remark-rehype/asides.test.ts @@ -0,0 +1,87 @@ +import { createMarkdownProcessor } from '@astrojs/markdown-remark'; +import { describe, expect, test } from 'vitest'; +import { starlightAsides } from '../../integrations/asides'; + +const processor = await createMarkdownProcessor({ + remarkPlugins: [...starlightAsides()], +}); + +test('generates