diff --git a/lint-staged.config.js b/lint-staged.config.js index 726e4bc..058145e 100644 --- a/lint-staged.config.js +++ b/lint-staged.config.js @@ -1,6 +1,10 @@ module.exports = { "*.js": ["prettier --write", "eslint --format=pretty --quiet --fix --cache"], - "*.ts": () => ["pnpm format", "pnpm typecheck", "pnpm test --only-changed"], + "*.ts": () => [ + "pnpm format", + "pnpm typecheck", + "pnpm test -- --only-changed", + ], "*.{json,yml,md}": "prettier --write --ignore-unknown", "*.sh": "shellcheck", }; diff --git a/src/lib/__tests__/__snapshots__/base-stack.test.ts.snap b/src/lib/__tests__/__snapshots__/base-stack.test.ts.snap new file mode 100644 index 0000000..41f2476 --- /dev/null +++ b/src/lib/__tests__/__snapshots__/base-stack.test.ts.snap @@ -0,0 +1,124 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`BaseStack generates an expected CloudFormation template 1`] = ` +{ + "Parameters": { + "BootstrapVersion": { + "Default": "/cdk-bootstrap/hnb659fds/version", + "Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]", + "Type": "AWS::SSM::Parameter::Value", + }, + }, + "Resources": { + "Bucket83908E77": { + "DeletionPolicy": "Retain", + "Properties": { + "Tags": [ + { + "Key": "myorg:application:description", + "Value": "Opinionated CDK Typescript Boilerplate", + }, + { + "Key": "myorg:application:environment", + "Value": "prod", + }, + { + "Key": "myorg:application:name", + "Value": "cdk-app-ts-boilerplate", + }, + { + "Key": "myorg:application:repository", + "Value": "https://github.com/dashmug/cdk-app-ts-boilerplate", + }, + { + "Key": "myorg:project:customer", + "Value": "myclient", + }, + { + "Key": "myorg:project:name", + "Value": "myproject", + }, + { + "Key": "myorg:project:owner", + "Value": "myteam", + }, + { + "Key": "myorg:stack:name", + "Value": "TestStack", + }, + ], + }, + "Type": "AWS::S3::Bucket", + "UpdateReplacePolicy": "Retain", + }, + "Queue4A7E3555": { + "DeletionPolicy": "Delete", + "Properties": { + "Tags": [ + { + "Key": "myorg:application:description", + "Value": "Opinionated CDK Typescript Boilerplate", + }, + { + "Key": "myorg:application:environment", + "Value": "prod", + }, + { + "Key": "myorg:application:name", + "Value": "cdk-app-ts-boilerplate", + }, + { + "Key": "myorg:application:repository", + "Value": "https://github.com/dashmug/cdk-app-ts-boilerplate", + }, + { + "Key": "myorg:project:customer", + "Value": "myclient", + }, + { + "Key": "myorg:project:name", + "Value": "myproject", + }, + { + "Key": "myorg:project:owner", + "Value": "myteam", + }, + { + "Key": "myorg:stack:name", + "Value": "TestStack", + }, + ], + }, + "Type": "AWS::SQS::Queue", + "UpdateReplacePolicy": "Delete", + }, + }, + "Rules": { + "CheckBootstrapVersion": { + "Assertions": [ + { + "Assert": { + "Fn::Not": [ + { + "Fn::Contains": [ + [ + "1", + "2", + "3", + "4", + "5", + ], + { + "Ref": "BootstrapVersion", + }, + ], + }, + ], + }, + "AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI.", + }, + ], + }, + }, +} +`; diff --git a/src/lib/__tests__/base-stack.test.ts b/src/lib/__tests__/base-stack.test.ts index a635d89..5e63aa4 100644 --- a/src/lib/__tests__/base-stack.test.ts +++ b/src/lib/__tests__/base-stack.test.ts @@ -1,6 +1,7 @@ -import { App, StackProps } from "aws-cdk-lib"; +import { App, type StackProps } from "aws-cdk-lib"; import { Template } from "aws-cdk-lib/assertions"; import { Bucket } from "aws-cdk-lib/aws-s3"; +import { Queue } from "aws-cdk-lib/aws-sqs"; import type { Construct } from "constructs"; import { BaseStack } from "src/lib/base-stack"; @@ -9,6 +10,7 @@ class TestStack extends BaseStack { super(scope, id, props); new Bucket(this, "Bucket"); + new Queue(this, "Queue"); } } @@ -55,4 +57,8 @@ describe("BaseStack", () => { ], }); }); + + it("generates an expected CloudFormation template", () => { + expect(template).toMatchSnapshot(); + }); });