Skip to main content
Glama

MCP PDF

emoji-rendering.test.tsβ€’4.82 kB
import assert from 'node:assert/strict'; import { createWriteStream, existsSync, readFileSync } from 'node:fs'; import { join } from 'node:path'; import { before, describe, test } from 'node:test'; import PDFDocument from 'pdfkit'; import { needsUnicodeFont, setupFonts } from '../src/lib/fonts.ts'; import { cleanTmpDir, getTmpSubdir } from './test-helpers.ts'; let testOutputDir: string; before(async () => { await cleanTmpDir(); testOutputDir = await getTmpSubdir('emoji-tests'); }); async function createTestPDF(filename: string, text: string, fontSpec?: string): Promise<string> { const outputPath = join(testOutputDir, filename); const doc = new PDFDocument(); const stream = createWriteStream(outputPath); doc.pipe(stream); // Setup fonts const fonts = await setupFonts(doc, fontSpec); doc.font(fonts.regular).fontSize(24).text(text); doc.end(); await new Promise<void>((resolve, reject) => { stream.on('finish', () => resolve()); stream.on('error', reject); }); return outputPath; } describe('Emoji and Unicode Rendering', (): void => { test('detects emoji as needing Unicode font', (): void => { assert.strictEqual(needsUnicodeFont('Hello πŸ‘‹'), true); assert.strictEqual(needsUnicodeFont('πŸ˜€ πŸŽ‰ πŸš€'), true); assert.strictEqual(needsUnicodeFont('Test βœ… ❌'), true); }); test('creates PDF with emoji using default font', async (): Promise<void> => { const text = 'Hello World πŸ‘‹ πŸ˜€ πŸŽ‰'; const path = await createTestPDF('emoji-default.pdf', text); assert.ok(existsSync(path), 'PDF should be created'); const stats = readFileSync(path); assert.ok(stats.length > 0, 'PDF should have content'); console.log(` πŸ“„ Created: ${path} (${stats.length} bytes)`); }); test('creates PDF with emoji using auto-detect font', async (): Promise<void> => { const text = 'Hello World πŸ‘‹ πŸ˜€ πŸŽ‰'; const path = await createTestPDF('emoji-auto.pdf', text, 'auto'); assert.ok(existsSync(path), 'PDF should be created'); const stats = readFileSync(path); assert.ok(stats.length > 0, 'PDF should have content'); console.log(` πŸ“„ Created: ${path} (${stats.length} bytes)`); }); test('creates PDF with various emoji categories', async (): Promise<void> => { const emojiTests = [ { category: 'Smileys', text: 'πŸ˜€ πŸ˜ƒ πŸ˜„ 😁 πŸ˜† πŸ˜… 🀣 πŸ˜‚' }, { category: 'Gestures', text: 'πŸ‘‹ 🀚 πŸ– βœ‹ πŸ–– πŸ‘Œ 🀌' }, { category: 'Symbols', text: '❀️ πŸ’” πŸ’― βœ… ❌ ⭐ πŸ”₯' }, { category: 'Objects', text: 'πŸ“± πŸ’» ⌨️ πŸ–₯ πŸ–¨ πŸ“ž πŸ“§' }, ]; for (const { category, text } of emojiTests) { const filename = `emoji-${category.toLowerCase()}.pdf`; const path = await createTestPDF(filename, `${category}: ${text}`, 'auto'); assert.ok(existsSync(path), `${category} PDF should be created`); const stats = readFileSync(path); console.log(` πŸ“„ ${category}: ${path} (${stats.length} bytes)`); } }); test('creates PDF with CJK characters', async (): Promise<void> => { const text = 'δ½ ε₯½δΈ–η•Œ γ“γ‚“γ«γ‘γ―δΈ–η•Œ μ•ˆλ…•ν•˜μ„Έμš” 세계'; const path = await createTestPDF('unicode-cjk.pdf', text, 'auto'); assert.ok(existsSync(path), 'CJK PDF should be created'); const stats = readFileSync(path); assert.ok(stats.length > 0, 'PDF should have content'); console.log(` πŸ“„ Created: ${path} (${stats.length} bytes)`); }); test('creates PDF with mixed ASCII and emoji', async (): Promise<void> => { const text = ` Technical Skills: β€’ TypeScript πŸ’™ β€’ Node.js ⚑ β€’ React βš›οΈ β€’ Testing βœ… Achievements: πŸ† First place in hackathon 🎯 100% test coverage πŸš€ Launched 5 products `; const path = await createTestPDF('mixed-content.pdf', text, 'auto'); assert.ok(existsSync(path), 'Mixed content PDF should be created'); const stats = readFileSync(path); console.log(` πŸ“„ Created: ${path} (${stats.length} bytes)`); }); test('creates PDF with font from URL', async (): Promise<void> => { // Noto Sans has good Unicode coverage const fontUrl = 'https://cdn.jsdelivr.net/npm/@fontsource/noto-sans@5.0.0/files/noto-sans-latin-400-normal.woff2'; const text = 'Hello World πŸ‘‹ Testing with downloaded font'; const path = await createTestPDF('emoji-url-font.pdf', text, fontUrl); assert.ok(existsSync(path), 'PDF with URL font should be created'); const stats = readFileSync(path); console.log(` πŸ“„ Created: ${path} (${stats.length} bytes)`); }); }); // Print summary at the end test('print test output directory', (): void => { console.log(`\nπŸ“ Test PDFs generated in: ${testOutputDir}`); console.log(' Open these files to visually verify emoji rendering\n'); });

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/mcp-z/mcp-pdf'

If you have feedback or need assistance with the MCP directory API, please join our Discord server