Skip to content

Commit

Permalink
generate .env.e2e to be able to run e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ebisbe committed Jul 12, 2024
1 parent 10b142c commit a8993a4
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 3 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/github-actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ jobs:
run: |
pnpm install
pnpm test
pnpm sls deploy
pnpm sls deploy
pnpm test-e2e
4 changes: 3 additions & 1 deletion __tests__/e2e.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { describe, expect, it } from "@jest/globals";
import { config } from "dotenv";
config({ path: ".env.e2e" });

const { endpoint } = process.env;
const { API_GATEWAY_URL: endpoint } = process.env;

const wrapper = ({ path = "", method, body }) => {
const headers = { Accept: "application/json" };
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"prettier": "3.3.2",
"serverless": "^4.1.11",
"serverless-iam-roles-per-function": "^3.2.0",
"serverless-plugin-scripts": "^1.0.2",
"serverless-step-functions": "^3.21.0",
"ts-jest": "^29.1.5",
"typescript": "^5.5.3",
Expand Down
8 changes: 8 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 34 additions & 0 deletions post-deploy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { execSync } from "child_process";
import { writeFileSync } from "fs";
import { parseArgs } from "util";

const args = process.argv;
const options = {
name: {
type: "string",
},
region: {
type: "string",
},
};
const { values } = parseArgs({
args,
options,
allowPositionals: true,
});

// Execute the AWS CLI command to get the CloudFormation outputs
const output = execSync(
`aws cloudformation describe-stacks --stack-name ${values.name} --region ${values.region} --query "Stacks[0].Outputs" --output json`,
);

// Parse the output
const outputs = JSON.parse(output);

// Find the API Gateway URL
const apiGatewayUrl = outputs.find(
(o) => o.OutputKey === "HttpApiUrl",
).OutputValue;

// Write the URL to the .env file
writeFileSync(".env.e2e", `API_GATEWAY_URL=${apiGatewayUrl}\n`);
18 changes: 17 additions & 1 deletion serverless.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { env } from "process";

import resources from "./src/resources";
import { WeddingTable } from "./src/resources/ddb";
import { stepFunctions } from "./src/stepFunctions";
Expand All @@ -20,6 +22,7 @@ const serverlessConfig: ServerlessExtended = {
provider: {
name: "aws",
stage: "dev",
region: "us-east-1",
runtime: "nodejs20.x",
logs: {
httpApi: {
Expand Down Expand Up @@ -47,7 +50,20 @@ const serverlessConfig: ServerlessExtended = {
},
},

plugins: ["serverless-iam-roles-per-function", "serverless-step-functions"],
plugins: [
"serverless-iam-roles-per-function",
"serverless-step-functions",
"serverless-plugin-scripts",
],

custom: {
scripts: {
hooks: {
"deploy:finalize":
"node post-deploy.js --name=${self:service} --region=${self:provider.region}",
},
},
},

stepFunctions,

Expand Down

0 comments on commit a8993a4

Please sign in to comment.