import { unified } from 'unified' import remarkParse from 'remark-parse' import remarkRehype from 'remark-rehype' import rehypeStringify from 'rehype-stringify' import { VFile } from 'vfile' import { test, expect, beforeAll } from 'vitest' import { remarkLeadParagraph, type MyFile } from '.' import { type Processor } from 'unified' let processor: Processor beforeAll(() => { processor = unified() .use(remarkParse) .use(remarkLeadParagraph) .use(remarkRehype) .use(rehypeStringify) }) test('remarkLeadParagraph should extract the first paragraph', async () => { const file = new VFile({ value: '# My Article\n\nThis is the lead paragraph.\n\nThis is another paragraph.', history: ['articles/my-article.md'], data: { astro: { frontmatter: { lead: '', leadRaw: '' } } } }) const result = await processor.process(file) expect((file.data as MyFile['data']).astro.frontmatter.lead).toBe( '

This is the lead paragraph.

' ) expect((file.data as MyFile['data']).astro.frontmatter.leadRaw).toBe( 'This is the lead paragraph.' ) expect(String(result)).toBe( '

My Article

\n

This is another paragraph.

' ) // Assuming the first paragraph is removed }) test('remarkLeadParagraph should skip processing if path does not include "articles"', async () => { const file = new VFile({ value: '# My Article\n\nThis is the lead paragraph.\n\nThis is another paragraph.', history: ['some-other-folder/my-article.md'], data: { astro: { frontmatter: { lead: '', leadRaw: '' } } } }) await processor.process(file) expect((file.data as MyFile['data']).astro.frontmatter.lead).toBe('') expect((file.data as MyFile['data']).astro.frontmatter.leadRaw).toBe('') })