Skip to content

Commit

Permalink
Merge pull request #9000 from thiagomini/hotfix/sse-stream-sink-content
Browse files Browse the repository at this point in the history
fix(sse): stream sink content
  • Loading branch information
kamilmysliwiec authored Feb 14, 2022
2 parents 50a847e + 3dafe28 commit 35090f8
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
2 changes: 1 addition & 1 deletion packages/core/router/sse-stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export class SseStream extends Transform {
destination.flushHeaders();
}

destination.write(':\n');
destination.write('\n');
return super.pipe(destination, options);
}

Expand Down
4 changes: 2 additions & 2 deletions packages/core/test/router/router-response-controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ describe('RouterResponseController', () => {
request.destroy();
await written(response);
expect(response.content).to.eql(
`:
`
id: 1
data: test
Expand Down Expand Up @@ -421,7 +421,7 @@ data: test

await written(response);
expect(response.content).to.eql(
`:
`
event: error
id: 1
data: Some error
Expand Down
14 changes: 11 additions & 3 deletions packages/core/test/router/sse-stream.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ describe('SseStream', () => {
const sse = new SseStream();
const sink = new Sink();
sse.pipe(sink);

sse.writeMessage(
{
data: 'hello\nworld',
Expand All @@ -57,8 +58,9 @@ describe('SseStream', () => {
);
sse.end();
await written(sink);

expect(sink.content).to.equal(
`:
`
id: 1
data: hello
data: world
Expand All @@ -75,6 +77,7 @@ data: monde
const sse = new SseStream();
const sink = new Sink();
sse.pipe(sink);

sse.writeMessage(
{
data: { hello: 'world' },
Expand All @@ -83,8 +86,9 @@ data: monde
);
sse.end();
await written(sink);

expect(sink.content).to.equal(
`:
`
id: 1
data: {"hello":"world"}
Expand All @@ -96,6 +100,7 @@ data: {"hello":"world"}
const sse = new SseStream();
const sink = new Sink();
sse.pipe(sink);

sse.writeMessage(
{
type: 'tea-time',
Expand All @@ -107,8 +112,9 @@ data: {"hello":"world"}
);
sse.end();
await written(sink);

expect(sink.content).to.equal(
`:
`
event: tea-time
id: the-id
retry: 222
Expand Down Expand Up @@ -148,6 +154,7 @@ data: hello
return sink;
},
);

sse.pipe(sink, {
additionalHeaders: { 'access-control-headers': 'some-cors-value' },
});
Expand All @@ -159,6 +166,7 @@ data: hello
sse = new SseStream(req);
sse.pipe(res);
});

server.listen(() => {
const es = new EventSource(
`http://localhost:${(server.address() as AddressInfo).port}`,
Expand Down

0 comments on commit 35090f8

Please sign in to comment.