@horietakehiro/aws-cdk-utul 0.2.2 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,14 +1,88 @@
1
- # Welcome to your CDK TypeScript project
1
+ # AWS CDK Unit Test Utility Library
2
2
 
3
- This is a blank project for CDK development with TypeScript.
3
+ <p align="left">
4
+ <a href="https://www.npmjs.com/package/@horietakehiro/aws-cdk-utul?activeTab=readme" >
5
+ <img alt="NPM Version" src="https://img.shields.io/npm/v/%40horietakehiro%2Faws-cdk-utul">
6
+ </a>
7
+ </p>
4
8
 
5
- The `cdk.json` file tells the CDK Toolkit how to execute your app.
9
+ **aws-cdk-utul(unit test utility library) makes it faster, more efficient, and less mistaken for you to code AWS CDK unit tests.**
6
10
 
7
- ## Useful commands
11
+ ---
8
12
 
9
- * `npm run build` compile typescript to js
10
- * `npm run watch` watch for changes and compile
11
- * `npm run test` perform the jest unit tests
12
- * `npx cdk deploy` deploy this stack to your default AWS account/region
13
- * `npx cdk diff` compare deployed stack with current state
14
- * `npx cdk synth` emits the synthesized CloudFormation template
13
+ ## Features
14
+
15
+ ---
16
+
17
+ ### TypedTemplate
18
+
19
+ When you code AWS CDK unit tests in some IDE(e.g. VSCode), `TypedTemplate` class provides you a type hinting and type validation for (alomost) all AWS CloudFormation resource types.
20
+
21
+ ![type-hinting-1](./docs/type-hinting-1.png)
22
+
23
+ The key concepts are:
24
+ - You can define unit tests for your AWS CloudFormation templates by using well-type-defined methods via `TypedTemplate` class - a proxy for original `Template` class.
25
+ - Returned values from methods of `TypedTemplate` are also well-type-defined.
26
+ - You can still use `Matcher` and other arbitrary objects too.
27
+
28
+ So you can quickly code AWS CDK unit tests without any trivial mistakes and googling.
29
+ ```js
30
+ import { Stack } from "aws-cdk-lib";
31
+ import { Template } from "aws-cdk-lib/assertions";
32
+
33
+ import { TypedTemplate } from "@horietakehiro/aws-cdk-utul/lib/assertions";
34
+ import { AWS_EC2_SUBNET, AWS_EC2_VPC } from "@horietakehiro/aws-cdk-utul/lib/types/cfn-resource-types";
35
+ const stack = new Stack()
36
+
37
+ // just wrap an original `Template` instance of aws-cdk-lib/assertions
38
+ const template = new TypedTemplate(Template.fromStack(stack))
39
+ // you can execute all method implemented in original `Template` instance
40
+ template.hasResource(AWS_EC2_VPC({Properties: {
41
+ CidrBlock: "10.0.0.0/16"
42
+ }}))
43
+ // you can still use original `Matcher` class too.
44
+ const subnets = template.findResources(AWS_EC2_SUBNET({Properties: {
45
+ Tags: Match.arrayWith([
46
+ {Key: "Name", Value: Match.stringLikeRegexp("Public")}
47
+ ])
48
+ }}))
49
+ // you can access resources with more efficient way
50
+ subnets.forEach((sn) => {
51
+ expect(sn.def.Properties?.CidrBlock?.endsWith("/24")).toBe(true)
52
+ })
53
+ ```
54
+
55
+ ---
56
+
57
+ ### ExtraMatch
58
+
59
+ `ExtraMatch` class provides you some kind of a syntax sugar for original `Match` class.
60
+
61
+ ```js
62
+ import { ExtraMatch } from "@horietakehiro/aws-cdk-utul/lib/assertions"
63
+ // get just vpc's logical id
64
+ const [{id}] = template.findResources(AWS_EC2_VPC({}))
65
+ template.allResources(AWS_EC2_SUBNET({
66
+ // Equals to {VpcId: {Ref: id}}
67
+ Properties: {VpcId: ExtraMatch.ref(id)}
68
+ }))
69
+ template.hasOutput("VPCARN", {
70
+ // Equals to {Value: {"Fn::GetAtt": [id, "Arn"]}}
71
+ Value: ExtraMatch.getAttArn(id)
72
+ })
73
+ ```
74
+
75
+ ---
76
+
77
+ ## Install
78
+
79
+ ```bash
80
+ npm install @horietakehiro/aws-cdk-utul
81
+ ```
82
+
83
+ ---
84
+
85
+ ## Some notes
86
+
87
+ - Schemas of AWS CloudFormation resource types used in this library are based on [those at `us-east-1`](https://docs.aws.amazon.com/ja_jp/AWSCloudFormation/latest/UserGuide/resource-type-schemas.html)
88
+ - Compatible with AWS CDK v2.0.0 or greater.
Binary file
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@horietakehiro/aws-cdk-utul",
3
3
  "license": "MIT",
4
- "version": "0.2.2",
4
+ "version": "0.9.0",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "https://github.com/horietakehiro/aws-cdk-utul"