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

Not known.

History of this file

Take it

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

fix(ssg): add `atom+xml` and `rss+xml` to `defaultExtensionMap` (#4899)Yuinbefore adoption8f027e5

lines 1–44why, 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: unknown[] = []20 const mockWritableStream = new Writable({21 write(chunk, _encoding, callback) {22 chunks.push(chunk)23 callback()24 },25 })26 // @ts-expect-error chunks property for testing27 mockWritableStream.chunks = chunks28 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)