Testing in SST
You can write tests for your SST apps using the new sst load-config
CLI. It auto-loads secrets and config for your tests.
Meaning that it’ll load the Config
of your app, but for your tests.
So for example, this command loads your Config
and runs your tests using Vitest.
Also, make sure to check out our launch announcement for Config
in case you missed it.
We updated the create sst
GraphQL starter to include the updated npm test
script.
We also have a new chapter in our docs dedicated to testing. It includes how to write tests for the different parts of your app:
- Tests for your domain code. Recall that we recommend Domain Driven Design.
- Tests for your APIs, the endpoints handling requests.
- Tests for your stacks, the code that creates your infrastructure.
Launch event
We hosted a launch livestream on YouTube where we talked about how to write tests for your SST apps.
The video is timestamped and here’s roughly what we covered.
- Intro
- Setting up a new app
- Testing domain code
- Testing APIs
- Testing stacks
- Deep dive into
sst load-config
- Q&A
- How to test asynchronous workflow?
- How to run tests in parallel?
Get started
To get started, create a new SST app with our GraphQL starter.
Make sure to select the graphql
and DynamoDB
option.
Next, install the dependencies.
Let’s deploy the app once. This’ll create all the infrastructure for your app and the Config
. Recall that we use AWS SSM to store our secrets and parameters.
And you can run your tests by running:
Make sure to check out the sample test included with the starter to get a sense of how it all works!
To learn more check out our docs.