import test from 'node:test'; import assert from 'node:assert/strict'; import { parseMarkdownCodeFiles, inferLanguage, assemblePreviewHtml } from './codeParser.ts'; import { ProjectFile } from '../types/index.ts'; test('inferLanguage accurately identifies file types', () => { assert.equal(inferLanguage('index.html'), 'html'); assert.equal(inferLanguage('style.css'), 'css'); assert.equal(inferLanguage('app.js'), 'javascript'); assert.equal(inferLanguage('component.tsx'), 'typescript'); assert.equal(inferLanguage('package.json'), 'json'); assert.equal(inferLanguage('README.md'), 'markdown'); }); test('parseMarkdownCodeFiles extracts multi-file blocks with comments', () => { const markdown = ` Here is your application: \`\`\`html

Hello World

\`\`\` And the styling: \`\`\`css /* file: style.css */ h1 { color: cyan; } \`\`\` And the logic: \`\`\`javascript // file: app.js console.log("RiShre Vibe Loaded"); \`\`\` `; const files = parseMarkdownCodeFiles(markdown); assert.equal(files.length, 3); const html = files.find(f => f.name === 'index.html'); const css = files.find(f => f.name === 'style.css'); const js = files.find(f => f.name === 'app.js'); assert.ok(html); assert.ok(css); assert.ok(js); assert.ok(html.content.includes('Hello World')); assert.ok(css.content.includes('color: cyan')); assert.ok(js.content.includes('RiShre Vibe Loaded')); }); test('assemblePreviewHtml injects styles, scripts, and virtual console', () => { const files: ProjectFile[] = [ { id: '1', name: 'index.html', path: '/index.html', language: 'html', content: 'Test

Content

' }, { id: '2', name: 'style.css', path: '/style.css', language: 'css', content: 'h1 { font-size: 24px; }' }, { id: '3', name: 'app.js', path: '/app.js', language: 'javascript', content: 'console.log("Ready");' } ]; const html = assemblePreviewHtml(files); assert.ok(html.includes('RISHRE_CONSOLE_EVENT')); assert.ok(html.includes('h1 { font-size: 24px; }')); assert.ok(html.includes('console.log("Ready");')); assert.ok(html.includes('

Content

')); });