Skip to content
Myr

stream-mock.ts

This file

Path

runtime-tests/lambda/stream-mock.ts

44 lines · 1.3 KiB · TypeScript

Last changed by

chore(builld): tsconfig project references (#4797)Jonathan Hainesbefore adoptiond69deb8

History of this file

Take it

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

4.9.0Yusuke Wadabefore adoption82bdc4d

lines 1–18why, one step back
1import { vi } from 'vitest'
2import { Writable } from 'node:stream'3import type {4 APIGatewayProxyEvent,5 APIGatewayProxyEventV2,6} from '../../src/adapter/aws-lambda/handler'7import type { LambdaContext } from '../../src/adapter/aws-lambda/types'89type StreamifyResponseHandler = (10 handlerFunc: (11 event: APIGatewayProxyEvent | APIGatewayProxyEventV2,12 responseStream: Writable,13 context: LambdaContext14 ) => Promise<void>15) => (event: APIGatewayProxyEvent, context: LambdaContext) => Promise<NodeJS.WritableStream>1617const mockStreamifyResponse: StreamifyResponseHandler = (handlerFunc) => {18 return async (event, context) => {

chore(builld): tsconfig project references (#4797)Jonathan Hainesbefore adoptiond69deb8

line 19why, one step back
19 const chunks: unknown[] = []

4.9.0Yusuke Wadabefore adoption82bdc4d

line 20why, one step back
20 const mockWritableStream = new Writable({

chore(eslint): upgrade `@hono/eslint-config` (#4781)Jonathan Hainesbefore adoption5d59ac7

line 21why, one step back
21 write(chunk, _encoding, callback) {

4.9.0Yusuke Wadabefore adoption82bdc4d

lines 22–25why, one step back
22 chunks.push(chunk)
23 callback()24 },25 })

chore(builld): tsconfig project references (#4797)Jonathan Hainesbefore adoptiond69deb8

line 26why, one step back
26 // @ts-expect-error chunks property for testing

4.9.0Yusuke Wadabefore adoption82bdc4d

lines 27–44why, one step back
27 mockWritableStream.chunks = chunks
28 await handlerFunc(event, mockWritableStream, context)29 mockWritableStream.end()30 return mockWritableStream31 }32}3334const awslambda = {35 streamifyResponse: mockStreamifyResponse,36 HttpResponseStream: {37 from: (stream: Writable, httpResponseMetadata: unknown): Writable => {38 stream.write(Buffer.from(JSON.stringify(httpResponseMetadata)))39 return stream40 },41 },42}4344vi.stubGlobal('awslambda', awslambda)