Skip to content
This repository was archived by the owner on Jan 28, 2025. It is now read-only.

Commit 75445e4

Browse files
authored
chore(aws-lambda): convert package to typescript (#1305)
1 parent 8b59562 commit 75445e4

File tree

13 files changed

+2745
-328
lines changed

13 files changed

+2745
-328
lines changed

packages/serverless-components/aws-lambda/__mocks__/aws-sdk.mock.js

Lines changed: 0 additions & 109 deletions
This file was deleted.
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
const promisifyMock = (mockFn) => {
2+
const promise = jest.fn();
3+
mockFn.mockImplementation(() => ({
4+
promise
5+
}));
6+
7+
return promise;
8+
};
9+
10+
export const mockCreateFunction = jest.fn();
11+
export const mockCreateFunctionPromise = promisifyMock(mockCreateFunction);
12+
13+
export const mockPublishVersion = jest.fn();
14+
export const mockPublishVersionPromise = promisifyMock(mockPublishVersion);
15+
16+
export const mockGetFunctionConfiguration = jest.fn();
17+
export const mockGetFunctionConfigurationPromise = promisifyMock(
18+
mockGetFunctionConfiguration
19+
);
20+
21+
export const mockUpdateFunctionCode = jest.fn();
22+
export const mockUpdateFunctionCodePromise = promisifyMock(
23+
mockUpdateFunctionCode
24+
);
25+
26+
export const mockUpdateFunctionConfiguration = jest.fn();
27+
export const mockUpdateFunctionConfigurationPromise = promisifyMock(
28+
mockUpdateFunctionConfiguration
29+
);
30+
31+
export const mockCreateQueue = jest.fn();
32+
export const mockCreateQueuePromise = promisifyMock(mockCreateQueue);
33+
34+
export const mockGetQueueAttributes = jest.fn();
35+
export const mockGetQueueAttributesPromise = promisifyMock(
36+
mockGetQueueAttributes
37+
);
38+
39+
export const mockDeleteQueue = jest.fn();
40+
export const mockDeleteQueuePromise = promisifyMock(mockDeleteQueue);
41+
42+
export const mockListEventSourceMappings = jest.fn();
43+
export const mockListEventSourceMappingsPromise = promisifyMock(
44+
mockListEventSourceMappings
45+
);
46+
47+
export const mockCreateEventSourceMapping = jest.fn();
48+
export const mockCreateEventSourceMappingPromise = promisifyMock(
49+
mockCreateEventSourceMapping
50+
);
51+
52+
export const mockGetCallerIdentityMapping = jest.fn();
53+
export const mockGetCallerIdentityMappingPromise = promisifyMock(
54+
mockGetCallerIdentityMapping
55+
);
56+
57+
export const mockListTags = jest.fn();
58+
export const mockListTagsPromise = promisifyMock(mockListTags);
59+
export const mockTagResource = jest.fn();
60+
export const mockTagResourcePromise = promisifyMock(mockTagResource);
61+
export const mockUntagResource = jest.fn();
62+
export const mockUntagResourcePromise = promisifyMock(mockUntagResource);
63+
64+
export default {
65+
SQS: jest.fn(() => ({
66+
createQueue: mockCreateQueue,
67+
getQueueAttributes: mockGetQueueAttributes,
68+
deleteQueue: mockDeleteQueue
69+
})),
70+
Lambda: jest.fn(() => ({
71+
listEventSourceMappings: mockListEventSourceMappings,
72+
createEventSourceMapping: mockCreateEventSourceMapping,
73+
createFunction: mockCreateFunction,
74+
publishVersion: mockPublishVersion,
75+
getFunctionConfiguration: mockGetFunctionConfiguration,
76+
updateFunctionCode: mockUpdateFunctionCode,
77+
updateFunctionConfiguration: mockUpdateFunctionConfiguration,
78+
listTags: mockListTags,
79+
tagResource: mockTagResource,
80+
untagResource: mockUntagResource
81+
}))
82+
};

packages/serverless-components/aws-lambda/__tests__/publishVersion.test.js renamed to packages/serverless-components/aws-lambda/__tests__/publishVersion.test.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
const { createComponent, createTmpDir } = require("../test-utils");
1+
import { createComponent, createTmpDir } from "../test-utils";
22

3-
const {
3+
import {
44
mockCreateFunction,
55
mockCreateFunctionPromise,
66
mockPublishVersion,
@@ -12,16 +12,20 @@ const {
1212
mockListTagsPromise,
1313
mockTagResource,
1414
mockUntagResource
15-
} = require("aws-sdk");
15+
} from "../__mocks__/aws-sdk.mock";
1616

1717
jest.mock("aws-sdk", () => require("../__mocks__/aws-sdk.mock"));
1818

1919
const mockIamRole = jest.fn();
2020
jest.mock("@serverless/aws-iam-role", () =>
2121
jest.fn(() => {
22-
const iamRole = mockIamRole;
23-
iamRole.init = () => {};
24-
iamRole.default = () => {};
22+
const iamRole: any = mockIamRole;
23+
iamRole.init = () => {
24+
// intentional
25+
};
26+
iamRole.default = () => {
27+
// intentional
28+
};
2529
iamRole.context = {};
2630
return iamRole;
2731
})
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module.exports = {
2+
presets: [
3+
["@babel/preset-env", { targets: { node: "current" } }],
4+
"@babel/preset-typescript"
5+
]
6+
};
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
clearMocks: true
3+
};

packages/serverless-components/aws-lambda/package.json

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,28 @@
1717
"url": "https://github.com/serverless-nextjs/serverless-next.js/issues"
1818
},
1919
"homepage": "https://github.com/serverless-nextjs/serverless-next.js#readme",
20+
"scripts": {
21+
"test": "jest",
22+
"clean": "yarn rimraf dist",
23+
"build": "tsc -p tsconfig.build.json",
24+
"prepare": "yarn clean && yarn build"
25+
},
26+
"devDependencies": {
27+
"@types/archiver": "^5.1.0",
28+
"@types/fs-extra": "^9.0.11",
29+
"@types/lodash": "^4.14.170",
30+
"@types/node": "^15.12.5",
31+
"@types/ramda": "^0.27.41",
32+
"jest": "^27.0.5",
33+
"rimraf": "^3.0.2",
34+
"typescript": "^4.3.4"
35+
},
2036
"dependencies": {
2137
"@serverless/aws-iam-role": "^1.0.0",
2238
"@serverless/aws-lambda-layer": "^1.0.0",
2339
"@serverless/aws-s3": "^4.2.0",
40+
"@serverless/core": "^1.1.2",
41+
"aws-sdk": "^2.935.0",
2442
"archiver": "^5.3.0",
2543
"fs-extra": "^9.1.0",
2644
"globby": "^11.0.1",
@@ -29,6 +47,10 @@
2947
},
3048
"peerDependencies": {
3149
"@serverless/core": "^1.1.2",
32-
"aws-sdk": "^2.702.0"
50+
"aws-sdk": "^2.935.0"
51+
},
52+
"jest": {
53+
"preset": "ts-jest",
54+
"testEnvironment": "node"
3355
}
3456
}

0 commit comments

Comments
 (0)