I see `vitest` is the test runner bundled in the s...
# sst
p
I see
vitest
is the test runner bundled in the starter templates. Is that what most of you are using? It’s the first I’ve heard of this framework, having mainly used Jest. Looking at the docs it looks the same API as Jest. Any gotchas to be aware of if switching to this from Jest?
t
Nope they made it work pretty well out of the box for people used to jest. It's way faster too!
p
Excellent! Just setting up an E2E test with it for my REST API…
working out the --outputFile approach to get a handle on the ApiUrl.
t
Yeah that's the approach right now but we have a new sst.Parameter thing coming up which will work without that
p
is it possible for the deployments from
sst start
triggered by hitting Enter to write their outputs to a file that I can read from my tests? Or does it have to explicitly go through the
sst deploy
command?
I kinda like not having to do the round trip to look up SST params every test run
t
It should be doing that, is it not?
You need to restart sst start for outputs to update?
p
will restart and check…
t
I've actually never used this feature haha
p
haha. Serverless Framework had an export-env plugin that I always use for this.
t
our new idea is to introduce sst.Parameter which saves values in SSM. You can attach them to functions and it'll autoload them on start. And then for tests we just load all of the ones in your whole app before running
It'll also codegen types so you get auto complete, a rough prototype is here https://github.com/serverless-stack/serverless-stack/blob/master/examples/parameter-prototype/stacks/MyStack.ts
p
that’s nice if it will autoload them for you as I’ve always ended up building
ssm-helper
util type modules for this
NICE on the types
p
so is this available now?
the
'@serverless-stack/node/config'
module I mean
t
It's technically published but we haven't released it yet, there's some design choices we need to make but I'm hoping this comes out in a month or so
you could use it though
p
so this Parameter module isn’t yet part of the framework libraries, I would need to include it in my own code if I want to get the codegen today, is that right?
t
Yeah and the other awkward thing is Parameter.use(func, ...)
When it's integrated functions will accept a list of parameters directly
p
ok. I might just leave it for now and just parse the outputs.json file
is there a way in my test runner I can get a handle on the current stage? Like is there a helper function in sst that reads the current stage (I think this is stored in the
.sst/stage
file) ?
I guess I could just read that file, just trying to save a few lines of code 😄
t
yeah we're in a weird middle phase because I'm working on rethinking our approach with testing using Parameter but I also ran into the same need, was just manually passing it as an env param when I ran the test command. But now that I think of it you could probably do
Copy code
import { State } from "@serverless-stack/core"

State.getStage(process.cwd())
p
got it working. Just reading stack config like so:
Copy code
const readStackConfig = () => {
  const stackOutputs = JSON.parse(
    readFileSync(join(__dirname, '../../../../stacks/stack-outputs.json')).toString()
  )
  const stackName = `${State.getStage(process.cwd())}-sst-twitter-exporter-MyStack`
  return stackOutputs[stackName]
}
btw, vitest seems very fast. No big pause at the start like with Jest
t
nice! yeah and jest was also a nightmare to configure with esm
y
Damn Vitest is really great, setting it up took a second and it’s so fast! Somethings that annoyed me about Jest are fixed or configurable in Vitest. Happy that I saw this thread 🙌