← tests

sse

Server-sent events: a text/event-stream response written event by event through the framework's own support for it.

Comparable across every framework. A framework with no support of its own writes the events by hand, and says so in its README. The events carry stream.ndjson's rows, so the difference from it is the event framing.

testheftrequestbasewhat differs from the base
sse.medium3GET /sse/mediumstream.ndjsonthe rows sent as server-sent events through the framework's own support for them, instead of as lines

sse.medium

heft 3

base stream.ndjson

items.medium's 89 rows, each the data of one server-sent event. The request carries the Accept header an EventSource sends. Every event is of type message with no id, and there is no Content-Length. Read against stream.ndjson, the difference is the framework's event framing against a line per row.

Request

GET /sse/medium
accepttext/event-stream

No body.

Expected response

HTTP 200
content-typematches /^text\/event-stream/
content-lengthis absent

payload items.medium, one row per event

data: {"id":1,"name":"slate-lamp-6647","category":"tools","priceCents":18928,"inStock":true}

data: {"id":2,"name":"brass-hinge-5716","category":"garden","priceCents":17577,"inStock":true}

data: {"id":3,"name":"linen-ring-6971","category":"kitchen","priceCents":5540,"inStock":true}

data: {"id":4,"name":"copper-bolt-9217","category":"outdoor","priceCents":11562,"inStock":true}

data: {"id":5,"name":"linen-lamp-8288","category":"office","priceCents":1413,"inStock":true}

data: {"id":6,"name":"copper-pan-9308","category":"tools","priceCents":10795,"inStock":true}

data: {"id":7,"name":"slate-seed-3051","category":"garden","priceCents":9667,"inStock":false}

data: {"id":8,"name":"oak-lamp-8662
… 8,538 bytes total

Compared event by event as an EventSource dispatches them: each of type message with no id, and its data as parsed JSON.

Test source, tests/sse/medium.ts
tests/sse/medium.tsopen on GitHub →
import { performanceTest } from "#kit";
import { sse } from "#payloads";

const path = "/sse/medium";

export default performanceTest({
  id: { family: "sse", name: "medium" },
  path,
  base: "stream.ndjson",
  varies: "event_stream",
  heft: 3,
  about:
    "items.medium's 89 rows, each the data of one server-sent event. The request " +
    "carries the Accept header an EventSource sends. Every event is of type " +
    "message with no id, and there is no Content-Length. Read against " +
    "stream.ndjson, the difference is the framework's event framing against a " +
    "line per row.",

  request: (c) =>
    c
      .get(path)
      .header("accept", "text/event-stream")
      .okWith(sse)
      .hasHeader("content-type", /^text\/event-stream/)
      .noHeader("content-length"),
});