-
Notifications
You must be signed in to change notification settings - Fork 64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Local testing for functions using hs functions test command #389
Conversation
|
This is fixed, needed to send the |
…ed cms-lib version
…cess.env values to be available in entire function code context
…ough passed options
….2.2 version for @hubspot/cli-lib
…o formatLogHeader
Description and Context
Allows local testing of serverless functions using
hs functions test <localDotFunctionsFolderPath>
command. This runs an express server on port5432
(or can be specified with--port=<port>
) that will host the endpoints configured withinserverless.json
of the specified .functions folder. By default the specified .functions folder is watched for changes, which will restart the server.The endpoints can be hit(
localhost:5432/_hcms/api/myEndpoint
) to execute the function and the context passed into the function will mimic the data shape/properties that are used in production. The output from the function will be logged to the console. CORS has been disabled on the local server, which allows pointing to the local endpoint from a DesignManger module to test the functionality.This library can also be used for an external project. For example...
The
limits
andcontact
property values are using mocked data, which can be modified using.env
file variables.Notes
.env
file can be included in the local .functions folder to mimic secretsenvironment
config object can be added at both the root level and at the function level inserverless.json
(function level overwrites root)headers
,params
,body
(fromPOST
s),secrets
,accountId
,limits
(mocked), andcontact
(mocked) get passed into the serverless execution contextconsole.log
s within the function will be caught and added to output.env
file--contact=false
option when running the command--watch=false
optionTODO
package.json
content so we don't keep a copy in this repoWho to Notify
@williamspiro @gcorne @bkrainer