https://serverless-stack.com/ logo
#sst
Title
# sst
a

Adrián Mouly

07/05/2021, 9:03 PM
Is anybody doing e2e test of SST apps?
f

Frank

07/05/2021, 9:32 PM
Something like Selenium tests?
a

Adrián Mouly

07/05/2021, 9:50 PM
Well, I want to test e2e… like API integrations, DB integrations, external services, etc.
f

Frank

07/05/2021, 10:52 PM
Right right! We have selenium to run browser tests.. nothing SST specific there.
As for integration tests, I’ve seen ppl use jest to curl and expect on the API response. And have some script to cleanup and setup the DB data.
Anything specific you are thinking about?
r

Ross Coundon

07/06/2021, 6:21 AM
Cypress is worth a look for e2e, particularly when it's a browser app. For other tests, such as integration, we use Jest. If you need something for calling API endpoints, you could look into Postman and its test runner and Newman
t

thdxr

07/06/2021, 2:02 PM
I am also using cypress
k

Karo

07/06/2021, 3:17 PM
we have been using https://testcafe.io/ for e2e
a

Adrián Mouly

07/06/2021, 5:25 PM
With Jest I can call HTTP too?
I don’t want to test the FE.
But I want to have e2e test of the API layer.
That means aws services + http layer + database.
That’s why Im saying e2e, I’m using NestJS on other projects and that’s how it’s called.
But the FE is not tested as part of the e2e.. it’s more like an integration test.
r

Ross Coundon

07/06/2021, 5:28 PM
Yeah, Jest will do it. You can write any code you want and then assert on the results
f

Frank

07/06/2021, 5:30 PM
@Ross Coundon just curious, do u reset the db before each test?
r

Ross Coundon

07/06/2021, 5:31 PM
For unit testing, each test is idempotent. For e2e we do this too, sometimes though it makes more sense to make each suite of tests idempotent, rather than each individual test
a

Adrián Mouly

07/06/2021, 5:32 PM
Yes, I want to do fresh tests with clean DB… but maybe with some seed data, like user profiles, etc.
Can somebody share with me an example project doing this?
I don’t know how I would test SQS integrations for example.
Should I mock those services with Jest?
t

thdxr

07/06/2021, 5:33 PM
For my e2e tests I reset the db before each test
r

Ross Coundon

07/06/2021, 5:33 PM
I don't have anything public, I'm afraid. For an integration test, you're typically not mocking those services,
a

Adrián Mouly

07/06/2021, 5:34 PM
And how it works?
I mean I need to execute an API that drops a message on SQS… then a second lambda should be triggered.
It’s part of the entire flow of my API.. it has some sync/async procedures.
How should I test this?
Same with EventBridge, or other services.
r

Ross Coundon

07/06/2021, 5:35 PM
Well, when you've deployed with SST, all those services actually exist
so when you trigger your API, the cascade of events should start and you can check the results
a

Adrián Mouly

07/06/2021, 5:37 PM
I know, when it’s deployed there are real services running… but I’m not doing deployments, I’m running tests on my CI/CD platform, bitbucket.
So how I test my integrations every time I want? I need to deploy all every time? on each PR?
t

thdxr

07/06/2021, 5:38 PM
Yeah that's one of the nice things about serverless, a "deployment" isn't super heavy. Easy to spin up and tear down. For my tests I deploy it every time and run my tests against the deployed infra, then spin it down
I tend not to write a lot of unit tests for that reason, prefer doing mostly integration tests
a

Adrián Mouly

07/06/2021, 5:38 PM
Ok yes, I totally agree, makes sense @thdxr.
Now looking on how should I do it, haha.
I mean, I’m also using SEED, and started to use SST… maybe my integration test should run on SEED? @Frank
f

Frank

07/06/2021, 5:41 PM
Yup, you can setup a Post-Deploy Phase to run ur integration test https://seed.run/docs/adding-a-post-deploy-phase.html
a

Adrián Mouly

07/06/2021, 5:41 PM
Ok, and in that point I can hit REAL services, right?
The ones that were created on the BUILD step.
f

Frank

07/06/2021, 5:42 PM
Yup, I’d like to think about integration tests as something u run after u deploy.
a

Adrián Mouly

07/06/2021, 5:42 PM
Yeah that.
Ok going to give it a try.
Thanks guys for the brainstorming.