Skip to content
Myr

stream-mock.ts

This file

Path

runtime-tests/lambda/stream-mock.ts

43 lines · 1.3 KiB · TypeScript

Last changed by

Not known.

History of this file

Take it

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

Revert "fix(etag): fallback if `res.clone()` is not supported (#4198)" (#4200)Yusuke Wadabefore adoption4a1dd5f

lines 1–43why, 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) => {19 const chunks = []20 const mockWritableStream = new Writable({21 write(chunk, encoding, callback) {22 chunks.push(chunk)23 callback()24 },25 })26 mockWritableStream.chunks = chunks27 await handlerFunc(event, mockWritableStream, context)28 mockWritableStream.end()29 return mockWritableStream30 }31}3233const awslambda = {34 streamifyResponse: mockStreamifyResponse,35 HttpResponseStream: {36 from: (stream: Writable, httpResponseMetadata: unknown): Writable => {37 stream.write(Buffer.from(JSON.stringify(httpResponseMetadata)))38 return stream39 },40 },41}4243vi.stubGlobal('awslambda', awslambda)