Skip to content

Instantly share code, notes, and snippets.

@FloStar3000
Created November 11, 2020 13:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FloStar3000/0e2c953f1a54e9147d7e203cbeb156b1 to your computer and use it in GitHub Desktop.
Save FloStar3000/0e2c953f1a54e9147d7e203cbeb156b1 to your computer and use it in GitHub Desktop.
Serverless Framework: Easy shortcut to test a function with event JSON
Normally, you would test a serverless function like this:
serverless invoke local -f methodName --path path/to/event.json
Shortcut:
1. All event files must be in the same folder (e.g. mocks-folder/) and named like this: [methodname].json
2. In package.json, add script: "test":"serverless invoke local -f $method --path mocks-path/$method.json"
3. Test a function with: method=functionName npm run test
You can adapt this for remote testing:
- "test-remote":"serverless invoke -f $method --path mocks-path/$method.json"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment