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:

  • 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.

  1. Intro
  2. Setting up a new app
  3. Testing domain code
  4. Testing APIs
  5. Testing stacks
  6. Deep dive into sst load-config
  7. Q&A
    1. How to test asynchronous workflow?
    2. How to run tests in parallel?

Get started

To 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.