aws / aws-cdk

The AWS Cloud Development Kit is a framework for defining cloud infrastructure in code
https://aws.amazon.com/cdk
Apache License 2.0
11.61k stars 3.9k forks source link

(docs): nodejs-function, document how to disable bundling for tests #12844

Open nbaillie opened 3 years ago

nbaillie commented 3 years ago

Create an option to disable, (or automatically disable?) asset build/bundling, when using Jest to instantiate a cdk-pipeline for tests

Use Case

When using a pipeline instance in jest it causes the assets to build/bundle, it may be the intention of the test to check only that the pipeline is correctly formed, build/bundle testing may be handled else where. In this case the build/bundle process creates additional time delay on testing in synth stage of the pipeline.

Proposed Solution

Create an option to disable, (or automatically disable?) asset build/bundling, when using Jest to instantiate a cdk-pipeline for tests

Other


This is a :rocket: Feature Request

rix0rrr commented 3 years ago

I believe there's an context value you can set to stop bundling (or more accurately, pick the stacks for which you want to enable bundling, which in your case would be none):

https://github.com/aws/aws-cdk/blob/6de792c3453cec17a9c4b0fca47477d69e5ed36e/packages/%40aws-cdk/core/lib/asset-staging.ts#L163

https://github.com/aws/aws-cdk/blob/c84217f94cf66cae800d434350b3b3d7676a03b3/packages/%40aws-cdk/cx-api/lib/app.ts#L45

rix0rrr commented 3 years ago

I'm assuming you're using NodeJSFunction or PythonFunction in your pipeline...

nbaillie commented 3 years ago

Thanks for the info above, I think this will help.

Yes using NodeJSFunction but another use case would be with s3-deploy.

anthonygerrard commented 2 years ago

I have a project which uses s3deployment bundling. I tried setting this context attribute in its tests but it led to build failures.

bracki commented 2 years ago

@rix0rrr Can you clarify what exactly needs to be done to disable this? I tried to do this programatically, but it seems the context variable can't be set at runtime? Do I need a separate cdk.json just for testing? That seems unfortunate.

bracki commented 2 years ago

https://github.com/aws/aws-cdk/issues/18125 has some answers. https://github.com/aws/aws-cdk/issues/18125#issuecomment-1099392204