I’m having trouble running `npx sst test` against ...
# help
a
I’m having trouble running
npx sst test
against a non-default stage (something other than dev). I’ve tried
npx sst test --stage stageName
which the documentation seems to indicate should work, but I just get an error that the Jest CLI doesn’t support that option. What am I missing?
f
Oh I’m seeing this as well.
a
Thanks, I’ll keep an eye on the issue!
m
I looked at this issue from the roadmap. It errors out because we pass the
stage
variable to jest and the jest cli doesn't expect a
stage
variable. @Austin You probably want to mock whatever values you feel would change between stages and not rely on live data for your tests. Do you have a specific use-case you'd like to share? If there's no unique case, we want to remove the stage option from the test command so we don't encourage this testing anti-pattern @Frank. Might need a new issue to track that.
a
Not really a specific use case. In my case it isn’t even a direct dependency. My stack is reading some config from a (stage specific) json file. I can get around it for this. I am curious what would be the appropriate pattern for testing stage-specific logic in stacks. In an ideal case infrastructure is identical in all environments, but in practice, this is not always true and there are inevitably differences between production and non-production stacks for certain systems. What is the most appropriate way to cover both cases with tests?
m
If they have different behaviors (they sound like they do) then they should be split into different modules/repos according to their concerns and not different stages like prod and dev. Those can be tested individually. Otherwise things get very hard to maintain down the line. It's a convention thing that's definitely workable but shouldn't be done. I feel that's partly why tools like jest don't provide a comparable
stage
option in their cli.