Files
portal/tools/registry-render.test.mjs
T
Дмитрий 8706e21db7 test(registry): 5 unit-тестов для replaceRegion (этап 1, task 7)
Покрытие: replacement, preservation границ, ошибки на пропавших маркерах,
multi-line content.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-23 14:31:34 +03:00

35 lines
1.3 KiB
JavaScript

// tools/registry-render.test.mjs
import { describe, it, expect } from 'vitest';
import { replaceRegion } from './registry-render.mjs';
describe('registry-render', () => {
it('replaces auto-region between markers', () => {
const input = `Header\n<!-- auto:foo:begin -->\nold content\n<!-- auto:foo:end -->\nFooter`;
const out = replaceRegion(input, 'foo', 'NEW CONTENT');
expect(out).toContain('NEW CONTENT');
expect(out).not.toContain('old content');
expect(out).toContain('Header');
expect(out).toContain('Footer');
});
it('preserves end marker exactly', () => {
const input = `<!-- auto:foo:begin -->\nold\n<!-- auto:foo:end -->`;
const out = replaceRegion(input, 'foo', 'new');
expect(out).toMatch(/<!-- auto:foo:end -->$/);
});
it('throws if markers missing', () => {
expect(() => replaceRegion('no markers here', 'foo', 'x')).toThrow(/Markers.*not found/);
});
it('throws if only begin marker present', () => {
expect(() => replaceRegion('<!-- auto:foo:begin -->\nstuff', 'foo', 'x')).toThrow();
});
it('handles multi-line rendered content', () => {
const input = `<!-- auto:foo:begin -->\n<!-- auto:foo:end -->`;
const out = replaceRegion(input, 'foo', 'line1\nline2\nline3');
expect(out).toMatch(/line1\nline2\nline3/);
});
});