Skip to content

Commit

Permalink
fix: update jest
Browse files Browse the repository at this point in the history
  • Loading branch information
ambreelmee committed Sep 14, 2022
1 parent 3b9d54d commit 677c6a2
Show file tree
Hide file tree
Showing 9 changed files with 1,314 additions and 3,057 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -61,7 +61,7 @@ aws-spa deploy app.example.com/$(git branch | grep * | cut -d ' ' -f2)

- `--wait`: Wait for CloudFront distribution to be deployed & cache invalidation to be completed. If you choose not to wait (default), you won't see site changes as soon as the command ends.
- `--directory`: The directory where the static files have been generated. It must contain an index.html. Default is `build`.
- `--credentials`: This option enables basic auth for the full s3 bucket (even if the domainName specifies a path). Credentials must be of the form "username:password". Basic auth is the recommened way to avoid search engine indexation of non-production apps (such as staging). You can also set credentials through the environment variable "AWS_SPA_CREDENTIALS" (the argument will override the environment variable if both are defined)
- `--credentials`: This option enables basic auth for the full s3 bucket (even if the domainName specifies a path). Credentials must be of the form "username:password". Basic auth is the recommended way to avoid search engine indexation of non-production apps (such as staging). You can also set credentials through the environment variable "AWS_SPA_CREDENTIALS" (the argument will override the environment variable if both are defined)
- `--cacheInvalidation`: cache invalidation to be done in CloudFront. Default is `*`: all files are invalidated. For a `create-react-app` app you only need to invalidate `/index.html`
- `--cacheBustedPrefix`: a folder where files are suffixed with a hash (cash busting). Their `cache-control` value is set to `max-age=31536000`. For a `create-react-app` app you can specify `static/`.
- `--noPrompt`: Disable confirm message that prompts on non CI environments (env CI=true).
Expand Down
5 changes: 2 additions & 3 deletions package.json
Expand Up @@ -66,16 +66,15 @@
"@babel/preset-env": "^7.19.0",
"@babel/preset-typescript": "^7.18.6",
"@types/adm-zip": "^0.5.0",
"@types/aws-sdk": "^2.7.0",
"@types/inquirer": "^8.2.3",
"@types/jest": "^24.0.22",
"@types/jest": "^29.0.2",
"@types/mime-types": "^2.1.1",
"@types/node": "^16.11.7",
"@types/rimraf": "^3.0.2",
"@types/yargs": "^17.0.12",
"codecov": "^3.8.3",
"husky": "^8.0.1",
"jest": "^24.9.0",
"jest": "^29.0.3",
"rimraf": "^3.0.2",
"semantic-release": "^19.0.5",
"typescript": "^4.8.3"
Expand Down
109 changes: 58 additions & 51 deletions src/acm.spec.ts
@@ -1,7 +1,14 @@
import { domainNameMatch, getCertificateARN, createCertificate } from "./acm";
import { createCertificate, domainNameMatch, getCertificateARN } from "./acm";
import { acm, route53 } from "./aws-services";
import { awsResolve } from "./test-helper";

jest.mock("inquirer", () => {
return {
__esModule: true,
default: { prompt: jest.fn() },
};
});

describe("acm", () => {
describe("getCertificateARN", () => {
const listCertificatesMock = jest.spyOn(acm, "listCertificates");
Expand All @@ -19,18 +26,18 @@ describe("acm", () => {
awsResolve({
CertificateSummaryList: [
{
CertificateArn: "arn:aws:acm:us-east-1:123456789:certificate/xxx"
}
]
CertificateArn: "arn:aws:acm:us-east-1:123456789:certificate/xxx",
},
],
})
);
describeCertificateMock.mockReturnValue(
awsResolve({
Certificate: {
Status: "ISSUED",
DomainName: "*.example.com",
CertificateArn: "arn:aws:acm:us-east-1:123456789:certificate/xxx"
}
CertificateArn: "arn:aws:acm:us-east-1:123456789:certificate/xxx",
},
})
);
const arn = await getCertificateARN("hello.example.com");
Expand All @@ -45,20 +52,20 @@ describe("acm", () => {
CertificateSummaryList: [
{
CertificateArn:
"arn:aws:acm:us-east-1:123456789:certificate/xxx"
}
"arn:aws:acm:us-east-1:123456789:certificate/xxx",
},
],
NextToken: "xxx"
NextToken: "xxx",
})
)
.mockReturnValueOnce(
awsResolve({
CertificateSummaryList: [
{
CertificateArn:
"arn:aws:acm:us-east-1:123456789:certificate/yyy"
}
]
"arn:aws:acm:us-east-1:123456789:certificate/yyy",
},
],
})
);
describeCertificateMock
Expand All @@ -67,17 +74,17 @@ describe("acm", () => {
Certificate: {
Status: "ISSUED",
DomainName: "hello2.example.com",
CertificateArn: "arn:aws:acm:us-east-1:123456789:certificate/xxx"
}
CertificateArn: "arn:aws:acm:us-east-1:123456789:certificate/xxx",
},
})
)
.mockReturnValueOnce(
awsResolve({
Certificate: {
Status: "ISSUED",
DomainName: "*.example.com",
CertificateArn: "arn:aws:acm:us-east-1:123456789:certificate/yyy"
}
CertificateArn: "arn:aws:acm:us-east-1:123456789:certificate/yyy",
},
})
);
const arn = await getCertificateARN("hello.example.com");
Expand All @@ -90,9 +97,9 @@ describe("acm", () => {
awsResolve({
CertificateSummaryList: [
{
CertificateArn: "arn:aws:acm:us-east-1:123456789:certificate/xxx"
}
]
CertificateArn: "arn:aws:acm:us-east-1:123456789:certificate/xxx",
},
],
})
);
describeCertificateMock.mockReturnValue(
Expand All @@ -101,8 +108,8 @@ describe("acm", () => {
DomainName: "example.com",
Status: "ISSUED",
CertificateArn: "arn:aws:acm:us-east-1:123456789:certificate/xxx",
SubjectAlternativeNames: ["staging.example.com", "*.example.com"]
}
SubjectAlternativeNames: ["staging.example.com", "*.example.com"],
},
})
);
const arn = await getCertificateARN("hello.example.com");
Expand All @@ -114,18 +121,18 @@ describe("acm", () => {
awsResolve({
CertificateSummaryList: [
{
CertificateArn: "arn:aws:acm:us-east-1:123456789:certificate/xxx"
}
]
CertificateArn: "arn:aws:acm:us-east-1:123456789:certificate/xxx",
},
],
})
);
describeCertificateMock.mockReturnValue(
awsResolve({
Certificate: {
DomainName: "*.example.com",
Status: "REVOKED",
CertificateArn: "arn:aws:acm:us-east-1:123456789:certificate/xxx"
}
CertificateArn: "arn:aws:acm:us-east-1:123456789:certificate/xxx",
},
})
);
const arn = await getCertificateARN("hello.example.com");
Expand All @@ -137,18 +144,18 @@ describe("acm", () => {
awsResolve({
CertificateSummaryList: [
{
CertificateArn: "arn:aws:acm:us-east-1:123456789:certificate/xxx"
}
]
CertificateArn: "arn:aws:acm:us-east-1:123456789:certificate/xxx",
},
],
})
);
describeCertificateMock.mockReturnValue(
awsResolve({
Certificate: {
DomainName: "example.com",
Status: "ISSUED",
CertificateArn: "arn:aws:acm:us-east-1:123456789:certificate/xxx"
}
CertificateArn: "arn:aws:acm:us-east-1:123456789:certificate/xxx",
},
})
);
const arn = await getCertificateARN("hello.example.com");
Expand All @@ -161,13 +168,13 @@ describe("acm", () => {
CertificateSummaryList: [
{
CertificateArn:
"arn:aws:acm:us-east-1:123456789:certificate/pending"
"arn:aws:acm:us-east-1:123456789:certificate/pending",
},
{
CertificateArn:
"arn:aws:acm:us-east-1:123456789:certificate/issued"
}
]
"arn:aws:acm:us-east-1:123456789:certificate/issued",
},
],
})
);
describeCertificateMock
Expand All @@ -177,8 +184,8 @@ describe("acm", () => {
DomainName: "*.example.com",
Status: "PENDING_VALIDATION",
CertificateArn:
"arn:aws:acm:us-east-1:123456789:certificate/pending"
}
"arn:aws:acm:us-east-1:123456789:certificate/pending",
},
})
)
.mockReturnValueOnce(
Expand All @@ -187,8 +194,8 @@ describe("acm", () => {
DomainName: "hello.example.com",
Status: "ISSUED",
CertificateArn:
"arn:aws:acm:us-east-1:123456789:certificate/issued"
}
"arn:aws:acm:us-east-1:123456789:certificate/issued",
},
})
);
const arn = await getCertificateARN("hello.example.com");
Expand All @@ -201,9 +208,9 @@ describe("acm", () => {
CertificateSummaryList: [
{
CertificateArn:
"arn:aws:acm:us-east-1:123456789:certificate/pending"
}
]
"arn:aws:acm:us-east-1:123456789:certificate/pending",
},
],
})
);
describeCertificateMock.mockReturnValue(
Expand All @@ -212,8 +219,8 @@ describe("acm", () => {
DomainName: "*.example.com",
Status: "PENDING_VALIDATION",
CertificateArn:
"arn:aws:acm:us-east-1:123456789:certificate/pending"
}
"arn:aws:acm:us-east-1:123456789:certificate/pending",
},
})
);
waitForMock.mockReturnValue(awsResolve());
Expand Down Expand Up @@ -270,7 +277,7 @@ describe("acm", () => {
it("should request a certificate", async () => {
requestCertificateMock.mockReturnValue(
awsResolve({
CertificateArn: "arn:aws:acm:us-east-1:123456789:certificate/xxx"
CertificateArn: "arn:aws:acm:us-east-1:123456789:certificate/xxx",
})
);
describeCertificateMock.mockReturnValue(
Expand All @@ -282,11 +289,11 @@ describe("acm", () => {
ResourceRecord: {
Name: "_sOmESTrAnGeChArAcTeRs.example.com",
Type: "CNAME",
Value: "_sOmESTrAnGeChArAcTeRs"
}
}
]
}
Value: "_sOmESTrAnGeChArAcTeRs",
},
},
],
},
})
);
changeResourceRecordSetsMock.mockReturnValue(awsResolve());
Expand All @@ -299,7 +306,7 @@ describe("acm", () => {
expect(requestCertificateParams.ValidationMethod).toEqual("DNS");
expect(waitForMock).toHaveBeenCalledWith("certificateValidated", {
CertificateArn: "arn:aws:acm:us-east-1:123456789:certificate/xxx",
$waiter: { delay: 10 }
$waiter: { delay: 10 },
});

expect(changeResourceRecordSetsMock).toHaveBeenCalledTimes(1);
Expand Down
9 changes: 7 additions & 2 deletions src/prompt.spec.ts
@@ -1,7 +1,12 @@
import * as inquirer from "inquirer";
import inquirer from "inquirer";
import { predeployPrompt } from "./prompt";

jest.mock("inquirer");
jest.mock("inquirer", () => {
return {
__esModule: true,
default: { prompt: jest.fn() },
};
});

describe("prompt", () => {
beforeEach(() => {
Expand Down
4 changes: 2 additions & 2 deletions src/prompt.ts
@@ -1,4 +1,4 @@
import { prompt } from "inquirer";
import inquirer from "inquirer";
import { logger } from "./logger";

export const predeployPrompt = async (ciEnv: boolean, noPrompt: boolean) => {
Expand All @@ -10,7 +10,7 @@ export const predeployPrompt = async (ciEnv: boolean, noPrompt: boolean) => {
`💡 If you don\'t want this message to prompt, either set CI=true in your env variables or use the "--noPrompt" option.`
);

const { continueDeploy } = await prompt([
const { continueDeploy } = await inquirer.prompt([
{
type: "confirm",
name: "continueDeploy",
Expand Down
15 changes: 11 additions & 4 deletions src/route53.spec.ts
@@ -1,6 +1,13 @@
import { route53 } from "./aws-services";
import { createHostedZone, findHostedZone, updateRecord } from "./route53";
import { awsResolve } from "./test-helper";
import { findHostedZone, createHostedZone, updateRecord } from "./route53";

jest.mock("inquirer", () => {
return {
__esModule: true,
default: { prompt: jest.fn() },
};
});

describe("route53", () => {
describe("findHostedZone", () => {
Expand All @@ -16,7 +23,7 @@ describe("route53", () => {
.mockReturnValueOnce(
awsResolve({
HostedZones: [{ Name: "example1.com" }],
NextMarker: "xxx"
NextMarker: "xxx",
})
)
.mockReturnValueOnce(awsResolve({ HostedZones: [matchingHostedZone] }));
Expand All @@ -30,7 +37,7 @@ describe("route53", () => {
const matchingHostedZone = { Name: "example.com." };
listHostedZonesMock.mockReturnValue(
awsResolve({
HostedZones: [matchingHostedZone]
HostedZones: [matchingHostedZone],
})
);

Expand All @@ -42,7 +49,7 @@ describe("route53", () => {
it("should return null if there is no hosted found", async () => {
listHostedZonesMock.mockReturnValue(
awsResolve({
HostedZones: [{ Name: "example2.com." }]
HostedZones: [{ Name: "example2.com." }],
})
);

Expand Down
7 changes: 4 additions & 3 deletions src/route53.ts
@@ -1,9 +1,10 @@
import { ResourceRecord } from "aws-sdk/clients/acm";
import { HostedZone } from "aws-sdk/clients/route53";
import { prompt } from "inquirer";
import inquirer from "inquirer";
import { getAll } from "./aws-helper";
import { route53 } from "./aws-services";
import { logger } from "./logger";

export const findHostedZone = async (domainName: string) => {
logger.info(
`[route53] 🔍 Looking for a hosted zone matching "${domainName}"...`
Expand Down Expand Up @@ -80,7 +81,7 @@ export const needsUpdateRecord = async (
return false;
}

const { continueUpdate } = await prompt([
const { continueUpdate } = await inquirer.prompt([
{
type: "confirm",
name: "continueUpdate",
Expand All @@ -107,7 +108,7 @@ export const needsUpdateRecord = async (
return false;
}

const { continueUpdate } = await prompt([
const { continueUpdate } = await inquirer.prompt([
{
type: "confirm",
name: "continueUpdate",
Expand Down

0 comments on commit 677c6a2

Please sign in to comment.