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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge #24

Merged
merged 44 commits into from
Sep 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
e3f3332
feat(elasticloadbalancingv2): more health check validations to NLB ta…
yerzhan7 Sep 10, 2020
940a443
feat(cli): support credential_source in aws shared config file (#10272)
iliapolo Sep 10, 2020
14c8a98
fix(pipelines): changing synth action doesn't restart pipeline (#10176)
rix0rrr Sep 10, 2020
238d963
chore: parallelize integ tests across regions (#10269)
rix0rrr Sep 10, 2020
a1f6e1b
feat(route53-patterns): support IPv6 in HttpsRedirect (#10203)
corpulentcoffee Sep 10, 2020
495aeb9
fix(cloudfront): comment for origin access identity is too long (#10266)
njlynch Sep 10, 2020
5861f07
chore(cli): install modules before bootstrap in integ tests (#10297)
iliapolo Sep 10, 2020
698e5ef
feat(codebuild): add git submodule options of codebuild (#10283)
zxkane Sep 11, 2020
54dfe83
fix(kms): do not change the principal to root for imported resources …
skinny85 Sep 11, 2020
0653e6b
fix(rds): Make most DatabaseClusterAttributes properties optional (#1…
njlynch Sep 11, 2020
8cfc190
feat(eks): bump aws-node-termination-handler to 0.9.5 (#10278)
pahud Sep 11, 2020
30a5b80
feat(appsync): support enumeration types for code-first approach (#10…
BryanPan342 Sep 11, 2020
65db131
feat(appsync): add support for subscriptions for code-first schema ge…
BryanPan342 Sep 11, 2020
4925e06
chore(cfn-include): updates to the ReadMe (#10315)
skinny85 Sep 12, 2020
8d5b954
chore(release): 1.63.0
Sep 12, 2020
8a2cbcc
Update CHANGELOG.md
NetaNir Sep 12, 2020
f5c5d06
chore(deps): bump node-fetch from 2.6.0 to 2.6.1 (#10329)
dependabot[bot] Sep 13, 2020
7a68125
chore(release): 1.63.0 (#10318)
mergify[bot] Sep 13, 2020
8c0b9c2
Merge branch 'master' into merge-back/1.63.0
mergify[bot] Sep 14, 2020
a8e8ed3
feat(secretsmanager): import secrets by name (#10309)
njlynch Sep 14, 2020
a0985ef
Merge branch 'master' into merge-back/1.63.0
mergify[bot] Sep 14, 2020
3d89964
chore(merge-back): 1.63.0 (#10336)
mergify[bot] Sep 14, 2020
ad9a705
fix(bootstrapping): `--cloudformation-execution-policies` not checked…
rix0rrr Sep 14, 2020
406f665
fix(cli): `cdk synth` fails if AWS_ credentials have expired (#10343)
rix0rrr Sep 14, 2020
19638a6
feat(eks): bottlerocket versoin follows the cluster k8s versoin (#10189)
pahud Sep 14, 2020
a2174a4
feat(lambda-nodejs): custom bundling image (#10270)
jogold Sep 14, 2020
857acbb
fix(eks): circular dependencies when security groups from other stack…
iliapolo Sep 14, 2020
53e7622
chore: add `return await` linting rule (#10358)
rix0rrr Sep 15, 2020
25256d0
chore: add yarn upgrade workflow (#10346)
RomainMuller Sep 15, 2020
957a12e
fix(cli): `--profile` is ignored if AWS_ variables are set (#10362)
rix0rrr Sep 16, 2020
89ce22a
docs(codepipeline): fix example documentation for Pipeline class (#10…
reubinoff Sep 16, 2020
5ad8cdb
feat(redshift): support existing cluster subnet groups (#10340)
njlynch Sep 16, 2020
a578ef8
feat(rds): add SQL Server version 15.00.4043.16.v1 (#10289)
abjoshi2785 Sep 16, 2020
3dcd01e
feat(events-targets): supports to specify fargate platform version (#…
kuwa0224 Sep 16, 2020
7b5c9d2
fix: SSM Association 'parameters' property has incorrect type (#10316)
skinny85 Sep 16, 2020
364543c
chore: fix integ tests (#10384)
rix0rrr Sep 16, 2020
5111837
feat(cognito): user pool client logout urls (#10301)
tneely Sep 16, 2020
a726dad
feat(custom-resource): allow referencing resource id in updates/delet…
cheruvian Sep 16, 2020
491113d
feat(ec2): user-defined subnet selectors (#10112)
flemjame-at-amazon Sep 16, 2020
746dfe2
fix(redshift): cluster defaultChild broken after adding subnet group …
njlynch Sep 16, 2020
b0b9c53
chore(core): add missing maturities (#10351)
ericzbeard Sep 16, 2020
9e4451a
chore: update module description to align with other modules (#10383)
shivlaks Sep 16, 2020
4751f42
fix(cfn-include): allow referring to Conditions in Outputs and Rules …
skinny85 Sep 16, 2020
673dd82
fix(diff): allow strings to be passed for boolean properties (#10378)
skinny85 Sep 16, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 75 additions & 0 deletions .github/workflows/yarn-upgrade.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
name: Yarn Upgrade

on:
schedule:
# Every wednesday at 13:37 UTC
- cron: 37 13 * * 3
workflow_dispatch: {}

jobs:
upgrade:
name: Yarn Upgrade
runs-on: ubuntu-latest
steps:

- name: Check Out
uses: actions/checkout@v2

- name: Set up Node
uses: actions/setup-node@v2.1.0
with:
node-version: 10

- name: Locate Yarn cache
id: yarn-cache
run: echo "::set-output name=dir::$(yarn cache dir)"

- name: Restore Yarn cache
uses: actions/cache@v2
with:
path: ${{ steps.yarn-cache.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |-
${{ runner.os }}-yarn-
- name: Install Tools
run: |-
npm -g install lerna npm-check-updates@^9.0.0
- name: List Mono-Repo Packages
id: list-packages
# These need to be ignored from the `ncu` runs!
run: |-
echo -n "::set-output name=list::"
node -p "$(lerna ls --all --json 2>/dev/null).map(item => item.name).join(',')"
- name: Run "ncu -u"
# We special-case @types/node because we want to stay on the current major (minimum supported node release)
# We special-case @types/fs-extra because the current major (9.x) is broken with @types/node >= 10
# We special-case typescript because it's not semantically versionned
run: |-
# Upgrade dependencies at repository root
ncu --upgrade --filter=@types/node,@types/fs-extra --target=minor
ncu --upgrade --filter=typescript --target=patch
ncu --upgrade --reject=@types/node,@types/fs-extra,typescript
# Upgrade all the packages
lerna exec --parallel ncu -- --upgrade --filter=@types/node,@types/fs-extra --target=minor
lerna exec --parallel ncu -- --upgrade --filter=typescript --target=patch
lerna exec --parallel ncu -- --upgrade --reject='@types/node,@types/fs-extra,typescript,${{ steps.list-packages.outputs.list }}'
# This will create a brand new `yarn.lock` file (this is more efficient than `yarn install && yarn upgrade`)
- name: Run "yarn install --force"
run: yarn install --force

- name: Make Pull Request
uses: peter-evans/create-pull-request@v2
with:
# Git commit details
branch: automation/yarn-upgrade
commit-message: |-
chore: npm-check-updates && yarn upgrade
Ran npm-check-updates and yarn upgrade to keep the `yarn.lock` file up-to-date.
# Pull Request details
title: 'chore: npm-check-updates && yarn upgrade'
body: |-
Ran npm-check-updates and yarn upgrade to keep the `yarn.lock` file up-to-date.
labels: contribution/core,dependencies
team-reviewers: aws-cdk-team
# Privileged token so automated PR validation happens
token: ${{ secrets.AUTOMATION_GITHUB_TOKEN }}
60 changes: 60 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,66 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

## [1.63.0](https://github.com/aws/aws-cdk/compare/v1.62.0...v1.63.0) (2020-09-12)


### ⚠ BREAKING CHANGES TO EXPERIMENTAL FEATURES

* **appsync:** force `apiKeyConfig` require a Expiration class instead of string
- **appsync**: Parameter `apiKeyConfig` takes `Expiration` class instead of `string`
* **core:** custom implementations of `IStackSynthesizer`
must now implement `synthesize()` instead of
`synthesizeStackArtifacts()`.
* **aws-batch:** Changed type of `ComputeResources.computeResourcesTags` from `Tag` to map

### Features

* **appsync:** add authorization config to the HttpDataSource ([#10171](https://github.com/aws/aws-cdk/issues/10171)) ([b2cc277](https://github.com/aws/aws-cdk/commit/b2cc277971aed36aa03e720b8fea093ef14bd9be)), closes [#9971](https://github.com/aws/aws-cdk/issues/9971) [#9934](https://github.com/aws/aws-cdk/issues/9934)
* **appsync:** add support for subscriptions for code-first schema generation ([#10078](https://github.com/aws/aws-cdk/issues/10078)) ([65db131](https://github.com/aws/aws-cdk/commit/65db1312d6b395700c203edeb50248b5e8a0c036)), closes [#9345](https://github.com/aws/aws-cdk/issues/9345)
* **appsync:** implement directives for code-first approach ([#9973](https://github.com/aws/aws-cdk/issues/9973)) ([088cd48](https://github.com/aws/aws-cdk/commit/088cd4857f2f3f29873bdf5f7d1c4b25b3d49372)), closes [#9879](https://github.com/aws/aws-cdk/issues/9879)
* **appsync:** support enumeration types for code-first approach ([#10023](https://github.com/aws/aws-cdk/issues/10023)) ([30a5b80](https://github.com/aws/aws-cdk/commit/30a5b806f265d88e88d2faea623e1ce024c019c3)), closes [#10023](https://github.com/aws/aws-cdk/pull/10023#issuecomment-690773916)
* **appsync:** support union types for code-first approach ([#10025](https://github.com/aws/aws-cdk/issues/10025)) ([28a9834](https://github.com/aws/aws-cdk/commit/28a9834fb6cbacbd3e0ef97441fa0fb6e45120b1))
* **cfn-include:** add support for Hooks ([#10143](https://github.com/aws/aws-cdk/issues/10143)) ([4de68c0](https://github.com/aws/aws-cdk/commit/4de68c0a5b0e7568a5e222e8a29703186b961ec7)), closes [#9713](https://github.com/aws/aws-cdk/issues/9713)
* **cfn-include:** allow renaming the template elements logical IDs ([#10169](https://github.com/aws/aws-cdk/issues/10169)) ([cf746a0](https://github.com/aws/aws-cdk/commit/cf746a07be171b35bb5e5514287c628642436df3)), closes [#9714](https://github.com/aws/aws-cdk/issues/9714)
* **chatbot:** log retention support and metrics utility methods ([#10137](https://github.com/aws/aws-cdk/issues/10137)) ([0f0d1e7](https://github.com/aws/aws-cdk/commit/0f0d1e74fb71a7b415aa9a5d02258b7c5933536b)), closes [#10135](https://github.com/aws/aws-cdk/issues/10135)
* **cli:** support credential_source in aws shared config file ([#10272](https://github.com/aws/aws-cdk/issues/10272)) ([940a443](https://github.com/aws/aws-cdk/commit/940a443ba457ddaebd85b44fa63cd9b15201c18a))
* **codebuild:** add git submodule options of codebuild ([#10283](https://github.com/aws/aws-cdk/issues/10283)) ([698e5ef](https://github.com/aws/aws-cdk/commit/698e5ef3568880474adf73a38c21dad919b62b7e)), closes [#10271](https://github.com/aws/aws-cdk/issues/10271)
* **eks:** arm64 support ([#9875](https://github.com/aws/aws-cdk/issues/9875)) ([ffb84c6](https://github.com/aws/aws-cdk/commit/ffb84c62d03e40daa0e07c451c31bdea2dd0816c)), closes [#9915](https://github.com/aws/aws-cdk/issues/9915)
* **eks:** bump aws-node-termination-handler to 0.9.5 ([#10278](https://github.com/aws/aws-cdk/issues/10278)) ([8cfc190](https://github.com/aws/aws-cdk/commit/8cfc190daaa112de448c19716df2c10eeb29695c)), closes [aws/aws-cdk#10277](https://github.com/aws/aws-cdk/issues/10277)
* **eks:** managed nodegroup with custom AMI and launch template support ([#9881](https://github.com/aws/aws-cdk/issues/9881)) ([5c294fb](https://github.com/aws/aws-cdk/commit/5c294fbc1149167a70f35c7870ff1995042839b7)), closes [#9873](https://github.com/aws/aws-cdk/issues/9873)
* **elasticloadbalancingv2:** more health check validations to NLB target group ([#3703](https://github.com/aws/aws-cdk/issues/3703)) ([#10205](https://github.com/aws/aws-cdk/issues/10205)) ([e3f3332](https://github.com/aws/aws-cdk/commit/e3f333212b7c9f7deb836be8ecd71c7a7a06c394))
* **elasticloadbalancingv2:** multiple security groups for ALBs ([#10244](https://github.com/aws/aws-cdk/issues/10244)) ([1ebf362](https://github.com/aws/aws-cdk/commit/1ebf36206b1e6a98a9a708efbe3ba3bfb1d3f05e)), closes [#5138](https://github.com/aws/aws-cdk/issues/5138)
* **lambda-nodejs:** improved project root detection ([#10182](https://github.com/aws/aws-cdk/issues/10182)) ([cce83dc](https://github.com/aws/aws-cdk/commit/cce83dcc163da8f71b8c2f95818d7d8f25db95f4)), closes [#10174](https://github.com/aws/aws-cdk/issues/10174)
* **pipelines:** adding IAM permissions to ShellScriptAction ([#10149](https://github.com/aws/aws-cdk/issues/10149)) ([ec15485](https://github.com/aws/aws-cdk/commit/ec154850b6bc2f485241aa1c0ea41400785d8a41)), closes [#9600](https://github.com/aws/aws-cdk/issues/9600)
* **rds:** database clusters from snapshots ([#10130](https://github.com/aws/aws-cdk/issues/10130)) ([915eb4b](https://github.com/aws/aws-cdk/commit/915eb4be3946652a00b7496b9e8610169852f27b)), closes [#4379](https://github.com/aws/aws-cdk/issues/4379)
* **rds:** deprecate OracleSE and OracleSE1 engine versions ([#10241](https://github.com/aws/aws-cdk/issues/10241)) ([562f891](https://github.com/aws/aws-cdk/commit/562f8913dae7b77a1516a60cc1ff277ac42fb9e0)), closes [#9249](https://github.com/aws/aws-cdk/issues/9249)
* **rds:** metrics for clusters ([#10162](https://github.com/aws/aws-cdk/issues/10162)) ([49f6034](https://github.com/aws/aws-cdk/commit/49f6034ee2b514f870819b7b48880246750b6fd2)), closes [#5212](https://github.com/aws/aws-cdk/issues/5212)
* **route53-patterns:** support IPv6 in HttpsRedirect ([#10203](https://github.com/aws/aws-cdk/issues/10203)) ([a1f6e1b](https://github.com/aws/aws-cdk/commit/a1f6e1be8a21625b1723b51277457f598a3be23e))
* **secrets-manager:** exclude characters for password rotation applications ([#10110](https://github.com/aws/aws-cdk/issues/10110)) ([1260d52](https://github.com/aws/aws-cdk/commit/1260d5215d474d6edc2460ffe9658552d17ab239)), closes [#4144](https://github.com/aws/aws-cdk/issues/4144)


### Bug Fixes

* **appsync:** strongly type `expires` prop in apiKeyConfig ([#9122](https://github.com/aws/aws-cdk/issues/9122)) ([287f808](https://github.com/aws/aws-cdk/commit/287f808cf34870295e4032995fc083ac204b64c3)), closes [#8698](https://github.com/aws/aws-cdk/issues/8698)
* **aws-batch:** `computeResources` tags are not configured properly ([#10209](https://github.com/aws/aws-cdk/issues/10209)) ([40222ef](https://github.com/aws/aws-cdk/commit/40222ef398fd1fb63b3b886624d5bb40562142c6)), closes [#7350](https://github.com/aws/aws-cdk/issues/7350)
* **cfn-include:** correctly parse YAML strings in short-form GetAtt ([#10197](https://github.com/aws/aws-cdk/issues/10197)) ([a388d70](https://github.com/aws/aws-cdk/commit/a388d70f38a84195bbe5e580220b5cd21ebde624)), closes [#10177](https://github.com/aws/aws-cdk/issues/10177)
* **cfn-include:** correctly substitute falsy parameter values ([#10195](https://github.com/aws/aws-cdk/issues/10195)) ([8791f88](https://github.com/aws/aws-cdk/commit/8791f8877165c87f6ef4967376aa53ffeb696013)), closes [#10107](https://github.com/aws/aws-cdk/issues/10107)
* **cli:** metadata not recorded for templates >50k ([#10184](https://github.com/aws/aws-cdk/issues/10184)) ([dfd2baf](https://github.com/aws/aws-cdk/commit/dfd2baf8b9d4cc930a1c5dc88c178ffe7d1121b0))
* **cli:** simplify lib template ([#10175](https://github.com/aws/aws-cdk/issues/10175)) ([fc3ec9b](https://github.com/aws/aws-cdk/commit/fc3ec9b20edb2442bab456acf55c5cff7efb11b9))
* **cli:** unable to set termination protection for pipeline stacks ([#9938](https://github.com/aws/aws-cdk/issues/9938)) ([a00a4ee](https://github.com/aws/aws-cdk/commit/a00a4ee162f287b5db45e73051ecdf0e32009def))
* **cloudfront:** comment for origin access identity is too long ([#10266](https://github.com/aws/aws-cdk/issues/10266)) ([495aeb9](https://github.com/aws/aws-cdk/commit/495aeb96fd530ba0f73eeeab5a5b75b4a7390c99)), closes [#10211](https://github.com/aws/aws-cdk/issues/10211)
* **codepipeline:** cross-region support stack requires bootstrapping ([#10217](https://github.com/aws/aws-cdk/issues/10217)) ([b5ff4d6](https://github.com/aws/aws-cdk/commit/b5ff4d6673629ebabceb72fc83464001267c328e)), closes [#10215](https://github.com/aws/aws-cdk/issues/10215)
* **core:** DefaultSynthesizer breaks this.node.setContext() on Stack ([#10246](https://github.com/aws/aws-cdk/issues/10246)) ([61865aa](https://github.com/aws/aws-cdk/commit/61865aaef682be6727d7768213260c7a95d799f8))
* **core:** Stacks render CloudFormation elements in nested Stages ([#10156](https://github.com/aws/aws-cdk/issues/10156)) ([5f36f6b](https://github.com/aws/aws-cdk/commit/5f36f6b5b2126de763b2e156fa2a9b6604f40f00)), closes [#9792](https://github.com/aws/aws-cdk/issues/9792) [#9669](https://github.com/aws/aws-cdk/issues/9669)
* **custom-resources:** deleting custom resource fails when using two or more ([#10012](https://github.com/aws/aws-cdk/issues/10012)) ([8d23f24](https://github.com/aws/aws-cdk/commit/8d23f248c7496d56c352a3db4b9d4bcccbdfe1c4))
* **ec2:** cfn-init user data hash not updated if file asset changes ([#10216](https://github.com/aws/aws-cdk/issues/10216)) ([0d7ca63](https://github.com/aws/aws-cdk/commit/0d7ca63edb11a80440732d6327d0fe3ed685a993)), closes [#10206](https://github.com/aws/aws-cdk/issues/10206)
* **eks:** restricted public access breaks cluster functionality ([#10103](https://github.com/aws/aws-cdk/issues/10103)) ([a1b5bf6](https://github.com/aws/aws-cdk/commit/a1b5bf6f5a77e236169f95159cf62a2ecfb25bc4))
* **kms:** do not change the principal to root for imported resources in dependent Stacks ([#10299](https://github.com/aws/aws-cdk/issues/10299)) ([54dfe83](https://github.com/aws/aws-cdk/commit/54dfe8374afeaff400e85f43185462b9fd9c8ac2)), closes [#10166](https://github.com/aws/aws-cdk/issues/10166)
* **lambda-nodejs:** permission denied, mkdir '/.parcel-cache' ([#10181](https://github.com/aws/aws-cdk/issues/10181)) ([20f5535](https://github.com/aws/aws-cdk/commit/20f5535bee8d0e1e7aa5b0c3bad780666d64bc87))
* **pipelines:** changing synth action doesn't restart pipeline ([#10176](https://github.com/aws/aws-cdk/issues/10176)) ([14c8a98](https://github.com/aws/aws-cdk/commit/14c8a9878d092aac857655c2e5c8684015c84b29)), closes [#9458](https://github.com/aws/aws-cdk/issues/9458)
* **pipelines:** check for an empty Stage object ([#10153](https://github.com/aws/aws-cdk/issues/10153)) ([cec20c8](https://github.com/aws/aws-cdk/commit/cec20c8f68676c2bf3c8c3246334c82f50261358)), closes [#9559](https://github.com/aws/aws-cdk/issues/9559)
* **rds:** Make most DatabaseClusterAttributes properties optional ([#10291](https://github.com/aws/aws-cdk/issues/10291)) ([0653e6b](https://github.com/aws/aws-cdk/commit/0653e6bead37ed92e47295010645009e3b97e246)), closes [#3587](https://github.com/aws/aws-cdk/issues/3587)

## [1.62.0](https://github.com/aws/aws-cdk/compare/v1.61.1...v1.62.0) (2020-09-03)


Expand Down
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
"tools/*"
],
"rejectCycles": "true",
"version": "1.62.0"
"version": "1.63.0"
}
59 changes: 59 additions & 0 deletions packages/@aws-cdk/assert/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,65 @@ expect(stack).to(haveResourceLike('AWS::IAM::Policy', {
}));
```

### Capturing values from a match

Special `Capture` matchers exist to capture values encountered during a match. These can be
used for two typical purposes:

* Apply additional assertions to the values found during a matching operation.
* Use the value found during a matching operation in a new matching operation.

`Capture` matchers take an inner matcher as an argument, and will only capture the value
if the inner matcher succeeds in matching the given value.

Here's an example which asserts that a policy for `RoleA` contains two statements
with *different* ARNs (without caring what those ARNs might be), and that
a policy for `RoleB` *also* has a statement for one of those ARNs (again, without
caring what the ARN might be):

```ts
const arn1 = Capture.aString();
const arn2 = Capture.aString();

expect(stack).to(haveResourceLike('AWS::IAM::Policy', {
Roles: ['RoleA'],
PolicyDocument: {
Statement: [
objectLike({
Resource: [arn1.capture()],
}),
objectLike({
Resource: [arn2.capture()],
}),
],
},
}));

// Don't care about the values as long as they are not the same
expect(arn1.capturedValue).not.toEqual(arn2.capturedValue);

expect(stack).to(haveResourceLike('AWS::IAM::Policy', {
Roles: ['RoleB'],
PolicyDocument: {
Statement: [
objectLike({
// This ARN must be the same as ARN1 above.
Resource: [arn1.capturedValue]
}),
],
},
}));
```

NOTE: `Capture` look somewhat like *bindings* in other pattern matching
libraries you might be used to, but they are far simpler and very
deterministic. In particular, they don't do unification: if the same Capture
is either used multiple times in the same structure expression or matches
multiple times, no restarting of the match is done to make them all match the
same value: the last value encountered by the `Capture` (as determined by the
behavior of the matchers around it) is stored into it and will be the one
available after the match has completed.

### Check number of resources

If you want to assert that `n` number of resources of a particular type exist, with or without specific properties:
Expand Down
98 changes: 98 additions & 0 deletions packages/@aws-cdk/assert/lib/assertions/have-resource-matchers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,104 @@ export function notMatching(matcher: any): PropertyMatcher {
});
}

export type TypeValidator<T> = (x: any) => x is T;

/**
* Captures a value onto an object if it matches a given inner matcher
*
* @example
*
* const someValue = Capture.aString();
* expect(stack).toHaveResource({
* // ...
* Value: someValue.capture(stringMatching('*a*')),
* });
* console.log(someValue.capturedValue);
*/
export class Capture<T=any> {
/**
* A Capture object that captures any type
*/
public static anyType(): Capture<any> {
return new Capture();
}

/**
* A Capture object that captures a string type
*/
public static aString(): Capture<string> {
return new Capture((x: any): x is string => {
if (typeof x !== 'string') {
throw new Error(`Expected to capture a string, got '${x}'`);
}
return true;
});
}

/**
* A Capture object that captures a custom type
*/
public static a<T>(validator: TypeValidator<T>): Capture<T> {
return new Capture(validator);
}

private _value?: T;
private _didCapture = false;
private _wasInvoked = false;

protected constructor(private readonly typeValidator?: TypeValidator<T>) {
}

/**
* Capture the value if the inner matcher successfully matches it
*
* If no matcher is given, `anything()` is assumed.
*
* And exception will be thrown if the inner matcher returns `true` and
* the value turns out to be of a different type than the `Capture` object
* is expecting.
*/
public capture(matcher?: any): PropertyMatcher {
if (matcher === undefined) {
matcher = anything();
}

return annotateMatcher({ $capture: matcher }, (value: any, failure: InspectionFailure) => {
this._wasInvoked = true;
const result = matcherFrom(matcher)(value, failure);
if (result) {
if (this.typeValidator && !this.typeValidator(value)) {
throw new Error(`Value not of the expected type: ${value}`);
}
this._didCapture = true;
this._value = value;
}
return result;
});
}

/**
* Whether a value was successfully captured
*/
public get didCapture() {
return this._didCapture;
}

/**
* Return the value that was captured
*
* Throws an exception if now value was captured
*/
public get capturedValue(): T {
// When this module is ported to jsii, the type parameter will obviously
// have to be dropped and this will have to turn into an `any`.
if (!this.didCapture) {
throw new Error(`Did not capture a value: ${this._wasInvoked ? 'inner matcher failed' : 'never invoked'}`);
}
return this._value!;
}
}

/**
* Match on the innards of a JSON string, instead of the complete string
*/
Expand Down
Loading