Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions runtime-tests/deno/stream.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import { Hono } from '../../src/hono.ts'

Deno.test('Should call onAbort via stream', async () => {
const app = new Hono()
let streamStarted = false
let aborted = false
app.get('/stream', (c) => {
return stream(c, (stream) => {
streamStarted = true
stream.onAbort(() => {
aborted = true
})
Expand All @@ -23,7 +25,9 @@ Deno.test('Should call onAbort via stream', async () => {
})
const res = fetch(req).catch(() => {})
assertEquals(aborted, false)
await new Promise((resolve) => setTimeout(resolve, 10))
while (!streamStarted) {
await new Promise((resolve) => setTimeout(resolve, 10))
}
ac.abort()
await res
while (!aborted) {
Expand Down Expand Up @@ -56,9 +60,11 @@ Deno.test('Should not call onAbort via stream if already closed', async () => {

Deno.test('Should call onAbort via streamSSE', async () => {
const app = new Hono()
let streamStarted = false
let aborted = false
app.get('/stream', (c) => {
return streamSSE(c, (stream) => {
streamStarted = true
stream.onAbort(() => {
aborted = true
})
Expand All @@ -73,10 +79,11 @@ Deno.test('Should call onAbort via streamSSE', async () => {
const req = new Request(`http://localhost:${server.addr.port}/stream`, {
signal: ac.signal,
})
assertEquals
const res = fetch(req).catch(() => {})
assertEquals(aborted, false)
await new Promise((resolve) => setTimeout(resolve, 10))
while (!streamStarted) {
await new Promise((resolve) => setTimeout(resolve, 10))
}
ac.abort()
await res
while (!aborted) {
Expand Down
Loading