-
-
Notifications
You must be signed in to change notification settings - Fork 816
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(url-loader): handle SSE ping event for Readable
- Loading branch information
Showing
8 changed files
with
80 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { handleEventStreamResponse } from '../src/event-stream/handleEventStreamResponse'; | ||
import { TextEncoder } from 'util'; | ||
|
||
describe('handleEventStreamResponse', () => { | ||
describe('ReadableStream', () => { | ||
if (parseInt(process.versions.node.split('.')[0]) < 16) { | ||
it('dummy', () => { }); | ||
} | ||
const { TransformStream } = require('stream/web'); | ||
it('should handle an event with data', async () => { | ||
const { readable, writable } = new TransformStream(); | ||
const encoder = new TextEncoder(); | ||
const stream = writable.getWriter(); | ||
|
||
const generator = await handleEventStreamResponse(readable); | ||
|
||
// stream.write(encoder.encode(':\n\n')); | ||
stream.write(encoder.encode('event: complete\n')); | ||
stream.write(encoder.encode('data: { "foo": "bar" }\n')); | ||
stream.write(encoder.encode('\n')); | ||
|
||
expect((await generator.next()).value).toMatchInlineSnapshot(` | ||
Object { | ||
"foo": "bar", | ||
} | ||
`); | ||
}); | ||
|
||
it('should ignore server pings', async () => { | ||
const { readable, writable } = new TransformStream(); | ||
const encoder = new TextEncoder(); | ||
const stream = writable.getWriter(); | ||
|
||
const readStream = async () => { | ||
const generator = await handleEventStreamResponse(readable); | ||
|
||
stream.write(encoder.encode(':\n\n')); | ||
stream.write(encoder.encode('event: next\n')); | ||
stream.write(encoder.encode('data: { "foo": "bar" }\n\n')); | ||
|
||
return generator.next(); | ||
}; | ||
|
||
await expect(await readStream()).resolves.toMatchInlineSnapshot(` | ||
Object { | ||
"done": false, | ||
"value": Object { | ||
"foo": "bar", | ||
}, | ||
} | ||
`); | ||
}); | ||
}); | ||
|
||
}) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2f1eb45
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs: