Skip to content

Commit

Permalink
Move test-lib into src/index
Browse files Browse the repository at this point in the history
  • Loading branch information
agwhi committed May 14, 2021
1 parent 3af4d55 commit 7a151ce
Show file tree
Hide file tree
Showing 7 changed files with 2,022 additions and 97 deletions.
11 changes: 10 additions & 1 deletion .all-contributorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,21 @@
{
"login": "hamilton-s",
"name": "Sarah Hamilton",
"avatar_url": "https://https://avatars.githubusercontent.com/hamilton-s",
"avatar_url": "https://avatars.githubusercontent.com/hamilton-s",
"profile": "https://github.com/hamilton-s",
"contributions": [
"code",
"doc",
]
},
{
"login": "aghwi",
"name": "Alexander White",
"avatar_url": "https://avatars.githubusercontent.com/agwhi",
"profile": "https://github.com/agwhi",
"contributions": [
"code",
]
}
],
"contributorsPerLine": 7,
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
node_modules
lib
build
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2021 Theodo UK

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
40 changes: 37 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,55 @@
{
"name": "sls-test-tools",
"version": "1.0.0",
"version": "1.0.0-alpha",
"description": "Custom Jest Assertions for Serverless Projects",
"main": "lib/index.js",
"directories": {
"lib": "lib"
},
"repository": "[email protected]:BenEllerby/sls-test-tools.git",
"author": "Ben Ellerby",
"license": "MIT",
"scripts": {
"build": "babel ./src --out-dir lib",
"build-maps": "babel ./src --out-dir lib --source-maps",
"dev": "babel ./src --out-dir lib --watch",
"lint": "eslint ./src",
"fix": "yarn lint --fix"
"fix": "yarn lint --fix",
"release": "release-it"
},
"dependencies": {
"aws-sdk": "^2.711.0",
"import-all.macro": "^3.1.0"
},
"devDependencies": {
"@babel/cli": "^7.5.5",
"@babel/core": "^7.5.5",
"@babel/preset-env": "^7.5.5",
"babel-plugin-macros": "^3.1.0",
"eslint": "^7.25.0",
"eslint-config-airbnb-base": "^14.2.1",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-prettier": "^3.4.0",
"prettier": "^2.2.1",
"release-it": "^14.6.1"
}
},
"babel": {
"presets": [
[
"@babel/preset-env",
{
"targets": {
"node": true
}
}
]
],
"plugins": [
"macros"
]
},
"files": [
"lib/**/*.js"
]
}
72 changes: 72 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,77 @@
import AWS from "aws-sdk";
import matchers from "./assertions";

const profileArg = process.argv.filter((x) => x.startsWith("--profile="))[0];
const profile = profileArg ? profileArg.split("=")[1] : "default";
const stackArg = process.argv.filter((x) => x.startsWith("--stack="))[0];
const regionArg = process.argv.filter((x) => x.startsWith("--region="))[0];
const region = regionArg ? regionArg.split("=")[1] : "eu-west-2";

export const stackName = stackArg.split("=")[1];

let creds;

if (process.env.AWS_ACCESS_KEY_ID && process.env.AWS_SECRET_ACCESS_KEY) {
creds = new AWS.Credentials({
accessKeyId: process.env.AWS_ACCESS_KEY_ID,
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
sessionToken: process.env.AWS_SESSION_TOKEN,
});
} else {
creds = new AWS.SharedIniFileCredentials({
profile,
callback: (err) => {
if (err) {
console.error(`SharedIniFileCreds Error: ${err}`);
}
},
});
}

AWS.config.credentials = creds;
AWS.config.region = region;
const cloudformation = new AWS.CloudFormation();
export const ssm = new AWS.SSM();
export const lambda = new AWS.Lambda();
export const sqs = new AWS.SQS();
export const eventBridge = new AWS.EventBridge();
export const s3 = new AWS.S3();

export const getStackResources = (stackName) =>
cloudformation
.describeStacks({ StackName: stackName })
.promise()
.catch((error) => {
console.error(error);
});

const apigateway = new AWS.APIGateway();
let apiKey = null;
export const getOptions = async () => {
if (!apiKey) {
const resources = await cloudformation
.listStackResources({ StackName: stackName })
.promise();
const id = resources.StackResourceSummaries.find(
(r) => r.ResourceType === "AWS::ApiGateway::ApiKey"
).PhysicalResourceId;
const params = {
apiKey: id,
includeValue: true,
};
const data = await apigateway.getApiKey(params).promise();
apiKey = data.value;
}

return {
method: "POST",
headers: {
"x-api-key": apiKey,
"Content-Type": "application/json",
},
};
};

const jestExpect = global.expect;

if (jestExpect !== undefined) {
Expand Down
75 changes: 0 additions & 75 deletions test-lib.js

This file was deleted.

Loading

0 comments on commit 7a151ce

Please sign in to comment.