mirror of
https://github.com/honojs/hono.git
synced 2024-11-25 13:19:30 +01:00
8b4392fa36
* 0.1 * lint * stream * type safe * ignore * lint * test Node.writablestream * 1.0 * fixed pipeline * fixed
43 lines
1.3 KiB
TypeScript
43 lines
1.3 KiB
TypeScript
import { vi } from 'vitest'
|
|
import type {
|
|
APIGatewayProxyEvent,
|
|
APIGatewayProxyEventV2,
|
|
LambdaFunctionUrlEvent,
|
|
} from '../../src/adapter/aws-lambda/handler'
|
|
import type { LambdaContext } from '../../src/adapter/aws-lambda/types'
|
|
|
|
type StreamifyResponseHandler = (
|
|
handlerFunc: (
|
|
event: APIGatewayProxyEvent | APIGatewayProxyEventV2 | LambdaFunctionUrlEvent,
|
|
responseStream: NodeJS.WritableStream,
|
|
context: LambdaContext
|
|
) => Promise<void>
|
|
) => (event: APIGatewayProxyEvent, context: LambdaContext) => Promise<NodeJS.WritableStream>
|
|
|
|
const mockStreamifyResponse: StreamifyResponseHandler = (handlerFunc) => {
|
|
return async (event, context) => {
|
|
const mockWritableStream: NodeJS.WritableStream = new (require('stream').Writable)({
|
|
write(chunk, encoding, callback) {
|
|
console.log('Writing chunk:', chunk.toString())
|
|
callback()
|
|
},
|
|
final(callback) {
|
|
console.log('Finalizing stream.')
|
|
callback()
|
|
},
|
|
})
|
|
mockWritableStream.on('finish', () => {
|
|
console.log('Stream has finished')
|
|
})
|
|
await handlerFunc(event, mockWritableStream, context)
|
|
mockWritableStream.end()
|
|
return mockWritableStream
|
|
}
|
|
}
|
|
|
|
const awslambda = {
|
|
streamifyResponse: mockStreamifyResponse,
|
|
}
|
|
|
|
vi.stubGlobal('awslambda', awslambda)
|