26 lines
720 B
TypeScript
26 lines
720 B
TypeScript
import { SseSerializer } from '../src/index.js';
|
|
|
|
describe('SseSerializer', () => {
|
|
it('formats SSE events', () => {
|
|
const serializer = new SseSerializer();
|
|
const event = serializer.event('job:completed', {
|
|
type: 'job:completed',
|
|
jobId: 'job-1',
|
|
timestamp: '2026-01-01T00:00:00.000Z',
|
|
});
|
|
|
|
expect(event).toContain('event: job:completed');
|
|
expect(event).toContain('"jobId":"job-1"');
|
|
expect(event.endsWith('\n\n')).toBe(true);
|
|
});
|
|
|
|
it('returns SSE headers', () => {
|
|
expect(SseSerializer.headers()).toEqual({
|
|
'Content-Type': 'text/event-stream',
|
|
'Cache-Control': 'no-cache',
|
|
Connection: 'keep-alive',
|
|
'X-Accel-Buffering': 'no',
|
|
});
|
|
});
|
|
});
|