Skip to content
Myr

stream.test.ts

This file

Path

runtime-tests/lambda/stream.test.ts

75 lines · 2.0 KiB · TypeScript

Last changed by

chore: rename `runtime_tests` to `runtime-tests` (#3419)Yusuke Wadabefore adoptiondfbd717

History of this file

Take it

chore: rename `runtime_tests` to `runtime-tests` (#3419)Yusuke Wadabefore adoptiondfbd717

lines 1–75why, one step back
1import { streamHandle } from '../../src/adapter/aws-lambda/handler'
2import type { LambdaEvent } from '../../src/adapter/aws-lambda/handler'3import type {4 ApiGatewayRequestContext,5 ApiGatewayRequestContextV2,6 LambdaContext,7} from '../../src/adapter/aws-lambda/types'8import { Hono } from '../../src/hono'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)7172 const metadata = JSON.parse(stream.chunks[0].toString())73 expect(metadata.cookies).toEqual(['cookie1=value1', 'cookie2=value2'])74 })75})