utils.test.ts 845 B

123456789101112131415161718192021222324
  1. import { describe, expect, test } from 'bun:test';
  2. import { extractHeadingsFromMarkdown, joinRenderedContent } from './utils';
  3. describe('smartfetch/utils', () => {
  4. test('extracts cleaned headings from markdown', () => {
  5. const headings = extractHeadingsFromMarkdown(
  6. ['# Intro', '## Details ###', '### C#', 'plain text'].join('\n'),
  7. );
  8. expect(headings).toEqual(['Intro', 'Details', 'C#']);
  9. });
  10. test('injects metadata comments after an XML declaration in html output', () => {
  11. const result = joinRenderedContent(
  12. '---\nsource: "smartfetch"\n---\n\n',
  13. '<?xml version="1.0"?><root>ok</root>',
  14. 'html',
  15. );
  16. expect(result).toStartWith('<?xml version="1.0"?>');
  17. expect(result).toContain('<!--\n---\nsource: "smartfetch"\n---\n-->');
  18. expect(result).toContain('<root>ok</root>');
  19. });
  20. });