Skip to content

Commit

Permalink
Merge branch 'release/1.4.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
spencerbeggs committed Feb 9, 2021
2 parents 14db87a + fd5a4d6 commit ec7b989
Show file tree
Hide file tree
Showing 7 changed files with 1,545 additions and 1,244 deletions.
65 changes: 15 additions & 50 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,64 +1,29 @@
module.exports = {
parser: "@typescript-eslint/parser", // Specifies the ESLint parser
root: true,
parser: "@typescript-eslint/parser",
plugins: ["@typescript-eslint"],
extends: [
"plugin:@typescript-eslint/recommended", // Uses the recommended rules from the @typescript-eslint/eslint-plugin
"prettier/@typescript-eslint", // Uses eslint-config-prettier to disable ESLint rules from @typescript-eslint/eslint-plugin that would conflict with prettier
"plugin:prettier/recommended", // Enables eslint-plugin-prettier and displays prettier errors as ESLint errors. Make sure this is always the last configuration in the extends array.
],
extends: ["eslint:recommended", "plugin:@typescript-eslint/recommended", "prettier", "prettier/@typescript-eslint"],
parserOptions: {
ecmaVersion: 2018, // Allows for the parsing of modern ECMAScript features
sourceType: "module", // Allows for the use of imports
ecmaFeatures: {
modules: true,
},
ecmaVersion: 2020,
sourceType: "module",
},
env: {
node: true,
jest: true,
},
settings: {
"import/extensions": [".js", ".jsx", ".ts", ".tsx"],
"import/parsers": {
"@typescript-eslint/parser": [".ts", ".tsx"],
},
"import/resolver": {
typescript: {
directory: "./tsconfig.json",
},
node: {
extensions: [".js", ".jsx", ".ts", ".tsx"],
},
},
es6: true,
},
globals: {},
rules: {
"sort-imports": [
"error",
{
ignoreCase: false,
ignoreDeclarationSort: false,
ignoreMemberSort: false,
memberSyntaxSortOrder: ["none", "all", "multiple", "single"],
},
],
"max-len": [
semi: ["error", "always"],
quotes: ["error", "double"],
"@typescript-eslint/explicit-function-return-type": "off",
"@typescript-eslint/no-explicit-any": 1,
"@typescript-eslint/no-var-requires": 0,
"@typescript-eslint/no-inferrable-types": [
"warn",
{
code: 125,
ignoreRegExpLiterals: true,
ignoreTemplateLiterals: true,
ignoreStrings: true,
ignoreUrls: true,
},
],
"no-unused-vars": [
"error",
{
vars: "all",
args: "after-used",
ignoreRestSiblings: true,
argsIgnorePattern: "err",
ignoreParameters: true,
},
],
"@typescript-eslint/no-unused-vars": "warn",
},
};
9 changes: 7 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"eslint.enable": true,
"eslint.validate": ["javascript", "javascriptreact", "typescript", "typescriptreact"],
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
Expand All @@ -11,7 +10,13 @@
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[typescript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true,
"source.organizeImports": true,
"source.addMissingImports": true
}
},
"[typescriptreact]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
Expand Down
56 changes: 46 additions & 10 deletions __tests__/construct.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { countResources, expect as expectCDK } from "@aws-cdk/assert";
import { Certificate, DnsValidatedCertificate } from "@aws-cdk/aws-certificatemanager";
import { PublicHostedZone } from "@aws-cdk/aws-route53";
import { App, Stack } from "@aws-cdk/core";
import { DomainRedirect, REGION_ERROR_MESSAGE } from "../src/redirect";
import { countResources, expect as expectCDK } from "@aws-cdk/assert";

import { Certificate } from "@aws-cdk/aws-certificatemanager";

class TestApp {
public readonly stack: Stack;
Expand All @@ -19,7 +19,7 @@ class TestApp {
}

describe("DomainRedirect", (): void => {
let stack: Stack, fromLookup: jest.Mock, fromAlias: jest.Mock, fakeCert: Certificate;
let stack: Stack, fromLookup: jest.Mock, fromAlias: jest.Mock;
beforeEach(() => {
({ stack } = new TestApp());
fromLookup = jest.fn();
Expand All @@ -29,16 +29,13 @@ describe("DomainRedirect", (): void => {
fromLookup: fromLookup,
},
AddressRecordTarget: {
fromAlias: function (): object {
fromAlias: function (): Record<string, unknown> {
return {
bind: fromAlias,
};
},
},
}));
fakeCert = new Certificate(stack, "Certificate", {
domainName: "example.com",
});
});
it("looks up an IHostedZone if a valid hostname is passed as a string to DomainOptions.zoneName", function (): void {
fromLookup.mockReturnValue({
Expand Down Expand Up @@ -67,6 +64,9 @@ describe("DomainRedirect", (): void => {
fromLookup.mockReturnValue({
zoneName: "example.com.",
});
const fakeCert = new Certificate(stack, "Certificate", {
domainName: "example.com",
});
new DomainRedirect(stack, "redirects", {
zoneName: "example.com",
cert: fakeCert,
Expand All @@ -79,19 +79,42 @@ describe("DomainRedirect", (): void => {
fromLookup.mockReturnValue({
zoneName: "example.com.",
});
const fakeCert = new Certificate(stack, "Certificate", {
domainName: "example.com",
});
new DomainRedirect(stack, "redirects", {
zoneName: "example.com",
cert: fakeCert,
target: "https://spencerbeg.gs",
hostnames: "foobar.example.com",
});
expectCDK(stack).to(countResources("AWS::CertificateManager::Certificate", 1));
expectCDK(stack).to(countResources("AWS::S3::Bucket", 1));
expectCDK(stack).to(countResources("AWS::CloudFront::Distribution", 1));
});
it("accepts a DnsValidatedCertificate as a cert type", function (): void {
const exampleDotComZone = new PublicHostedZone(stack, "ExampleDotCom", {
zoneName: "example.com",
});
new DomainRedirect(stack, "redirects", {
zoneName: "example.com",
cert: new DnsValidatedCertificate(stack, "DnsValidatedCertificate", {
domainName: "test.example.com",
hostedZone: exampleDotComZone,
}),
target: "https://spencerbeg.gs",
hostnames: "foobar.example.com",
});
expectCDK(stack).to(countResources("AWS::S3::Bucket", 1));
expectCDK(stack).to(countResources("AWS::CloudFront::Distribution", 1));
});
it("passes through an array of strings for DomainOptions.hostnames", function (): void {
fromLookup.mockReturnValue({
zoneName: "example.com.",
});
const fakeCert = new Certificate(stack, "Certificate", {
domainName: "example.com",
});
new DomainRedirect(stack, "redirects", {
zoneName: "example.com",
cert: fakeCert,
Expand All @@ -105,6 +128,9 @@ describe("DomainRedirect", (): void => {
fromLookup.mockReturnValue({
zoneName: "example.com",
});
const fakeCert = new Certificate(stack, "Certificate", {
domainName: "example.com",
});
new DomainRedirect(stack, "redirects", {
zoneName: "example.com",
cert: fakeCert,
Expand All @@ -114,6 +140,9 @@ describe("DomainRedirect", (): void => {
expectCDK(stack).to(countResources("AWS::CloudFront::Distribution", 1));
});
it("accepts and array of DomainOptions", () => {
const fakeCert = new Certificate(stack, "Certificate", {
domainName: "example.com",
});
fromLookup
.mockReturnValueOnce({
zoneName: "domain1.com",
Expand All @@ -140,7 +169,9 @@ describe("DomainRedirect", (): void => {
fromLookup.mockReturnValueOnce({
zoneName: "example.com",
});

const fakeCert = new Certificate(stack, "Certificate", {
domainName: "example.com",
});
new DomainRedirect(stack, "redirects", {
zoneName: "domain1.com",
cert: fakeCert,
Expand All @@ -157,7 +188,9 @@ describe("DomainRedirect", (): void => {
fromLookup.mockReturnValueOnce({
zoneName: "example.com",
});

const fakeCert = new Certificate(stack, "Certificate", {
domainName: "example.com",
});
new DomainRedirect(stack, "redirects", {
zoneName: "domain1.com",
cert: fakeCert,
Expand All @@ -169,6 +202,9 @@ describe("DomainRedirect", (): void => {
});
it("it throws if you try to create a stack that is not in us-east-1", () => {
const { stack: stackInWrongRegion } = new TestApp("us-west-1");
const fakeCert = new Certificate(stack, "Certificate", {
domainName: "example.com",
});
const fn = (): void => {
new DomainRedirect(stackInWrongRegion, "redirects", {
zoneName: "domain1.com",
Expand Down
3 changes: 1 addition & 2 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ module.exports = {
testEnvironment: "node",
globals: {
"ts-jest": {
packageJson: "package.json",
tsConfig: "tsconfig.json",
tsconfig: "tsconfig.json",
},
},
transform: {
Expand Down
99 changes: 54 additions & 45 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@spencerbeggs/aws-cdk-domain-redirect",
"description": "An AWS CDK construct that makes redirecting HTTP(S) requests to a different domain a breeze.",
"version": "1.3.0",
"version": "1.4.0",
"license": "MIT",
"author": "C. Spencer Beggs <[email protected]>",
"scripts": {
Expand Down Expand Up @@ -41,51 +41,51 @@
"registry": "https://registry.npmjs.org/"
},
"devDependencies": {
"@aws-cdk/assert": "^1.39.0",
"@aws-cdk/assets": "^1.39.0",
"@aws-cdk/aws-apigateway": "^1.39.0",
"@aws-cdk/aws-certificatemanager": "^1.39.0",
"@aws-cdk/aws-cloudformation": "^1.39.0",
"@aws-cdk/aws-cloudfront": "^1.39.0",
"@aws-cdk/aws-cloudwatch": "^1.39.0",
"@aws-cdk/aws-cognito": "^1.39.0",
"@aws-cdk/aws-ec2": "^1.39.0",
"@aws-cdk/aws-elasticloadbalancing": "^1.39.0",
"@aws-cdk/aws-elasticloadbalancingv2": "^1.39.0",
"@aws-cdk/aws-events": "^1.39.0",
"@aws-cdk/aws-iam": "^1.39.0",
"@aws-cdk/aws-kms": "^1.39.0",
"@aws-cdk/aws-lambda": "^1.39.0",
"@aws-cdk/aws-logs": "^1.39.0",
"@aws-cdk/aws-route53": "^1.39.0",
"@aws-cdk/aws-route53-targets": "^1.39.0",
"@aws-cdk/aws-s3": "^1.39.0",
"@aws-cdk/aws-s3-assets": "^1.39.0",
"@aws-cdk/aws-sns": "^1.39.0",
"@aws-cdk/aws-sqs": "^1.39.0",
"@aws-cdk/aws-ssm": "^1.39.0",
"@aws-cdk/cdk-assets-schema": "^1.39.0",
"@aws-cdk/cloud-assembly-schema": "^1.39.0",
"@aws-cdk/core": "^1.39.0",
"@aws-cdk/custom-resources": "^1.39.0",
"@aws-cdk/cx-api": "^1.39.0",
"@aws-cdk/region-info": "^1.39.0",
"@types/fs-extra": "^9.0.0",
"@types/jest": "^25.2.3",
"@types/node": "14.0.1",
"@typescript-eslint/eslint-plugin": "^2.26.0",
"@typescript-eslint/parser": "^2.26.0",
"constructs": "^3.0.3",
"@aws-cdk/assert": "^1.88.0",
"@aws-cdk/assets": "^1.88.0",
"@aws-cdk/aws-apigateway": "^1.88.0",
"@aws-cdk/aws-certificatemanager": "^1.88.0",
"@aws-cdk/aws-cloudformation": "^1.88.0",
"@aws-cdk/aws-cloudfront": "^1.88.0",
"@aws-cdk/aws-cloudwatch": "^1.88.0",
"@aws-cdk/aws-cognito": "^1.88.0",
"@aws-cdk/aws-ec2": "^1.88.0",
"@aws-cdk/aws-elasticloadbalancing": "^1.88.0",
"@aws-cdk/aws-elasticloadbalancingv2": "^1.88.0",
"@aws-cdk/aws-events": "^1.88.0",
"@aws-cdk/aws-iam": "^1.88.0",
"@aws-cdk/aws-kms": "^1.88.0",
"@aws-cdk/aws-lambda": "^1.88.0",
"@aws-cdk/aws-logs": "^1.88.0",
"@aws-cdk/aws-route53": "^1.88.0",
"@aws-cdk/aws-route53-targets": "^1.88.0",
"@aws-cdk/aws-s3": "^1.88.0",
"@aws-cdk/aws-s3-assets": "^1.88.0",
"@aws-cdk/aws-sns": "^1.88.0",
"@aws-cdk/aws-sqs": "^1.88.0",
"@aws-cdk/aws-ssm": "^1.88.0",
"@aws-cdk/cdk-assets-schema": "^1.88.0",
"@aws-cdk/cloud-assembly-schema": "^1.88.0",
"@aws-cdk/core": "^1.88.0",
"@aws-cdk/custom-resources": "^1.88.0",
"@aws-cdk/cx-api": "^1.88.0",
"@aws-cdk/region-info": "^1.88.0",
"@types/fs-extra": "^9.0.6",
"@types/jest": "^26.0.20",
"@types/node": "14.14.25",
"@typescript-eslint/eslint-plugin": "^4.14.2",
"@typescript-eslint/parser": "^4.14.2",
"constructs": "^3.3.14",
"coveralls": "^3.0.9",
"eslint": "^7.0.0",
"eslint-config-prettier": "^6.10.0",
"eslint-plugin-prettier": "^3.1.2",
"fs-extra": "^9.0.0",
"jest": "^26.0.1",
"prettier": "^2.0.2",
"ts-jest": "^26.0.0",
"ts-node": "^8.6.2",
"typescript": "^3.9.2"
"eslint": "^7.19.0",
"eslint-config-prettier": "^7.2.0",
"eslint-plugin-prettier": "^3.3.1",
"fs-extra": "^9.1.0",
"jest": "^26.6.3",
"prettier": "^2.2.1",
"ts-jest": "^26.5.0",
"ts-node": "^9.1.1",
"typescript": "^4.1.3"
},
"peerDependencies": {
"@aws-cdk/assert": "^1.39.0",
Expand Down Expand Up @@ -118,5 +118,14 @@
"@aws-cdk/cx-api": "^1.39.0",
"@aws-cdk/region-info": "^1.39.0",
"constructs": "^3.0.3"
},
"dependencies": {
"@aws-cdk/aws-apigatewayv2": "^1.88.0",
"@aws-cdk/aws-applicationautoscaling": "^1.88.0",
"@aws-cdk/aws-autoscaling-common": "^1.88.0",
"@aws-cdk/aws-codeguruprofiler": "^1.88.0",
"@aws-cdk/aws-ecr": "^1.88.0",
"@aws-cdk/aws-ecr-assets": "^1.88.0",
"@aws-cdk/aws-efs": "^1.88.0"
}
}
Loading

0 comments on commit ec7b989

Please sign in to comment.