readme.test.ts•3.08 kB
import { extractStability, extractDescription } from './readme.js';
describe('README Parser', () => {
describe('extractStability', () => {
it('should extract stability from autogenerated status section', () => {
const content = `# Component Name
| Status | |
|-------|--|
| Stability | [beta] |
| Distributions | [contrib] |
Some other content...`;
expect(extractStability(content)).toBe('beta');
});
it('should extract stability from old format', () => {
const content = `# Component Name
Stability: beta
Some other content...`;
expect(extractStability(content)).toBe('beta');
});
it('should return Unknown when no stability info is found', () => {
const content = `# Component Name
Some other content...`;
expect(extractStability(content)).toBe('Unknown');
});
it('should handle stability with additional text', () => {
const content = `# Component Name
| Status | |
|-------|--|
| Stability | [beta] (see [breaking changes](link)) |
| Distributions | [contrib] |
Some other content...`;
expect(extractStability(content)).toBe('beta');
});
});
describe('extractDescription', () => {
it('should extract description from first paragraph after title', () => {
const content = `# Component Name
This is a description of the component.
Some other content...`;
expect(extractDescription(content)).toBe('This is a description of the component.');
});
it('should skip autogenerated status section when extracting description', () => {
const content = `# Component Name
<!-- status autogenerated section -->
| Status | |
|-------|--|
| Stability | [beta] |
<!-- end autogenerated section -->
This is a description of the component.
Some other content...`;
expect(extractDescription(content)).toBe('This is a description of the component.');
});
it('should return default message when no description is found', () => {
const content = `# Component Name
<!-- status autogenerated section -->
| Status | |
|-------|--|
| Stability | [beta] |
<!-- end autogenerated section -->
## Configuration
Some other content...`;
expect(extractDescription(content)).toBe('No description available');
});
it('should handle description with multiple lines', () => {
const content = `# Component Name
This is a description of the component
that spans multiple lines.
Some other content...`;
expect(extractDescription(content)).toBe('This is a description of the component that spans multiple lines.');
});
it('should handle description with special characters', () => {
const content = `# Component Name
This is a description with special chars: !@#$%^&*()
Some other content...`;
expect(extractDescription(content)).toBe('This is a description with special chars: !@#$%^&*()');
});
});
});