Skip to content

Amplify Gen2 documentation for testing setup (vitest) #8476

@sot1986

Description

@sot1986

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.

{
    "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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions