www/src/content/docs/blog/testing-in-sst.mdx
import { YouTube } from '@astro-community/astro-embed-youtube';
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.
$ sst load-config -- vitest run
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.
"test": "sst load-config -- vitest run"
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:
We hosted a launch livestream on YouTube where we talked about how to write tests for your SST apps.
<YouTube id="YtaxDURRjHA" posterQuality="high" />The video is timestamped and here's roughly what we covered.
sst load-configTo get started, create a new SST app with our GraphQL starter.
$ npx create-sst@latest
Make sure to select the graphql and DynamoDB option.
Next, install the dependencies.
$ cd my-sst-app
$ npm install
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.
$ npm run deploy
And you can run your tests by running:
npm test
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.