hitspec can test Server-Sent Events (SSE) endpoints. SSE is a standard for servers to push real-time updates to clients over a single HTTP connection.
When hitspec detects a text/event-stream Content-Type in a response, it automatically parses the SSE events and makes them available in the test results. Events are shown in verbose console output and returned in JSON/API results.
Basic Usage
Connect to an SSE endpoint and assert on the events received:
How It Works
- hitspec sends the HTTP request normally (the
Accept: text/event-stream header is set by your test file).
- The server responds with
Content-Type: text/event-stream and a body containing SSE-formatted events.
- hitspec detects the content type and parses the response body into structured events.
- Each event has optional
id, type, and data fields per the SSE specification.
- Parsed events appear in verbose output and in the JSON/API result under
sseEvents.
Configuration
Control how long hitspec listens for events using the @timeout directive:
Verbose Output
Run with --verbose to see parsed SSE events in the console:
Multi-line Data
SSE events with multiple data: lines are joined with newlines, per the SSE specification:
A server response like:
Produces a single event with data equal to "line one\nline two\nline three". Last modified on February 10, 2026