Skip to content
Myr

text.test.ts

This file

Path

src/helper/streaming/text.test.ts

34 lines · 969 bytes · TypeScript

Last changed by

chore: let oxfmt sort imports instead of eslint (#5442)Yusuke Wadabefore adoption859e2c2

History of this file

Take it

The walk stopped after 200 commits: lines older than f0b094d point at it.

Merge commit from forkYusuke Wadabefore adoptionf0b094d

line 1why, one step back
1import { streamText } from '.'

chore: let oxfmt sort imports instead of eslint (#5442)Yusuke Wadabefore adoption859e2c2

line 2why, one step back
2import { Context } from '../../context'

Merge commit from forkYusuke Wadabefore adoptionf0b094d

lines 3–34why, one step back
3
4describe('Text Streaming Helper', () => {5 const req = new Request('http://localhost/')6 let c: Context7 beforeEach(() => {8 c = new Context(req)9 })1011 it('Check streamText Response', async () => {12 const res = streamText(c, async (stream) => {13 for (let i = 0; i < 3; i++) {14 await stream.write(`${i}`)15 await stream.sleep(1)16 }17 })1819 expect(res.status).toBe(200)20 expect(res.headers.get('content-type')).toMatch(/^text\/plain/)21 expect(res.headers.get('x-content-type-options')).toBe('nosniff')22 expect(res.headers.get('transfer-encoding')).toBe('chunked')2324 if (!res.body) {25 throw new Error('Body is null')26 }27 const reader = res.body.getReader()28 const decoder = new TextDecoder()29 for (let i = 0; i < 3; i++) {30 const { value } = await reader.read()31 expect(decoder.decode(value)).toEqual(`${i}`)32 }33 })34})