0

Is it a good idea to run integration tests on my CI using serverless offline?

I am on AWS and I want to test the Lambda <-> SQS integration.

My Lambda reads from an API Gateway, which I know is emulated on the serverless offline.

const JEST_SLS_OFFLINE_URL = localhost:3000 // Default sls offline url

describe('Version endpoint ', () => {
  const fetchUser = async () => {
    const url = `${String(JEST_SLS_OFFLINE_URL)}/user/123`
  }
  test('Should fetchUser', async () => {
    expect(await fetchUser()).toBe('')
  })
})

An alternative is to spin up a new servererless function on AWS (for every PR), which is quite resource consuming

user1398619
  • 696
  • 7
  • 8

1 Answers1

0

I don't think this is a right or wrong answer - people kinda create their preferences with this but imo yes it's fine. It's what I do for integration tests. I also spinup a docker with DynamoDb. For SQS however you're going to have to emulate that - For integration tests I spin up a simple server and mock the calls/response - I do this for SQS,SNS,Cognito and a few other things that are either not available in serverless offline or do not provide the type of testing framework I desire. You can check out one of my answers on mocking Cognito - the same process applies to every AWS service which is very handy.

cyberwombat
  • 38,105
  • 35
  • 175
  • 251