aws-amplify / aws-amplify/docs
Amplify Gen2 documentation for testing setup (vitest)
- Dominant language
- MDX
- Stars
- 506
- Forks
- 1.1k
- Avg merge
- 3h 14m
- Merged PRs (30d)
- 1
Description
**Is your feature request related to a problem? Please describe.**
There is no clear example on how configure testing environment, if should us node or jsdom, if it is need runWithAmplifyContext...
**Describe the solution you'd like**
An example of setup.ts file that provides auth, client, storage to be used in test framework like vitest
**Describe alternatives you've considered**
some LLM instructions to share with AI agent and let it build the setup files. Also a direction on how to setup would be helpful, like emulating ssr context, or configure to use jsdom environment...
**Additional context**
Vitest supports different environments ('node', 'jsdom', 'happy-dom'). When using standard library functions (not the one coming from 'aws-amplify/auth/server' or 'aws-amplify/api/server') the identiy is not availble in the resolver context.
```json
{
"logType": "RequestFunctionEvaluation",
"path": [
"getMyProfile"
],
"fieldName": "getMyProfile",
"resolverArn": "..."
"functionName": "Fn_Query_getMyProfile_1",
"requestId": "1c8bb2e0-1ebf-4a19-b391-5298585a9f16",
"context": {
"arguments": {},
"prev": {
"result": {}
},
"stash": {
"amplifyApiEnvironmentName": "NONE",
"awsAppsyncApiId": "...."
},
"outErrors": []
},
"fieldInError": true,
"errors": [
"Not Authorized to access getMyProfile on type Query"
],
"parentType": "Query",
....
}
```
Using the others and runWithAmplifyContext is not so clear (no cookies in test environment)
Contributor guide
Assessment
This issue has not been assessed yet.