@horietakehiro/aws-cdk-utul 0.2.2 → 0.9.1
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 +83 -10
- package/package.json +1 -1
- package/.env +0 -1
- package/tsconfig.json +0 -42
package/README.md
CHANGED
|
@@ -1,14 +1,87 @@
|
|
|
1
|
-
#
|
|
1
|
+
# AWS CDK Unit Test Utility Library
|
|
2
2
|
|
|
3
|
-
|
|
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
|
-
|
|
9
|
+
**aws-cdk-utul(unit test utility library) makes it faster, more efficient with less mistakes for you to code AWS CDK unit tests.**
|
|
6
10
|
|
|
7
|
-
|
|
11
|
+
---
|
|
8
12
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
## Features
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
### TypedTemplate
|
|
18
|
+
|
|
19
|
+
`TypedTemplate` class provides you proper type definitions for (almost) all AWS CloudFormation resource types. So you can easily and quickly code AWS CDK unit tests without trivial mistakes and googling.
|
|
20
|
+
|
|
21
|
+

|
|
22
|
+
|
|
23
|
+
- You can use by just wrapping AWS CDK's `Template` class.
|
|
24
|
+
- You can use all methods implemented by AWS CDK's `Template` class with proper type definitions.
|
|
25
|
+
- Return values of some methods - e.g. `findResources` - are changed from original ones, so that succeeding processes can handle and access them more easily.
|
|
26
|
+
- You can still use AWS CDK's `Matcher` class and other arbitrary objects too.
|
|
27
|
+
|
|
28
|
+
```js
|
|
29
|
+
import { Stack } from "aws-cdk-lib";
|
|
30
|
+
import { Template } from "aws-cdk-lib/assertions";
|
|
31
|
+
|
|
32
|
+
import { TypedTemplate } from "@horietakehiro/aws-cdk-utul/lib/assertions";
|
|
33
|
+
import { AWS_EC2_SUBNET, AWS_EC2_VPC } from "@horietakehiro/aws-cdk-utul/lib/types/cfn-resource-types";
|
|
34
|
+
const stack = new Stack()
|
|
35
|
+
|
|
36
|
+
// just wrap an original `Template` instance of aws-cdk-lib/assertions
|
|
37
|
+
const template = new TypedTemplate(Template.fromStack(stack))
|
|
38
|
+
// you can execute all method implemented in original `Template` instance
|
|
39
|
+
template.hasResource(AWS_EC2_VPC({Properties: {
|
|
40
|
+
CidrBlock: "10.0.0.0/16"
|
|
41
|
+
}}))
|
|
42
|
+
// you can still use original `Matcher` class too.
|
|
43
|
+
const subnets = template.findResources(AWS_EC2_SUBNET({Properties: {
|
|
44
|
+
Tags: Match.arrayWith([
|
|
45
|
+
{Key: "Name", Value: Match.stringLikeRegexp("Public")}
|
|
46
|
+
])
|
|
47
|
+
}}))
|
|
48
|
+
// you can access resources with more efficient way
|
|
49
|
+
subnets.forEach((sn) => {
|
|
50
|
+
expect(sn.def.Properties?.CidrBlock?.endsWith("/24")).toBe(true)
|
|
51
|
+
})
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
---
|
|
55
|
+
|
|
56
|
+
### ExtraMatch
|
|
57
|
+
|
|
58
|
+
`ExtraMatch` class provides you some kind of a syntax sugar for AWS CDK's `Match` class.
|
|
59
|
+
|
|
60
|
+
```js
|
|
61
|
+
import { ExtraMatch } from "@horietakehiro/aws-cdk-utul/lib/assertions"
|
|
62
|
+
// get just vpc's logical id
|
|
63
|
+
const [{id}] = template.findResources(AWS_EC2_VPC({}))
|
|
64
|
+
template.allResources(AWS_EC2_SUBNET({
|
|
65
|
+
// Equals to {VpcId: {Ref: id}}
|
|
66
|
+
Properties: {VpcId: ExtraMatch.ref(id)}
|
|
67
|
+
}))
|
|
68
|
+
template.hasOutput("VPCARN", {
|
|
69
|
+
// Equals to {Value: {"Fn::GetAtt": [id, "Arn"]}}
|
|
70
|
+
Value: ExtraMatch.getAttArn(id)
|
|
71
|
+
})
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
---
|
|
75
|
+
|
|
76
|
+
## Install
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
npm install @horietakehiro/aws-cdk-utul
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
---
|
|
83
|
+
|
|
84
|
+
## Some notes
|
|
85
|
+
|
|
86
|
+
- 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)
|
|
87
|
+
- Compatible with AWS CDK v2.0.0 or greater.
|
package/package.json
CHANGED
package/.env
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export NODE_OPTIONS="$NODE_OPTIONS --experimental-vm-modules"
|
package/tsconfig.json
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"target": "ES2020",
|
|
4
|
-
"module": "commonjs",
|
|
5
|
-
"lib": [
|
|
6
|
-
"es2020",
|
|
7
|
-
"dom"
|
|
8
|
-
],
|
|
9
|
-
"declaration": true,
|
|
10
|
-
"strict": true,
|
|
11
|
-
"noImplicitAny": true,
|
|
12
|
-
"strictNullChecks": true,
|
|
13
|
-
"noImplicitThis": true,
|
|
14
|
-
"alwaysStrict": true,
|
|
15
|
-
"noUnusedLocals": false,
|
|
16
|
-
"noUnusedParameters": false,
|
|
17
|
-
"noImplicitReturns": true,
|
|
18
|
-
"noFallthroughCasesInSwitch": false,
|
|
19
|
-
"inlineSourceMap": true,
|
|
20
|
-
"inlineSources": true,
|
|
21
|
-
"experimentalDecorators": true,
|
|
22
|
-
"strictPropertyInitialization": false,
|
|
23
|
-
// "emitDeclarationOnly": true,
|
|
24
|
-
"typeRoots": [
|
|
25
|
-
"./node_modules/@types",
|
|
26
|
-
// "./lib/types"
|
|
27
|
-
],
|
|
28
|
-
// "outDir": "./dist"
|
|
29
|
-
},
|
|
30
|
-
"include": [
|
|
31
|
-
"./lib",
|
|
32
|
-
"./index.ts",
|
|
33
|
-
],
|
|
34
|
-
"exclude": [
|
|
35
|
-
"node_modules",
|
|
36
|
-
"cdk.out",
|
|
37
|
-
"test",
|
|
38
|
-
"scripts",
|
|
39
|
-
"bin",
|
|
40
|
-
|
|
41
|
-
]
|
|
42
|
-
}
|