Skip to content
Myr

mock.ts

This file

Path

runtime_tests/lambda/mock.ts

42 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 8addfd4 point at it.

chore: upgrading vitest to v1.0 (#1830)watanybefore adoption8addfd4

lines 1–42why, one step back
1import { vi } from 'vitest'
2import type {3 APIGatewayProxyEvent,4 APIGatewayProxyEventV2,5 LambdaFunctionUrlEvent,6} from '../../src/adapter/aws-lambda/handler'7import type { LambdaContext } from '../../src/adapter/aws-lambda/types'89type StreamifyResponseHandler = (10 handlerFunc: (11 event: APIGatewayProxyEvent | APIGatewayProxyEventV2 | LambdaFunctionUrlEvent,12 responseStream: NodeJS.WritableStream,13 context: LambdaContext14 ) => Promise<void>15) => (event: APIGatewayProxyEvent, context: LambdaContext) => Promise<NodeJS.WritableStream>1617const mockStreamifyResponse: StreamifyResponseHandler = (handlerFunc) => {18 return async (event, context) => {19 const mockWritableStream: NodeJS.WritableStream = new (require('stream').Writable)({20 write(chunk, encoding, callback) {21 console.log('Writing chunk:', chunk.toString())22 callback()23 },24 final(callback) {25 console.log('Finalizing stream.')26 callback()27 },28 })29 mockWritableStream.on('finish', () => {30 console.log('Stream has finished')31 })32 await handlerFunc(event, mockWritableStream, context)33 mockWritableStream.end()34 return mockWritableStream35 }36}3738const awslambda = {39 streamifyResponse: mockStreamifyResponse,40}4142vi.stubGlobal('awslambda', awslambda)