CI (Gitea Actions), request hardening (body-size limit -> 413, server timeouts), graceful shutdown (app.close drains streams + connections), and per-route subgraph slicing (routes run only their needed providers/steps; observer plugin steps run unconditionally). TLS/CORS/validation and mesh-side slicing deferred to RC. Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
This commit is contained in:
9 files changed
+243
-20
No files matched your search
@@ -0,0 +1,18 @@
|
||||
name: CI
|
||||
on:
|
||||
push:
|
||||
branches: [develop, main]
|
||||
pull_request:
|
||||
branches: [develop, main]
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: '18'
|
||||
- run: npm ci
|
||||
- run: npm run typecheck
|
||||
- run: npm test
|
||||
- run: npm run build
|
||||
@@ -68,8 +68,18 @@ class ApiModule {}
|
||||
const app = createApp({ modules: [ApiModule] });
|
||||
await app.listen(3000);
|
||||
// GET /api/users/9 (header x-token) → { "requested": "9", "you": { "id": "...", "name": "Diego" } }
|
||||
|
||||
await app.close(); // graceful shutdown: drains in-flight requests, closes streams + mesh links
|
||||
```
|
||||
|
||||
> **Per-route execution (important).** Each route runs **only the providers/steps in the transitive
|
||||
> closure of its handler's `@needs`** — nothing else. A route that doesn't `@needs('user')` does **not**
|
||||
> run the `Authenticate` step. This means a cross-cutting *enforcement* step (e.g. auth that throws 401)
|
||||
> only protects routes that actually `@needs` its token. To run something on **every** route regardless
|
||||
> of needs (logging, audit, a global guard), add it as a **plugin step** via `scope.add({ ..., provides: [] })` —
|
||||
> steps that produce nothing run unconditionally. Don't rely on a token-providing step to guard routes
|
||||
> that don't declare it.
|
||||
|
||||
### Argument decorators
|
||||
|
||||
| Decorator | Reads from | Adds a graph dependency? |
|
||||
|
||||
+24
-7
@@ -1,9 +1,9 @@
|
||||
import http from 'http';
|
||||
import { Bus } from './bus';
|
||||
import { Container } from './container';
|
||||
import { topoSort, GraphNode } from './graph';
|
||||
import { topoSort, subgraphFor, GraphNode } from './graph';
|
||||
import { runPipeline, PipelineStep } from './pipeline';
|
||||
import { createHttpServer, parseQuery, RouteDef, WsRouteDef } from './http';
|
||||
import { createHttpServer, parseQuery, RouteDef, WsRouteDef, RequestLimits } from './http';
|
||||
import { isAsyncIterable } from './channel';
|
||||
import { JsonTransformer } from './transformers';
|
||||
import { mountPlugin, Plugin, ScopeApi, ScopeNode } from './plugin';
|
||||
@@ -20,6 +20,7 @@ import type { RequestEnvelope, RouteEntry } from './mesh/protocol';
|
||||
export interface InspectLine { name: string; kind: 'provider' | 'step' | 'handler'; origin: string }
|
||||
export interface App {
|
||||
listen(port: number): Promise<http.Server>;
|
||||
close(): Promise<void>;
|
||||
inspect(routePath: string): InspectLine[];
|
||||
bus: Bus;
|
||||
}
|
||||
@@ -43,9 +44,11 @@ export interface MeshConfig {
|
||||
timeoutMs?: number;
|
||||
}
|
||||
|
||||
export function createApp(opts: { modules: Ctor[]; plugins?: Plugin[]; mesh?: MeshConfig }): App {
|
||||
export function createApp(opts: { modules: Ctor[]; plugins?: Plugin[]; mesh?: MeshConfig; limits?: RequestLimits }): App {
|
||||
const bus = new Bus();
|
||||
const container = new Container();
|
||||
let server: http.Server | undefined;
|
||||
const streams = new Set<() => void>();
|
||||
const extraSteps: ScopeNode[] = [];
|
||||
const scope: ScopeApi = { add: (n) => extraSteps.push(n) };
|
||||
|
||||
@@ -126,7 +129,14 @@ export function createApp(opts: { modules: Ctor[]; plugins?: Plugin[]; mesh?: Me
|
||||
const ordered = topoSort([...providerNodes, ...stepNodes], ['req', 'params']);
|
||||
orderedProviders = ordered.filter((n) => providerNodes.includes(n));
|
||||
orderedSteps = ordered.filter((n) => stepNodes.includes(n));
|
||||
for (const plan of routePlans) { plan.providers = orderedProviders; plan.steps = orderedSteps; }
|
||||
const alwaysSteps = stepNodes.filter((n) => n.provides.length === 0); // side-effect/observer steps (plugins)
|
||||
const alwaysNeeds = alwaysSteps.flatMap((n) => n.needs); // pull observers' deps into every route
|
||||
for (const plan of routePlans) {
|
||||
const closure = subgraphFor([...plan.needs, ...alwaysNeeds], ordered);
|
||||
plan.providers = closure.filter((n) => providerNodes.includes(n));
|
||||
const sliced = new Set<GraphNode>([...closure.filter((n) => stepNodes.includes(n)), ...alwaysSteps]);
|
||||
plan.steps = ordered.filter((n) => stepNodes.includes(n) && sliced.has(n)); // topo order, deduped
|
||||
}
|
||||
|
||||
const producedKeys = new Set<string>([
|
||||
...providerNodes.flatMap((n) => n.provides),
|
||||
@@ -279,13 +289,20 @@ export function createApp(opts: { modules: Ctor[]; plugins?: Plugin[]; mesh?: Me
|
||||
},
|
||||
}));
|
||||
|
||||
const server = createHttpServer(httpRoutes, wsRoutes, bus, meshControl);
|
||||
server = createHttpServer(httpRoutes, wsRoutes, bus, meshControl, { limits: opts.limits, streams });
|
||||
server.on('close', () => { for (const l of meshLinks) { try { l.close(); } catch { /* */ } } });
|
||||
await new Promise<void>((resolve) => server.listen(port, resolve));
|
||||
await new Promise<void>((resolve) => server!.listen(port, resolve));
|
||||
return server;
|
||||
};
|
||||
|
||||
return { listen, inspect, bus };
|
||||
const close = (): Promise<void> => new Promise<void>((resolve) => {
|
||||
if (!server) return resolve();
|
||||
server.close(() => resolve()); // waits for in-flight buffered to drain
|
||||
for (const closeStream of streams) closeStream(); // force-close long-lived SSE/WS so close() resolves
|
||||
server.closeIdleConnections(); // Node >=18.2: drop idle keep-alive
|
||||
});
|
||||
|
||||
return { listen, close, inspect, bus };
|
||||
}
|
||||
|
||||
async function snapshot(c: Container, needs: string[]): Promise<Record<string, unknown>> {
|
||||
|
||||
@@ -37,3 +37,18 @@ export function topoSort(nodes: GraphNode[], seedKeys: string[]): GraphNode[] {
|
||||
for (const n of nodes) visit(n, []);
|
||||
return ordered;
|
||||
}
|
||||
|
||||
export function subgraphFor(needs: string[], ordered: GraphNode[]): GraphNode[] {
|
||||
const producedBy = new Map<string, GraphNode>();
|
||||
for (const n of ordered) for (const k of n.provides) producedBy.set(k, n);
|
||||
const inClosure = new Set<GraphNode>();
|
||||
const work = [...needs];
|
||||
while (work.length) {
|
||||
const token = work.pop() as string;
|
||||
const node = producedBy.get(token);
|
||||
if (!node || inClosure.has(node)) continue; // no producer = seed/envelope; already-seen = skip
|
||||
inClosure.add(node);
|
||||
work.push(...node.needs);
|
||||
}
|
||||
return ordered.filter((n) => inClosure.has(n));
|
||||
}
|
||||
+40
-11
@@ -2,11 +2,20 @@ import http from 'http';
|
||||
import { once } from 'events';
|
||||
import { channel } from './channel';
|
||||
import { errorToResponse } from './transformers';
|
||||
import { HttpError } from './signals';
|
||||
import { sseEncoder, ndjsonEncoder, StreamEncoder } from './encoders';
|
||||
import { isStreamResult, type PipelineResult, type ResponseShape } from './pipeline';
|
||||
import type { Transport } from './metadata';
|
||||
import type { Bus } from './bus';
|
||||
|
||||
export interface RequestLimits {
|
||||
maxBodyBytes?: number; // default 1_000_000
|
||||
requestTimeoutMs?: number; // default 30_000
|
||||
headersTimeoutMs?: number; // default 10_000
|
||||
keepAliveTimeoutMs?: number; // default 5_000
|
||||
}
|
||||
export interface HttpOptions { limits?: RequestLimits; streams?: Set<() => void> }
|
||||
|
||||
export type RouteHandler = (req: {
|
||||
method: string; url: string;
|
||||
headers: Record<string, string | string[] | undefined>;
|
||||
@@ -58,9 +67,14 @@ export function parseQuery(url: string): Record<string, string> {
|
||||
return out;
|
||||
}
|
||||
|
||||
async function readBody(req: http.IncomingMessage): Promise<string | undefined> {
|
||||
async function readBody(req: http.IncomingMessage, maxBodyBytes: number): Promise<string | undefined> {
|
||||
const chunks: Buffer[] = [];
|
||||
for await (const chunk of req) chunks.push(chunk as Buffer);
|
||||
let total = 0;
|
||||
for await (const chunk of req) {
|
||||
total += (chunk as Buffer).length;
|
||||
if (total > maxBodyBytes) throw new HttpError(413, 'Payload Too Large');
|
||||
chunks.push(chunk as Buffer);
|
||||
}
|
||||
if (chunks.length === 0) return undefined;
|
||||
const raw = Buffer.concat(chunks).toString('utf8');
|
||||
return raw === '' ? undefined : raw;
|
||||
@@ -74,7 +88,7 @@ function pickEncoder(transport: Transport, accept: string): StreamEncoder {
|
||||
|
||||
async function pipeStream(
|
||||
res: http.ServerResponse, stream: AsyncIterable<unknown>, encoder: StreamEncoder,
|
||||
bus?: Bus, name = '',
|
||||
bus?: Bus, name = '', streams?: Set<() => void>,
|
||||
): Promise<void> {
|
||||
res.writeHead(200, encoder.headers);
|
||||
bus?.emit('stream:open', { name });
|
||||
@@ -83,6 +97,8 @@ async function pipeStream(
|
||||
if (encoder.ping) { ping = setInterval(() => res.write(encoder.ping!()), PING_MS); ping.unref?.(); }
|
||||
const stop = () => { if (ping) clearInterval(ping); void Promise.resolve(it.return?.()).catch(() => {}); };
|
||||
res.on('close', stop);
|
||||
const closer = () => { try { res.destroy(); } catch { /* */ } };
|
||||
streams?.add(closer);
|
||||
const onClose = once(res, 'close');
|
||||
try {
|
||||
while (true) {
|
||||
@@ -99,6 +115,7 @@ async function pipeStream(
|
||||
if (frame && !res.writableEnded) res.write(frame);
|
||||
} finally {
|
||||
if (ping) clearInterval(ping);
|
||||
streams?.delete(closer);
|
||||
if (!res.writableEnded && !res.destroyed) res.end();
|
||||
bus?.emit('stream:close', { name });
|
||||
}
|
||||
@@ -108,7 +125,9 @@ function loadWss(): any | null {
|
||||
try { return require('ws').WebSocketServer; } catch { return null; }
|
||||
}
|
||||
|
||||
function attachWs(server: http.Server, wsRoutes: WsRouteDef[], bus?: Bus, meshControl?: MeshControl): void {
|
||||
function attachWs(
|
||||
server: http.Server, wsRoutes: WsRouteDef[], bus?: Bus, meshControl?: MeshControl, streams?: Set<() => void>,
|
||||
): void {
|
||||
if (wsRoutes.length === 0 && !meshControl) return;
|
||||
const WSS = loadWss();
|
||||
const wss = WSS ? new WSS({ noServer: true }) : null;
|
||||
@@ -123,6 +142,9 @@ function attachWs(server: http.Server, wsRoutes: WsRouteDef[], bus?: Bus, meshCo
|
||||
if (!route) { socket.destroy(); return; }
|
||||
if (!wss) { socket.write('HTTP/1.1 501 Not Implemented\r\n\r\n'); socket.destroy(); return; }
|
||||
wss.handleUpgrade(req, socket, head, async (ws: any) => {
|
||||
const closer = () => { try { (ws.terminate ?? ws.close).call(ws); } catch { /* */ } };
|
||||
streams?.add(closer);
|
||||
ws.on('close', () => streams?.delete(closer));
|
||||
const inbound = channel<unknown>();
|
||||
const ac = new AbortController();
|
||||
ws.on('message', (d: Buffer) => inbound.push(d.toString()));
|
||||
@@ -154,7 +176,10 @@ function attachWs(server: http.Server, wsRoutes: WsRouteDef[], bus?: Bus, meshCo
|
||||
});
|
||||
}
|
||||
|
||||
export function createHttpServer(routes: RouteDef[], wsRoutes: WsRouteDef[] = [], bus?: Bus, meshControl?: MeshControl): http.Server {
|
||||
export function createHttpServer(
|
||||
routes: RouteDef[], wsRoutes: WsRouteDef[] = [], bus?: Bus, meshControl?: MeshControl, opts?: HttpOptions,
|
||||
): http.Server {
|
||||
const maxBody = opts?.limits?.maxBodyBytes ?? 1_000_000;
|
||||
const server = http.createServer(async (req, res) => {
|
||||
const url = req.url ?? '/';
|
||||
const path = url.split('?')[0];
|
||||
@@ -166,10 +191,11 @@ export function createHttpServer(routes: RouteDef[], wsRoutes: WsRouteDef[] = []
|
||||
}
|
||||
let raw: string | undefined;
|
||||
try {
|
||||
raw = await readBody(req);
|
||||
} catch {
|
||||
res.writeHead(500, { 'content-type': 'application/json' });
|
||||
res.end(JSON.stringify({ error: 'Internal Server Error' }));
|
||||
raw = await readBody(req, maxBody);
|
||||
} catch (error) {
|
||||
const r = errorToResponse(error);
|
||||
res.writeHead(r.status, { ...r.headers, connection: 'close' });
|
||||
res.end(r.body);
|
||||
return;
|
||||
}
|
||||
let body: unknown = raw;
|
||||
@@ -193,13 +219,16 @@ export function createHttpServer(routes: RouteDef[], wsRoutes: WsRouteDef[] = []
|
||||
}
|
||||
if (isStreamResult(result)) {
|
||||
const encoder = pickEncoder(matched.def.transport, String(req.headers.accept ?? ''));
|
||||
await pipeStream(res, result.stream, encoder, bus, matched.def.pattern);
|
||||
await pipeStream(res, result.stream, encoder, bus, matched.def.pattern, opts?.streams);
|
||||
return;
|
||||
}
|
||||
const r: ResponseShape = result;
|
||||
res.writeHead(r.status, r.headers);
|
||||
res.end(r.body);
|
||||
});
|
||||
attachWs(server, wsRoutes, bus, meshControl);
|
||||
server.requestTimeout = opts?.limits?.requestTimeoutMs ?? 30_000;
|
||||
server.headersTimeout = opts?.limits?.headersTimeoutMs ?? 10_000;
|
||||
server.keepAliveTimeout = opts?.limits?.keepAliveTimeoutMs ?? 5_000;
|
||||
attachWs(server, wsRoutes, bus, meshControl, opts?.streams);
|
||||
return server;
|
||||
}
|
||||
@@ -20,6 +20,7 @@ export { inbound, abort } from './params';
|
||||
export { sseEncoder, ndjsonEncoder } from './encoders';
|
||||
export type { StreamEncoder } from './encoders';
|
||||
export type { MeshConfig } from './app';
|
||||
export type { RequestLimits } from './http';
|
||||
export { connectLink } from './mesh/link';
|
||||
export { buildRemote, envelopeFrom } from './mesh/teacup';
|
||||
export { buildManifest, createMeshControl, MESH_CONTROL_PATH } from './mesh/teapot';
|
||||
|
||||
@@ -153,3 +153,77 @@ describe('app streaming wiring', () => {
|
||||
client.close(); server.close();
|
||||
});
|
||||
});
|
||||
|
||||
describe('per-route subgraph slicing', () => {
|
||||
it('a route that does not @needs a step does not run it', async () => {
|
||||
const ran: string[] = [];
|
||||
@Step({ provides: 'tracked', needs: [] })
|
||||
class Tracked { run() { ran.push('tracked'); return { tracked: true }; } }
|
||||
@Route('/')
|
||||
class Ctl {
|
||||
@Get('/needs') needs(@needs('tracked') t: any) { return { t }; }
|
||||
@Get('/free') free() { return { ok: true }; }
|
||||
}
|
||||
@Module({ mountpoint: '/', steps: [Tracked], controllers: [Ctl] }) class M {}
|
||||
const app = createApp({ modules: [M] });
|
||||
const server = await app.listen(0);
|
||||
const port = (server.address() as any).port;
|
||||
|
||||
await fetch(`http://127.0.0.1:${port}/free`).then((r) => r.json());
|
||||
expect(ran).toEqual([]); // step did NOT run for /free
|
||||
await fetch(`http://127.0.0.1:${port}/needs`).then((r) => r.json());
|
||||
expect(ran).toEqual(['tracked']); // step ran for /needs
|
||||
expect(app.inspect('/free').map((l) => l.kind)).toEqual(['handler']); // no step in the chain
|
||||
server.close();
|
||||
});
|
||||
|
||||
it('a side-effect step (provides: []) added by a plugin runs unconditionally', async () => {
|
||||
// NB: @Step always provides exactly one token (always sliceable). provides:[] only arises via a plugin's scope.add.
|
||||
const ran: string[] = [];
|
||||
const observer = (api: any) => api.scope.add({ kind: 'step', name: 'obs', needs: [], provides: [], run: () => { ran.push('obs'); return {}; } });
|
||||
@Route('/')
|
||||
class Ctl { @Get('/free') free() { return { ok: true }; } }
|
||||
@Module({ mountpoint: '/', controllers: [Ctl] }) class M {}
|
||||
const app = createApp({ modules: [M], plugins: [observer] });
|
||||
const server = await app.listen(0);
|
||||
const port = (server.address() as any).port;
|
||||
await fetch(`http://127.0.0.1:${port}/free`).then((r) => r.json());
|
||||
expect(ran).toEqual(['obs']); // ran despite the route @needs-ing nothing
|
||||
server.close();
|
||||
});
|
||||
|
||||
it('an always-run observer step receives its declared needs even when the route does not need them', async () => {
|
||||
let seen: any;
|
||||
const observer = (api: any) => api.scope.add({ kind: 'step', name: 'audit', needs: ['user'], provides: [], run: (ctx: any) => { seen = ctx.user; return {}; } });
|
||||
@Step({ provides: 'user', needs: [] })
|
||||
class Auth { run() { return { user: { id: 'u1' } }; } }
|
||||
@Route('/')
|
||||
class Ctl { @Get('/free') free() { return { ok: true }; } } // does NOT @needs('user')
|
||||
@Module({ mountpoint: '/', steps: [Auth], controllers: [Ctl] }) class M {}
|
||||
const app = createApp({ modules: [M], plugins: [observer] });
|
||||
const server = await app.listen(0);
|
||||
const port = (server.address() as any).port;
|
||||
await fetch(`http://127.0.0.1:${port}/free`).then((r) => r.json());
|
||||
expect(seen).toEqual({ id: 'u1' }); // observer got user, not undefined
|
||||
server.close();
|
||||
});
|
||||
});
|
||||
|
||||
describe('graceful shutdown', () => {
|
||||
it('app.close() stops accepting and resolves, even with an SSE stream open', async () => {
|
||||
@Route('/')
|
||||
class Ctl { @Sse('/ticks') ticks() { return (async function* () { yield { t: 1 }; await new Promise((r) => setTimeout(r, 1000)); yield { t: 2 }; })(); } }
|
||||
@Module({ mountpoint: '/', controllers: [Ctl] }) class M {}
|
||||
const app = createApp({ modules: [M] });
|
||||
const server = await app.listen(0);
|
||||
const port = (server.address() as any).port;
|
||||
|
||||
const res = await fetch(`http://127.0.0.1:${port}/ticks`, { headers: { accept: 'text/event-stream' } });
|
||||
const reader = res.body!.getReader();
|
||||
await reader.read(); // first event; stream still open
|
||||
|
||||
await app.close(); // must NOT hang despite the open stream
|
||||
await expect(fetch(`http://127.0.0.1:${port}/ticks`).then((r) => r.text())).rejects.toThrow();
|
||||
reader.cancel().catch(() => {});
|
||||
});
|
||||
});
|
||||
+20
-2
@@ -1,5 +1,5 @@
|
||||
import { expect, test } from 'vitest';
|
||||
import { topoSort, GraphNode } from '../src/graph';
|
||||
import { describe, expect, it, test } from 'vitest';
|
||||
import { topoSort, GraphNode, subgraphFor } from '../src/graph';
|
||||
|
||||
const node = (name: string, needs: string[], provides: string[]): GraphNode =>
|
||||
({ name, needs, provides, origin: 'test' });
|
||||
@@ -23,3 +23,21 @@ test('throws on cycle', () => {
|
||||
const nodes = [node('a', ['b'], ['a']), node('b', ['a'], ['b'])];
|
||||
expect(() => topoSort(nodes, [])).toThrow(/cycle detected/);
|
||||
});
|
||||
|
||||
const N = (name: string, needs: string[] = []) => ({ name, needs, provides: [name], origin: 'm' });
|
||||
|
||||
describe('subgraphFor', () => {
|
||||
const ordered = [N('config'), N('db', ['config']), N('user', ['db', 'req']), N('audit', ['db'])];
|
||||
it('returns the transitive closure of needs, in the given order', () => {
|
||||
expect(subgraphFor(['user'], ordered).map((n) => n.name)).toEqual(['config', 'db', 'user']);
|
||||
});
|
||||
it('returns empty for no needs', () => {
|
||||
expect(subgraphFor([], ordered)).toEqual([]);
|
||||
});
|
||||
it('ignores tokens with no producer (seeds/envelope)', () => {
|
||||
expect(subgraphFor(['user', 'query', 'req'], ordered).map((n) => n.name)).toEqual(['config', 'db', 'user']);
|
||||
});
|
||||
it('does not pull in unrelated nodes', () => {
|
||||
expect(subgraphFor(['user'], ordered).map((n) => n.name)).not.toContain('audit');
|
||||
});
|
||||
});
|
||||
@@ -97,3 +97,44 @@ describe('http streaming', () => {
|
||||
server.close();
|
||||
});
|
||||
});
|
||||
|
||||
describe('request hardening', () => {
|
||||
const getUrl = (s: import('http').Server) => `http://127.0.0.1:${(s.address() as any).port}`;
|
||||
|
||||
it('rejects an over-size body with 413 and does not run the handler', async () => {
|
||||
let ran = false;
|
||||
const server = createHttpServer(
|
||||
[{ method: 'POST', pattern: '/echo', transport: 'buffer',
|
||||
handler: async () => { ran = true; return { status: 200, headers: {}, body: 'ok' }; } }],
|
||||
[], undefined, undefined, { limits: { maxBodyBytes: 16 } },
|
||||
);
|
||||
await new Promise<void>((r) => server.listen(0, r));
|
||||
const res = await fetch(`${getUrl(server)}/echo`, { method: 'POST', body: 'x'.repeat(1000) });
|
||||
expect(res.status).toBe(413);
|
||||
expect(ran).toBe(false);
|
||||
server.close();
|
||||
});
|
||||
|
||||
it('sets the configured server timeouts', async () => {
|
||||
const server = createHttpServer([], [], undefined, undefined,
|
||||
{ limits: { requestTimeoutMs: 12345, headersTimeoutMs: 6789, keepAliveTimeoutMs: 4321 } });
|
||||
expect(server.requestTimeout).toBe(12345);
|
||||
expect(server.headersTimeout).toBe(6789);
|
||||
expect(server.keepAliveTimeout).toBe(4321);
|
||||
server.close();
|
||||
});
|
||||
|
||||
it('requestTimeout does NOT kill an in-flight SSE stream (streaming regression)', async () => {
|
||||
async function* feed() { for (let n = 1; n <= 3; n++) { yield { n }; await new Promise((r) => setTimeout(r, 80)); } }
|
||||
const server = createHttpServer(
|
||||
[{ method: 'GET', pattern: '/feed', transport: 'sse', handler: async () => ({ stream: feed() }) }],
|
||||
[], undefined, undefined, { limits: { requestTimeoutMs: 100 } },
|
||||
);
|
||||
await new Promise<void>((r) => server.listen(0, r));
|
||||
const res = await fetch(`${getUrl(server)}/feed`, { headers: { accept: 'text/event-stream' } });
|
||||
const text = await res.text();
|
||||
expect(text).toContain('data: {"n":1}');
|
||||
expect(text).toContain('data: {"n":3}');
|
||||
server.close();
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user