clone

a browser-first diagram editor with live svg previews, local drafts and encrypted, accountless sharing

main
diagramzip / renderers / edge / test / svgbob.test.ts
svgbob.test.ts 2.6K
1import { describe, expect, it } from 'vitest'2import { svgbobAdapter } from '../src/adapters/svgbob'3import type { RenderRequest } from '../src/runtime/types'45const request = (source: string, options: Record<string, string> = {}): RenderRequest => ({6 engine: 'svgbob', source, format: 'svg', options,7 metadata: { title: '', description: '' },8 presentation: { background: '', padding: 0, frame: false },9})10const cloud = ` .-,( ),-.11 ___ _ .-( )-.12 [___]|=| -->( ) __________13 /::/ |_| '-( ).-' --->[_...__... ]14 '-.( ).-'15 \\ ____ __16 '--->| | |==|17 |____| | |18 /::::/ |__|`1920describe('Svgbob edge-Wasm adapter', () => {21 it('renders ASCII source without trimming its leading whitespace', async () => {22 const result = await svgbobAdapter.render(request(' +---+\n | A |\n +---+'), new AbortController().signal)23 expect(result.runtime).toBe('edge-wasm')24 expect(result.body).toContain('<svg')25 expect(result.body).toContain('A')26 })2728 it('maps the six Kroki settings to the pure library API', async () => {29 const result = await svgbobAdapter.render(request('A -> B', {30 background: '#f3f3f3', 'fill-color': '#123456', 'font-family': 'monospace',31 'font-size': '18', scale: '2', 'stroke-width': '3',32 }), new AbortController().signal)33 expect(result.body).toContain('#f3f3f3')34 expect(result.body).toContain('#123456')35 expect(result.body).toContain('font-size: 18px')36 })3738 it('keeps upstream cloud fixture dimensions at 400x160 and scales to 600x240', async () => {39 const defaultResult = await svgbobAdapter.render(request(cloud), new AbortController().signal)40 const scaledResult = await svgbobAdapter.render(request(cloud, { scale: '1.5' }), new AbortController().signal)41 expect(defaultResult.body).toMatch(/<svg[^>]*width="400"[^>]*height="160"/)42 expect(scaledResult.body).toMatch(/<svg[^>]*width="600"[^>]*height="240"/)43 })4445 it('rejects unknown, invalid, and oversized input before Wasm', async () => {46 await expect(svgbobAdapter.render(request('A', { 'stroke-color': 'red' }), new AbortController().signal)).rejects.toMatchObject({ status: 400, code: 'unsupported_options' })47 await expect(svgbobAdapter.render(request('A', { scale: 'NaN' }), new AbortController().signal)).rejects.toMatchObject({ status: 400, code: 'invalid_options' })48 await expect(svgbobAdapter.render(request('é'.repeat(140_000)), new AbortController().signal)).rejects.toMatchObject({ status: 413, code: 'source_too_large' })49 })50})