0.2.0 • Published 5 years ago

lambda-utilities v0.2.0

Weekly downloads
52
License
MIT
Repository
github
Last release
5 years ago

lambda-utilities

Utility functions and type definitions for AWS Lambda

Installation

$ npm isntall lambda-utilities

Usage

Utilities

Callback

Provide mock Callback that implementing interface of SinonExpectation. The argument callback is executed on callsFake.

generateMockCallback: (callback?: Callback) => MockCallback

Context

Provide mock Context. done, fail and succeed are implementing interface of SinonExpectation. If you set a function with parameters, it will be executed on callsFake.

generateMockContext: (params?: GenerateMockContext.Params) => MockContext

export namespace GenerateMockContext {
  export interface Params {
    callbackWaitsForEmptyEventLoop?: boolean
    functionName?: string
    functionVersion?: string
    invokedFunctionArn?: string
    memoryLimitInMB?: number
    awsRequestId?: string
    logGroupName?: string
    logStreamName?: string,
    identity?: CognitoIdentity,

    getRemainingTimeInMillis?: () => number

    done?: (error: any, result: any) => void,
    fail?: (arg0: any) => void,
    succeed?: (arg0: any, arg1?: any) => void
  }
}

InvokeHandler

It is a function that executes the handler of lambda. It can be used in tests in combination with mock.

const handler: Handler<TestEvet, TestCallback> = (event, context, callback) => {
  setTimeout(() => {
    callback(undefined, { foo: event.foo * 2 })
  }, 1000)
}

const callback = generateMockCallback((error, result) => {
  callback.once()
  assert.equal(result.foo, 42)
  assert.ok(callback.verify())
  done()
})

invokeHandler(handler, {
  event: { foo: 21 },
  callback: callback
})
0.2.0

5 years ago

0.1.1

5 years ago

0.1.0

6 years ago

0.0.3

6 years ago

0.0.2

7 years ago

0.0.1

7 years ago