https://serverless-stack.com/ logo
#sst
Title
# sst
p

Paul Swail

05/20/2022, 11:49 AM
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

thdxr

05/20/2022, 12:02 PM
Nope they made it work pretty well out of the box for people used to jest. It's way faster too!
p

Paul Swail

05/20/2022, 12:02 PM
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

thdxr

05/20/2022, 12:04 PM
Yeah that's the approach right now but we have a new sst.Parameter thing coming up which will work without that
p

Paul Swail

05/20/2022, 12:04 PM
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

thdxr

05/20/2022, 12:05 PM
It should be doing that, is it not?
You need to restart sst start for outputs to update?
p

Paul Swail

05/20/2022, 12:06 PM
will restart and check…
t

thdxr

05/20/2022, 12:07 PM
I've actually never used this feature haha
p

Paul Swail

05/20/2022, 12:07 PM
haha. Serverless Framework had an export-env plugin that I always use for this.
t

thdxr

05/20/2022, 12:10 PM
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

Paul Swail

05/20/2022, 12:11 PM
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

Paul Swail

05/20/2022, 12:12 PM
so is this available now?
the
'@serverless-stack/node/config'
module I mean
t

thdxr

05/20/2022, 12:13 PM
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

Paul Swail

05/20/2022, 12:20 PM
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

thdxr

05/20/2022, 12:21 PM
Yeah and the other awkward thing is Parameter.use(func, ...)
When it's integrated functions will accept a list of parameters directly
p

Paul Swail

05/20/2022, 12:24 PM
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

thdxr

05/20/2022, 12:29 PM
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

Paul Swail

05/20/2022, 12:48 PM
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

thdxr

05/20/2022, 12:51 PM
nice! yeah and jest was also a nightmare to configure with esm
y

Younes El Attar

05/30/2022, 10:47 PM
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 🙌