Is anybody doing e2e test of SST apps?
# sst
a
Is anybody doing e2e test of SST apps?
f
Something like Selenium tests?
a
Well, I want to test e2e… like API integrations, DB integrations, external services, etc.
f
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
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
I am also using cypress
k
we have been using https://testcafe.io/ for e2e
a
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
Yeah, Jest will do it. You can write any code you want and then assert on the results
f
@Ross Coundon just curious, do u reset the db before each test?
r
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
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
For my e2e tests I reset the db before each test
r
I don't have anything public, I'm afraid. For an integration test, you're typically not mocking those services,
a
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
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
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
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
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
Yup, you can setup a Post-Deploy Phase to run ur integration test https://seed.run/docs/adding-a-post-deploy-phase.html
a
Ok, and in that point I can hit REAL services, right?
The ones that were created on the BUILD step.
f
Yup, I’d like to think about integration tests as something u run after u deploy.
a
Yeah that.
Ok going to give it a try.
Thanks guys for the brainstorming.