Amplify Mock Commands
Pre-requisite
Java is required on your development workstation to use Local Mocking in Amplify
Which package is used?#
If you go into the $HOME_DIR/.amplify/plugins.json file (where $HOME_DIR is your home directory), which lists all the plugins available on your system, you might notice the following lines at the end:
This indicates that the amplify-util-mock package is used when we invoke mocking commands.
What commands are available?#
As per the above JSON property, we can infer that the following commands are available for invocation:
Folder Structure#
Details of files and folders#
- amplify-plugin-index.ts
- api
- commands
- func
- mockAll.ts
- storage
The executeAmplifyCommand determines the sub-command and calls the run() function in the appropriate file located in the commands/mock directory.
Files:
api.ts: It exposes a class calledAPITestresponsible for starting the Local AppSync simulator, as well as starting the GraphQL transformer. It also starts a local DynamoDB server which uses SQLite.index.ts: It exposes the globalstart()function which is called whenamplify mock apiis executed.lambda-arn-to-config.ts: Attempts to match an arn object against the array of lambdas configured in the project.run-graphql-transformer.ts: Executes the GraphQL transformer from the$TSContextobject.
This folder exposes a run() for each function which is called by amplify mock <command>.
Files:
api.ts: Foramplify mock apifucntion.ts: Foramplify mock function <functionName>help.ts: Foramplify mock helpmock.ts: Foramplify mockstorage.ts: Foramplify mock storage
The file exposes the start() function which is responsible to mock Lambda functions locally. It uses the package amplify-category-function in order to execute operations.
The function mockAllCategories() first searches for all the locally available resources which can be mocked and then executes each mocking utility to mock each mockable resource.
Files:
index.ts: It exposes thestart()function which is called whenamplify mock storageis executed.storage.ts: It exposes a class calledStorageTestwhich is responsible for mocking S3 resources and start a mock storage server.