import { describe, it, expect } from 'vitest' import { recipes, allRecipes, getRecipeBySlug, getRecipeForUrl, genericRecipe, } from './index' describe('recipes', () => { it('exports 8 site-specific recipes', () => { expect(recipes.length).toBe(8) }) it('exports 9 total recipes including generic', () => { expect(allRecipes.length).toBe(9) }) it('all recipes have required metadata', () => { for (const recipe of allRecipes) { expect(recipe.meta.slug).toBeDefined() expect(recipe.meta.name).toBeDefined() expect(recipe.meta.description).toBeDefined() expect(recipe.meta.category).toBeDefined() expect(recipe.meta.icon).toBeDefined() expect(recipe.meta.maintainers.length).toBeGreaterThan(0) } }) it('all recipes have match pattern', () => { for (const recipe of allRecipes) { expect(recipe.match).toBeDefined() } }) it('all recipes have fields', () => { for (const recipe of allRecipes) { expect(Object.keys(recipe.fields).length).toBeGreaterThan(0) } }) it('all recipes have extract function', () => { for (const recipe of allRecipes) { expect(typeof recipe.extract).toBe('function') } }) }) describe('getRecipeBySlug', () => { it('returns recipe by slug', () => { const github = getRecipeBySlug('github') expect(github).toBeDefined() expect(github?.meta.slug).toBe('github') }) it('returns undefined for unknown slug', () => { const unknown = getRecipeBySlug('unknown-recipe') expect(unknown).toBeUndefined() }) }) describe('getRecipeForUrl', () => { it('matches GitHub URLs', () => { const recipe = getRecipeForUrl('https://github.com/facebook/react') expect(recipe.meta.slug).toBe('github') }) it('matches Amazon URLs', () => { const recipe = getRecipeForUrl('https://www.amazon.com/dp/B08N5WRWNW') expect(recipe.meta.slug).toBe('amazon') }) it('matches YouTube URLs', () => { const recipe = getRecipeForUrl('https://www.youtube.com/watch?v=dQw4w9WgXcQ') expect(recipe.meta.slug).toBe('youtube') }) it('matches Twitter/X URLs', () => { expect(getRecipeForUrl('https://x.com/user/status/123').meta.slug).toBe('twitter') expect(getRecipeForUrl('https://twitter.com/user/status/123').meta.slug).toBe('twitter') }) it('returns generic for unknown URLs', () => { const recipe = getRecipeForUrl('https://example.com/random') expect(recipe.meta.slug).toBe('generic') }) }) describe('extract functions', () => { it('amazon extracts price and title', async () => { const amazon = getRecipeBySlug('amazon') const html = ` Test Product 99 99 In Stock ` const data = await amazon!.extract(html, 'https://amazon.com/dp/test') expect(data.title).toBe('Test Product') expect(data.price).toBe(99.99) expect(data.inStock).toBe(true) }) it('github extracts repo info', async () => { const github = getRecipeBySlug('github') const html = ` ` const data = await github!.extract(html, 'https://github.com/facebook/react') expect(data.title).toBe('facebook/react') expect(data.description).toBe('A JavaScript library') }) it('generic extracts basic metadata', async () => { const html = `