Hello all, any recommendations for reference that ...
# guide
t
Hello all, any recommendations for reference that expands the testing page of the guide? I was hoping for neat SSTesque ways to 1. test lambdas that use AWS resources (e.g. unit test CRUD persistence) 2. test end-points (e.g. integration test CRUD persistence)
a
I use JEST for both. Unit tests mock out everything to test only the compilation unit (module, in Javascript). Integration tests are separate; they populate test data in the cloud and use the APIs via node-fetch.
t
Thanks. The pointers are useful, I can imagine what it might take.
I guess the deeper question is whether there’s any guidance / trickery in having e.g. a testing stage deployed whose data can be manipulated for testing.
Anyone’s pointers or practices on testing welcome =]
f
I’ve seen many teams follow the PR workflow, ie. 1 stage per PR. You can use jest, cypress, whatever u r familiar with to run tests against it.
And when the PR is merged, u can
sst remove
the stage.
We explain the workflow in a bit more details here on Seed’s doc https://seed.run/docs/working-with-pull-requests.html
The same idea can be applied to other CI services, with some setup.
t
Thanks. Reading the best practices section got me to a similar place, where it says –
You want to configure your CI/CD pipeline to automatically bring these stages up, test against them, and tear them down once you are done.
So good to see that seed has that built-in.
I still think there’s a good piece missing on testing from what is otherwise a stunningly comprehensive guide (and I say that genuinely). Testing data persistence is kinda the bedrock of the server-side things I’ve done before (coming to this as a generalist, e.g. some Django, some Node+Mongo).
j
Would be nice if we could run unit tests for other languages inside SEED. I use Golang lambdas and Typescript CDK. Currently a Makefile inside a Github action but would prefer to use SEED
f
@Toby Harris yeah it’s an area we are thinking a lot about this and have some plans to improve the testing experience for SST. Actually just chatted w/ @thdxr about this earlier today.
Testing data persistence
Do you mean testing somethign and then verifying the change in DB? Can you elaborate on that a bit more?
@Joe Kendal if you are using the General Purpose build images, it comes with Golang preinstalled. You can run custom test scripts inside the before_build hook to test the Golang lambdas. Let me know if that works for you.
t
@Frank Yes. Take the most vanilla Lambda, say https://serverless-stack.com/chapters/add-an-api-to-get-a-note.html, and the guide doesn’t actually give any path to test it. In the monolithic back-end work I’ve done before, there’s lots of calling the route handlers and then inspecting the db. For handlers that use remote APIs, I see the general trend of mocking. But a) it strikes me that the automation of SST deploy means mocking is less necessary and b) there’s no pointer either way in the guide. It’s an untested API, pretty much.
Generally I have the feeling the best testing strategy for something like the app in your guide might be to unit test all the business functions and then actually test the lambdas by hitting the API – closer to an integration test, but with the tooling to set up temporary URL, test data etc.
But really, I’m new to this world, so just flagging that testing as a general topic in the guide is underserved compared to everything else. Props for such a good guide.