Unit Testing AWS Infrastructure with Jest
An example of using Jest with Pulumi to write test-driven code that mocks AWS infrastructure.
This example lives in the pulumi/examples repository. Check out just this directory to use it:
git clone --filter=blob:none --sparse https://github.com/pulumi/examples pulumi-examplesgit -C pulumi-examples sparse-checkout set testing-unit-ts-mocks-jestcd pulumi-examples/testing-unit-ts-mocks-jestAn example of using Pulumi with Jest, the JavaScript testing framework, to write in-memory unit tests that mock AWS infrastructure. The program under test deploys a single AWS Lambda function and an associated Lambda Function URL.
Prerequisites#
- Install Pulumi.
- Install Node.js.
- Configure your AWS credentials.
Deploying the App#
-
Clone this repo, change to this directory, then create a new stack for the project:
Terminal window pulumi stack init -
Specify an AWS region to deploy into:
Terminal window pulumi config set aws:region us-west-2 -
Install Node dependencies and run the tests:
Terminal window npm installnpm testIn a few moments, the tests should pass.
-
If you’d like to deploy the program as well, run
pulumi up. In a few moments, theFunctionUrlof thetimeURLLambda will be emitted as a Pulumi stack output calledaudioURL:Terminal window ...Outputs:audioURL: "https://o3vbc73qd2vxrhtaao5v53yeaa0sricr.lambda-url.us-west-2.on.aws/" -
When you’re ready, destroy your stack and remove it:
Terminal window pulumi destroy --yespulumi stack rm --yes