UNPKG

@zerospacegg/vynthra

Version:
256 lines (205 loc) 9.93 kB
import { test } from 'node:test'; import assert from 'node:assert'; // Test the main library index exports test('Library Index', async (t) => { await t.test('module exports', async (t) => { await t.test('should export all type definitions', async () => { const module = await import('../../src/lib/index.js'); // Test that type exports exist (they'll be undefined at runtime but should not throw) assert.doesNotThrow(() => { // These are type-only exports, so we can't directly test them // but we can ensure the module loads without errors }); }); await t.test('should export search functionality', async () => { const module = await import('../../src/lib/index.js'); assert.ok(module.searchEntities); assert.strictEqual(typeof module.searchEntities, 'function'); assert.ok(module.describeSearchResult); assert.strictEqual(typeof module.describeSearchResult, 'function'); }); await t.test('should export fuzzy matching utilities', async () => { const module = await import('../../src/lib/index.js'); assert.ok(module.createFuzzyMatcher); assert.strictEqual(typeof module.createFuzzyMatcher, 'function'); assert.ok(module.fuzzySearch); assert.strictEqual(typeof module.fuzzySearch, 'function'); assert.ok(module.contains); assert.strictEqual(typeof module.contains, 'function'); assert.ok(module.startsWith); assert.strictEqual(typeof module.startsWith, 'function'); assert.ok(module.exactMatch); assert.strictEqual(typeof module.exactMatch, 'function'); }); await t.test('should export rendering functions', async () => { const module = await import('../../src/lib/index.js'); assert.ok(module.renderSearchResultToTerminal); assert.strictEqual(typeof module.renderSearchResultToTerminal, 'function'); assert.ok(module.renderSearchResultAsMarkdown); assert.strictEqual(typeof module.renderSearchResultAsMarkdown, 'function'); }); await t.test('should export bot functionality', async () => { const module = await import('../../src/lib/index.js'); assert.ok(module.createBot); assert.strictEqual(typeof module.createBot, 'function'); assert.ok(module.deployCommands); assert.strictEqual(typeof module.deployCommands, 'function'); assert.ok(module.deleteCommands); assert.strictEqual(typeof module.deleteCommands, 'function'); assert.ok(module.createSubcommand); assert.strictEqual(typeof module.createSubcommand, 'function'); assert.ok(module.createQuerySubcommand); assert.strictEqual(typeof module.createQuerySubcommand, 'function'); }); await t.test('should export default object with main functionality', async () => { const module = await import('../../src/lib/index.js'); assert.ok(module.default); assert.strictEqual(typeof module.default, 'object'); assert.ok(module.default.searchEntities); assert.ok(module.default.describeSearchResult); assert.ok(module.default.renderSearchResultToTerminal); assert.ok(module.default.renderSearchResultAsMarkdown); }); }); await t.test('default export functionality', async (t) => { await t.test('should provide working search functionality via default export', async () => { const vynthra = (await import('../../src/lib/index.js')).default; const result = vynthra.searchEntities('lasher'); assert.ok(result); assert.strictEqual(result.type, 'single'); const description = vynthra.describeSearchResult(result); assert.strictEqual(typeof description, 'string'); assert.ok(description.length > 0); }); await t.test('should provide working rendering functionality via default export', async () => { const vynthra = (await import('../../src/lib/index.js')).default; const result = vynthra.searchEntities('lasher'); const markdown = vynthra.renderSearchResultAsMarkdown(result); assert.strictEqual(typeof markdown, 'string'); assert.ok(markdown.length > 0); assert.ok(markdown.includes('Lasher')); const terminal = vynthra.renderSearchResultToTerminal(result); assert.strictEqual(typeof terminal, 'string'); assert.ok(terminal.length > 0); }); }); await t.test('named exports vs default exports', async (t) => { await t.test('should have consistent functionality between named and default exports', async () => { const module = await import('../../src/lib/index.js'); // Test search functionality const namedResult = module.searchEntities('lasher'); const defaultResult = module.default.searchEntities('lasher'); assert.deepStrictEqual(namedResult, defaultResult); // Test description functionality const namedDescription = module.describeSearchResult(namedResult); const defaultDescription = module.default.describeSearchResult(defaultResult); assert.strictEqual(namedDescription, defaultDescription); // Test rendering functionality const namedMarkdown = module.renderSearchResultAsMarkdown(namedResult); const defaultMarkdown = module.default.renderSearchResultAsMarkdown(defaultResult); assert.strictEqual(namedMarkdown, defaultMarkdown); const namedTerminal = module.renderSearchResultToTerminal(namedResult); const defaultTerminal = module.default.renderSearchResultToTerminal(defaultResult); assert.strictEqual(namedTerminal, defaultTerminal); }); }); await t.test('re-exported iolin types', async (t) => { await t.test('should not throw when importing iolin type re-exports', async () => { // These are type-only re-exports, so we can't test them directly at runtime // but we can ensure the module loads without errors await assert.doesNotReject(async () => { await import('../../src/lib/index.js'); }); }); }); await t.test('integration test', async (t) => { await t.test('should work end-to-end with real search and render pipeline', async () => { const { searchEntities, renderSearchResultAsMarkdown, renderSearchResultToTerminal, describeSearchResult, } = await import('../../src/lib/index.js'); // Perform a search const searchResult = searchEntities('lasher'); assert.ok(searchResult); // Get description const description = describeSearchResult(searchResult); assert.strictEqual(typeof description, 'string'); assert.ok(description.length > 0); // Render as markdown const markdown = renderSearchResultAsMarkdown(searchResult); assert.strictEqual(typeof markdown, 'string'); assert.ok(markdown.length > 0); // Render for terminal const terminal = renderSearchResultToTerminal(searchResult); assert.strictEqual(typeof terminal, 'string'); assert.ok(terminal.length > 0); // Verify content consistency if (searchResult.type === 'single') { assert.ok(description.includes(searchResult.entity.name)); assert.ok(markdown.includes(searchResult.entity.name)); // Terminal output might have formatting, so we check the original name is in there somewhere assert.ok(terminal.includes(searchResult.entity.name)); } }); }); await t.test('performance', async (t) => { await t.test('should load the module efficiently', async () => { const startTime = performance.now(); await import('../../src/lib/index.js'); const endTime = performance.now(); // Module loading should be fast (under 1000ms in most cases) assert.ok(endTime - startTime < 1000); }); await t.test('should handle repeated function calls efficiently', async () => { const { searchEntities } = await import('../../src/lib/index.js'); const startTime = performance.now(); for (let i = 0; i < 100; i++) { searchEntities('lasher'); } const endTime = performance.now(); // 100 searches should complete quickly assert.ok(endTime - startTime < 1000); }); }); await t.test('library consumer scenarios', async (t) => { await t.test('should support destructured imports', async () => { const { searchEntities, renderSearchResultAsMarkdown, createBot, createSubcommand, } = await import('../../src/lib/index.js'); assert.ok(searchEntities); assert.ok(renderSearchResultAsMarkdown); assert.ok(createBot); assert.ok(createSubcommand); }); await t.test('should support namespace imports', async () => { const vynthra = await import('../../src/lib/index.js'); assert.ok(vynthra.searchEntities); assert.ok(vynthra.renderSearchResultAsMarkdown); assert.ok(vynthra.createBot); assert.ok(vynthra.createSubcommand); }); await t.test('should support default import usage pattern', async () => { const vynthra = (await import('../../src/lib/index.js')).default; // Should have all the main functionality assert.ok(vynthra.searchEntities); assert.ok(vynthra.describeSearchResult); assert.ok(vynthra.renderSearchResultToTerminal); assert.ok(vynthra.renderSearchResultAsMarkdown); // Should work as expected const result = vynthra.searchEntities('lasher'); const markdown = vynthra.renderSearchResultAsMarkdown(result); assert.strictEqual(typeof markdown, 'string'); }); await t.test('should support mixed import patterns', async () => { const { searchEntities, default: vynthra } = await import('../../src/lib/index.js'); const namedResult = searchEntities('lasher'); const defaultResult = vynthra.searchEntities('lasher'); assert.deepStrictEqual(namedResult, defaultResult); }); }); });