Library for testing serverless applications.
npm install --save @dustfoundation/serverless-testingimport{mockAPIGatewayProxyHandler}from'@dustfoundation/serverless-testing';import{expect}from'chai';describe('simple test',()=>{it('GIVEN valid data THEN 201',async()=>{// mockAPIGatewayProxyHandler.execute<T> - T is optional generic that describes response body typeconst{ statusCode, body }=awaitmockAPIGatewayProxyHandler(handler).execute<{users: string[]}>({event: {pathParameters: {field: 'some'},queryStringParameters: {field: 'some'},body: JSON.stringify({field: 'some'}),headers: {field: 'some'},requestContext: {authorizer: {id: 'YourCustomAuthorizerId',groups: ['YourCustomAuthorizerGroup1','YourCustomAuthorizerGroup2'].join(';'),},},},responseToJson: true,});expect(statusCode).eql(201);expect(body.users).lengthOf(5);});});import{mockDDBStreamHandler}from'@dustfoundation/serverless-testing';import{expect}from'chai';describe('simple test',()=>{it('GIVEN valid data THEN success',async()=>{awaitmockDDBStreamHandler(handler).execute({records: [],// DynamoDB Stream Records});// You can test handler with .commandCalls(), etc...});});import{mockSNSHandler}from'@dustfoundation/serverless-testing';import{expect}from'chai';describe('simple test',()=>{it('GIVEN valid data THEN success',async()=>{awaitmockSNSHandler(handler).execute({records: [],// SNS Records});// You can test handler with .commandCalls(), etc...});});import{mockSQSHandler}from'@dustfoundation/serverless-testing';import{expect}from'chai';describe('simple test',()=>{it('GIVEN valid data THEN success',async()=>{awaitmockSQSHandler(handler).execute({records: [],// SQS Records});// You can test handler with .commandCalls(), etc...});});