Ross Coundon
11/03/2021, 11:07 AMRoss Coundon
11/03/2021, 11:31 AMSeth Geoghegan
11/03/2021, 12:52 PMthdxr
11/03/2021, 1:37 PMRoss Coundon
11/03/2021, 1:46 PMsst test --config jest.config.js
I get the error
argv.config.match is not a function
Ross Coundon
11/03/2021, 1:48 PMsst start
is running. I can't picture how this can be done right nowRoss Coundon
11/03/2021, 3:44 PMthdxr
11/03/2021, 3:50 PMsst test
- it's a layer of abstraction that's useful for people for basic projects but is unnecessary if you're doing more advanced things.
In terms of running tests against a running sst start
- there's not really anything sst specific here. You'd write tests that hit certain API endpoints and set that with a variable you pass inthdxr
11/03/2021, 3:51 PMRoss Coundon
11/03/2021, 3:56 PMthdxr
11/03/2021, 3:58 PMRoss Coundon
11/03/2021, 4:00 PMthdxr
11/03/2021, 4:01 PMRoss Coundon
11/03/2021, 4:05 PMRoss Coundon
11/03/2021, 4:05 PMRoss Coundon
11/03/2021, 4:05 PMSeth Geoghegan
11/03/2021, 4:14 PMconst myApiEndpoint = "<https://bgrsbgy.execute-api.us-east-1.amazonaws.com>"
const request = require('supertest')(myApiEndpoint)
describe('/foobar'), () => {
it('should do a thing',() => {
const response = <http://request.post|request.post>('/foobar')
assert(response.body).toHaveProperty('theThing','...')
}
}
Seth Geoghegan
11/03/2021, 4:15 PMthdxr
11/03/2021, 4:17 PMsst start
2. Environment is bootstrapped and values like the bus name are stored in SSM with something like /stagename/BUS_NAME
3. Run jest
with an env variable like SSM_PREFIX=/stagename/
4. The test will read the bus from ssm and then send an event to it.
5. I guess then it can sleep for some time then look for the dynamodb write - again by using SSM to lookup the table namethdxr
11/03/2021, 4:18 PMthdxr
11/03/2021, 4:19 PMthdxr
11/03/2021, 4:19 PMRoss Coundon
11/03/2021, 4:19 PMthdxr
11/03/2021, 4:20 PMRoss Coundon
11/03/2021, 4:23 PMthdxr
11/03/2021, 4:24 PMLinks.found()
function that gets triggered once I see a link in a slack message
export async function found(detail: FoundEvent["detail"]) {
const evt: FoundEvent = {
source: "tempest",
type: "link.found",
detail,
}
await Bus.publish(evt)
}
This is calling Bus.publish(evt)
which is a wrapper around EventBridge to publish an event to my app's event bus:
export function publish(...events: Event[]) {
return bus
.putEvents({
Entries: events.map((item) => ({
EventBusName: Config.BUS_NAME,
Detail: JSON.stringify(item.detail),
Source: item.source,
DetailType: item.type,
})),
})
.promise()
}
This is loading the Bus name from Config.BUS_NAME
which is loaded on app boot from SSM. This is really ugly code because I use deasync
can ignore the datails - it just does a scan on SSM for `/stage/*`:
Then jest only needs one environment variable passed which is the stage namethdxr
11/03/2021, 4:24 PMRoss Coundon
11/03/2021, 4:25 PMRoss Coundon
11/03/2021, 4:25 PMthdxr
11/03/2021, 4:26 PMthis.addSSM
option. And then maybe even provide a simple library for loading them into memory in jsSeth Geoghegan
11/03/2021, 4:57 PMSeth Geoghegan
11/03/2021, 4:57 PMSeth Geoghegan
11/03/2021, 4:58 PMthdxr
11/03/2021, 5:05 PMRoss Coundon
11/03/2021, 5:07 PMSeth Geoghegan
11/03/2021, 7:19 PMthdxr
11/03/2021, 7:41 PMRoss Coundon
11/03/2021, 7:47 PMSeth Geoghegan
11/03/2021, 7:50 PMSeth Geoghegan
11/03/2021, 7:53 PMthdxr
11/03/2021, 7:56 PMRoss Coundon
11/03/2021, 8:01 PMSeth Geoghegan
11/03/2021, 8:04 PMSeth Geoghegan
11/03/2021, 8:05 PM