Skip to content

falsy reason in tests when using serverless AWSLambda.wrapHandler #3133

Closed
@miladr0

Description

@miladr0

I'm writing tests for my lambda function but when I'm using @sentry/serverless and wrap my lambda function with AWSLambda.wrapHandler mocha shows Promise rejected with no or falsy reason.

Sample Lambda function:

const lambdaFn = async (event, context) => {
  context.callbackWaitsForEmptyEventLoop = false
  try {
    return  {
    200,
    body: JSON.stringify(body)
  }
  } catch (error) {
    console.error(error)
    sentry.captureException(error)
    await sentry.flush(2500)
  }
}

exports.actualLambda = lambdaFn
exports.handler = sentry.AWSLambda.wrapHandler(lambdaFn)

Sample test(not working as expected):

  it('status must be 200', async () => {
       const result = await app.handler(null, context)
       expect(result.statusCode).to.equal(200)
  })

But if I directly call exports.actualLambda function test will be passed. like below:
Sample test:

  it('status must be 200', async () => {
       const result = await app.actualLambda(null, context)
       expect(result.statusCode).to.equal(200)
  })

Metadata

Metadata

Assignees

No one assigned

    Labels

    Package: serverlessIssues related to the Sentry Serverless SDK

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions