stream.test.ts
This file
Path
adapters/aws-lambda/test/stream.test.ts
75 lines · 1.9 KiB · TypeScript
Last changed by
test: move adapter runtime tests into `adapters/*` (#5466)Yusuke Wadabefore adoption645ddd6
History of this fileTake it
test: move adapter runtime tests into `adapters/*` (#5466)Yusuke Wadabefore adoption645ddd6
lines 1–75why, one step back1import { Hono } from 'hono'2import { streamHandle } from '../src/handler'3import type { LambdaEvent } from '../src/handler'4import type {5 ApiGatewayRequestContext,6 ApiGatewayRequestContextV2,7 LambdaContext,8} from '../src/types'9import './stream-mock'1011type Bindings = {12 event: LambdaEvent13 lambdaContext: LambdaContext14 requestContext: ApiGatewayRequestContext | ApiGatewayRequestContextV215}1617const testApiGatewayRequestContextV2 = {18 accountId: '123456789012',19 apiId: 'urlid',20 authentication: null,21 authorizer: {22 iam: {23 accessKey: 'AKIA...',24 accountId: '111122223333',25 callerId: 'AIDA...',26 cognitoIdentity: null,27 principalOrgId: null,28 userArn: 'arn:aws:iam::111122223333:user/example-user',29 userId: 'AIDA...',30 },31 },32 domainName: 'example.com',33 domainPrefix: '<url-id>',34 http: {35 method: 'GET',36 path: '/my/path',37 protocol: 'HTTP/1.1',38 sourceIp: '123.123.123.123',39 userAgent: 'agent',40 },41 requestId: 'id',42 routeKey: '$default',43 stage: '$default',44 time: '12/Mar/2020:19:03:58 +0000',45 timeEpoch: 1583348638390,46 customProperty: 'customValue',47}4849describe('streamHandle function', () => {50 const app = new Hono<{ Bindings: Bindings }>()5152 app.get('/cookies', async (c) => {53 c.res.headers.append('Set-Cookie', 'cookie1=value1')54 c.res.headers.append('Set-Cookie', 'cookie2=value2')55 return c.text('Cookies Set')56 })5758 const handler = streamHandle(app)5960 it('to write multiple cookies into the headers', async () => {61 const event = {62 headers: { 'content-type': 'text/plain' },63 rawPath: '/cookies',64 rawQueryString: '',65 body: null,66 isBase64Encoded: false,67 requestContext: testApiGatewayRequestContextV2,68 }6970 const stream = await handler(event, {} as LambdaContext, vi.fn())7172 const metadata = JSON.parse(stream.chunks[0].toString())73 expect(metadata.cookies).toEqual(['cookie1=value1', 'cookie2=value2'])74 })75})