Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Best way to test handlers without actually deploying #66

Open
pocesar opened this issue Dec 26, 2019 · 5 comments
Open

Best way to test handlers without actually deploying #66

pocesar opened this issue Dec 26, 2019 · 5 comments
Labels

Comments

@pocesar
Copy link
Contributor

pocesar commented Dec 26, 2019

Might be out of the scope of punchcard to provide a cli or a helper library (like @punchcard/test semi serious 馃槂), but it's related to #63, I'm trying to run node debugger, but there are too many spawning processes that make breakpoints useless (node that calls cdk synth that calls ts-node). this is really useful and is akin to serverless-offline.
Another issue with debugging the generated code while on lambda is that there's only X-Ray, and you can't actually get insight of that happening inside scopes and the current call stack, having to change code to spit out console.log statements are icky.

@sam-goodwin
Copy link
Owner

I think the SAM CLI has support for running lambda functions locally and is also integrated with the CDK: https://sanderknape.com/2019/05/building-serverless-applications-aws-cdk/. Perhaps we could try that? Do you want your function to run against live AWS resources or locally mocked?

I test handlers with unit tests by passing in mocked clients for the dependencies:

const table = new DynamoDB.Table(..)
const f = new Lambda.Function(.., { depends: table.readAccess() })
const mockTableClient = ...
const result = await f.handler(event, mockTableClient);

@pocesar
Copy link
Contributor Author

pocesar commented Dec 27, 2019

the SAM CLI looks a good starting point! I'll take a look, as I was thinking more of calling the handler from the command line or even from an adjacent file that can do the wiring on the 'synthesized' bundle. my goal was to help debugging the issues with the generated code, but might come in handy when debugging own code as well.

@sam-goodwin
Copy link
Owner

The generated code should (hopefully) be entirely transparent to the user once its mature. Is it still causing problems?

The Dependency abstraction should allow you to do a bunch of unit testing by calling Function.handle instead of running Lambda in a local container. But as previously mentioned, SAM CLI should already support that. Have you tried it?

@sam-goodwin
Copy link
Owner

Apologies that the struct-overhaul change is taking so long. Punchcard might be broken at the moment due to CDK's updates. Really wish we had a better solution for that ...

@pocesar
Copy link
Contributor Author

pocesar commented Jan 19, 2020

no worries! we are in for the ride, it's expectedly highly iterative 馃憤

the issue was mainly because of that internal webpack error (#57), it wasn't a problem with the handler per-se, nor with the external code (that is testable in isolation). the handler should be slim anyway (ApiGateway.response with your response shape)

and no, it's deploying as expected, just hit the missing CORS headers nag (the APIGW one) unrelated to this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants