mirror of
https://github.com/stackblitz-labs/bolt.diy
synced 2025-01-22 10:55:34 +00:00
49 lines
1.6 KiB
TypeScript
49 lines
1.6 KiB
TypeScript
import { describe, expect, it } from 'vitest';
|
|
import { stripCodeFenceFromArtifact } from './Markdown';
|
|
|
|
describe('stripCodeFenceFromArtifact', () => {
|
|
it('should remove code fences around artifact element', () => {
|
|
const input = "```xml\n<div class='__boltArtifact__'></div>\n```";
|
|
const expected = "\n<div class='__boltArtifact__'></div>\n";
|
|
expect(stripCodeFenceFromArtifact(input)).toBe(expected);
|
|
});
|
|
|
|
it('should handle code fence with language specification', () => {
|
|
const input = "```typescript\n<div class='__boltArtifact__'></div>\n```";
|
|
const expected = "\n<div class='__boltArtifact__'></div>\n";
|
|
expect(stripCodeFenceFromArtifact(input)).toBe(expected);
|
|
});
|
|
|
|
it('should not modify content without artifacts', () => {
|
|
const input = '```\nregular code block\n```';
|
|
expect(stripCodeFenceFromArtifact(input)).toBe(input);
|
|
});
|
|
|
|
it('should handle empty input', () => {
|
|
expect(stripCodeFenceFromArtifact('')).toBe('');
|
|
});
|
|
|
|
it('should handle artifact without code fences', () => {
|
|
const input = "<div class='__boltArtifact__'></div>";
|
|
expect(stripCodeFenceFromArtifact(input)).toBe(input);
|
|
});
|
|
|
|
it('should handle multiple artifacts but only remove fences around them', () => {
|
|
const input = [
|
|
'Some text',
|
|
'```typescript',
|
|
"<div class='__boltArtifact__'></div>",
|
|
'```',
|
|
'```',
|
|
'regular code',
|
|
'```',
|
|
].join('\n');
|
|
|
|
const expected = ['Some text', '', "<div class='__boltArtifact__'></div>", '', '```', 'regular code', '```'].join(
|
|
'\n',
|
|
);
|
|
|
|
expect(stripCodeFenceFromArtifact(input)).toBe(expected);
|
|
});
|
|
});
|