Skip to content
Myr

refactor(helper/streaming): Avoid attaching AbortSignal on newer versions of Bun (#3859)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

* refactor(helper/streaming): Avoid attaching AbortSignal on newer versions of Bun * fixed the tests and refactored ---------

authored by Jarred Sumner · committed by GitHub · parent d40fffb · Browse files · 5 files+53 added−12 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Trailers

  • Co-authored-by: Yusuke Wada <yusuke@kamawada.com>

Diff stats

5 files+53 added−12 removed

  • tests:+20 added−0 removed
  • other:+33 added−12 removed

5 files+53 added−12 removed

modified:src/helper/streaming/sse.test.tsx+5 added
74 unmodified lines
75 expect(aborted).toBeTruthy()76 })7778 it('Check streamSSE Response if aborted by abort signal', async () => {79 // Emulate an old version of Bun (version 1.1.0) for this specific test case80 // @ts-expect-error Bun is not typed81 global.Bun = {82 version: '1.1.0',83 }84 const ac = new AbortController()85 const req = new Request('http://localhost/', { signal: ac.signal })86 const c = new Context(req)87
154 unmodified lines
modified:src/helper/streaming/sse.ts+11 added-6 removed
modified:src/helper/streaming/stream.test.ts+15 added
1import { Context } from '../../context'2import { isOldBunVersion } from './utils'3import { stream } from '.'45describe('Basic Streaming Helper', () => {6 const req = new Request('http://localhost/')
40 unmodified lines
47 expect(aborted).toBeTruthy()48 })4950 it('Check stream Response if aborted by abort signal', async () => {51 // Emulate an old version of Bun (version 1.1.0) for this specific test case52 // @ts-expect-error Bun is not typed53 global.Bun = {54 version: '1.1.0',55 }56 const ac = new AbortController()57 const req = new Request('http://localhost/', { signal: ac.signal })58 const c = new Context(req)59
14 unmodified lines
74 const { value } = await reader.read()75 expect(value).toEqual(new Uint8Array([0]))76 ac.abort()77 expect(aborted).toBeTruthy()78 // @ts-expect-error Bun is not typed79 delete global.Bun80 })8182 it('Check stream Response if pipe is aborted by abort signal', async () => {83 // Emulate an old version of Bun (version 1.1.0) for this specific test case84 // @ts-expect-error Bun is not typed85 global.Bun = {86 version: '1.1.0',87 }88 const ac = new AbortController()89 const req = new Request('http://localhost/', { signal: ac.signal })90 const c = new Context(req)91
11 unmodified lines
103 const pReading = reader.read()104 ac.abort()105 await pReading106 expect(aborted).toBeTruthy()107 // @ts-expect-error Bun is not typed108 delete global.Bun109 })110111 it('Check stream Response if error occurred', async () => {112 const onError = vi.fn()
17 unmodified lines
modified:src/helper/streaming/stream.ts+11 added-6 removed
added:src/helper/streaming/utils.ts+11 added