@tsed/platform-serverless-testing 6.91.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/PlatformServerlessTest.d.ts +46 -0
- package/lib/cjs/PlatformServerlessTest.js +147 -0
- package/lib/cjs/PlatformServerlessTest.js.map +1 -0
- package/lib/cjs/createFakeContext.d.ts +2 -0
- package/lib/cjs/createFakeContext.js +18 -0
- package/lib/cjs/createFakeContext.js.map +1 -0
- package/lib/cjs/createFakeEvent.d.ts +2 -0
- package/lib/cjs/createFakeEvent.js +35 -0
- package/lib/cjs/createFakeEvent.js.map +1 -0
- package/lib/cjs/index.d.ts +3 -0
- package/lib/cjs/index.js +7 -0
- package/lib/cjs/index.js.map +1 -0
- package/lib/esm/PlatformServerlessTest.js +142 -0
- package/lib/esm/PlatformServerlessTest.js.map +1 -0
- package/lib/esm/createFakeContext.js +14 -0
- package/lib/esm/createFakeContext.js.map +1 -0
- package/lib/esm/createFakeEvent.js +31 -0
- package/lib/esm/createFakeEvent.js.map +1 -0
- package/lib/esm/index.js +4 -0
- package/lib/esm/index.js.map +1 -0
- package/lib/types/PlatformServerlessTest.d.ts +46 -0
- package/lib/types/createFakeContext.d.ts +2 -0
- package/lib/types/createFakeEvent.d.ts +2 -0
- package/lib/types/index.d.ts +3 -0
- package/package.json +71 -0
- package/readme.md +76 -0
- package/src/PlatformServerlessTest.ts +198 -0
- package/src/createFakeContext.ts +15 -0
- package/src/createFakeEvent.ts +32 -0
- package/src/index.ts +3 -0
- package/tsconfig.compile.esm.json +23 -0
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { DITest } from "@tsed/di";
|
|
2
|
+
import { APIGatewayEventDefaultAuthorizerContext, APIGatewayProxyEventBase, APIGatewayProxyHandler } from "aws-lambda";
|
|
3
|
+
import { APIGatewayProxyResult } from "aws-lambda/trigger/api-gateway-proxy";
|
|
4
|
+
import { Type } from "@tsed/core";
|
|
5
|
+
import { PlatformBuilder, PlatformBuilderSettings } from "@tsed/common";
|
|
6
|
+
export interface LambdaPromiseResult extends Promise<APIGatewayProxyResult> {
|
|
7
|
+
}
|
|
8
|
+
export declare class LambdaClientRequest extends Promise<APIGatewayProxyResult> {
|
|
9
|
+
event: APIGatewayProxyEventBase<APIGatewayEventDefaultAuthorizerContext>;
|
|
10
|
+
context: import("aws-lambda").Context;
|
|
11
|
+
static call(lambdaName: string): LambdaClientRequest;
|
|
12
|
+
static get(path: string, options?: Partial<APIGatewayProxyEventBase<APIGatewayEventDefaultAuthorizerContext>>): LambdaClientRequest;
|
|
13
|
+
static post(path: string, body?: any, options?: Partial<APIGatewayProxyEventBase<APIGatewayEventDefaultAuthorizerContext>>): LambdaClientRequest;
|
|
14
|
+
static put(path: string, body?: any, options?: Partial<APIGatewayProxyEventBase<APIGatewayEventDefaultAuthorizerContext>>): LambdaClientRequest;
|
|
15
|
+
static patch(path: string, body?: any, options?: Partial<APIGatewayProxyEventBase<APIGatewayEventDefaultAuthorizerContext>>): LambdaClientRequest;
|
|
16
|
+
static delete(path: string, body?: any, options?: Partial<APIGatewayProxyEventBase<APIGatewayEventDefaultAuthorizerContext>>): LambdaClientRequest;
|
|
17
|
+
get(path: string, options?: Partial<APIGatewayProxyEventBase<APIGatewayEventDefaultAuthorizerContext>>): this;
|
|
18
|
+
post(path: string, body?: any, options?: Partial<APIGatewayProxyEventBase<APIGatewayEventDefaultAuthorizerContext>>): this;
|
|
19
|
+
patch(path: string, body?: any, options?: Partial<APIGatewayProxyEventBase<APIGatewayEventDefaultAuthorizerContext>>): this;
|
|
20
|
+
put(path: string, body?: any, options?: Partial<APIGatewayProxyEventBase<APIGatewayEventDefaultAuthorizerContext>>): this;
|
|
21
|
+
delete(path: string, body?: any, options?: Partial<APIGatewayProxyEventBase<APIGatewayEventDefaultAuthorizerContext>>): this;
|
|
22
|
+
query(query: any): this;
|
|
23
|
+
params(pathParameters: any): this;
|
|
24
|
+
headers(headers: Record<string, any>): this;
|
|
25
|
+
body(body: any): this;
|
|
26
|
+
protected init(lambda: string, resolve: Function, reject: Function): void;
|
|
27
|
+
}
|
|
28
|
+
export declare class PlatformServerlessTest extends DITest {
|
|
29
|
+
static callbacks: Record<string, APIGatewayProxyHandler>;
|
|
30
|
+
static instance: any;
|
|
31
|
+
static request: typeof LambdaClientRequest;
|
|
32
|
+
static bootstrap(serverless: {
|
|
33
|
+
bootstrap: (server: Type<any>, settings: PlatformBuilderSettings) => PlatformBuilder;
|
|
34
|
+
}, { server, ...settings }: PlatformBuilderSettings & {
|
|
35
|
+
server: Type<any>;
|
|
36
|
+
}): () => Promise<any>;
|
|
37
|
+
static bootstrap(serverless: {
|
|
38
|
+
bootstrap: (settings: Partial<TsED.Configuration> & {
|
|
39
|
+
lambda?: Type[];
|
|
40
|
+
}) => any;
|
|
41
|
+
}, { server, ...settings }: PlatformBuilderSettings): () => Promise<any>;
|
|
42
|
+
/**
|
|
43
|
+
* Resets the test injector of the test context, so it won't pollute your next test. Call this in your `tearDown` logic.
|
|
44
|
+
*/
|
|
45
|
+
static reset(): Promise<void>;
|
|
46
|
+
}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PlatformServerlessTest = exports.LambdaClientRequest = void 0;
|
|
4
|
+
const di_1 = require("@tsed/di");
|
|
5
|
+
const createFakeEvent_1 = require("./createFakeEvent");
|
|
6
|
+
const createFakeContext_1 = require("./createFakeContext");
|
|
7
|
+
const core_1 = require("@tsed/core");
|
|
8
|
+
class LambdaClientRequest extends Promise {
|
|
9
|
+
constructor() {
|
|
10
|
+
super(...arguments);
|
|
11
|
+
this.event = (0, createFakeEvent_1.createFakeEvent)();
|
|
12
|
+
this.context = (0, createFakeContext_1.createFakeContext)();
|
|
13
|
+
}
|
|
14
|
+
static call(lambdaName) {
|
|
15
|
+
const resolvers = {};
|
|
16
|
+
const promise = new LambdaClientRequest((resolve, reject) => {
|
|
17
|
+
resolvers.resolve = resolve;
|
|
18
|
+
resolvers.reject = reject;
|
|
19
|
+
});
|
|
20
|
+
promise.init(lambdaName, resolvers.resolve, resolvers.reject);
|
|
21
|
+
return promise;
|
|
22
|
+
}
|
|
23
|
+
static get(path, options = {}) {
|
|
24
|
+
return this.call("handler").get(path, options);
|
|
25
|
+
}
|
|
26
|
+
static post(path, body, options = {}) {
|
|
27
|
+
return this.call("handler").post(path, body, options);
|
|
28
|
+
}
|
|
29
|
+
static put(path, body, options = {}) {
|
|
30
|
+
return this.call("handler").put(path, body, options);
|
|
31
|
+
}
|
|
32
|
+
static patch(path, body, options = {}) {
|
|
33
|
+
return this.call("handler").patch(path, body, options);
|
|
34
|
+
}
|
|
35
|
+
static delete(path, body, options = {}) {
|
|
36
|
+
return this.call("handler").delete(path, body, options);
|
|
37
|
+
}
|
|
38
|
+
get(path, options = {}) {
|
|
39
|
+
Object.assign(this.event, options);
|
|
40
|
+
this.event.path = path;
|
|
41
|
+
this.event.httpMethod = "GET";
|
|
42
|
+
return this;
|
|
43
|
+
}
|
|
44
|
+
post(path, body = {}, options = {}) {
|
|
45
|
+
Object.assign(this.event, options);
|
|
46
|
+
this.event.path = path;
|
|
47
|
+
this.event.httpMethod = "POST";
|
|
48
|
+
this.body(body);
|
|
49
|
+
return this;
|
|
50
|
+
}
|
|
51
|
+
patch(path, body = {}, options = {}) {
|
|
52
|
+
Object.assign(this.event, options);
|
|
53
|
+
this.event.path = path;
|
|
54
|
+
this.event.httpMethod = "PATCH";
|
|
55
|
+
this.body(body);
|
|
56
|
+
return this;
|
|
57
|
+
}
|
|
58
|
+
put(path, body = {}, options = {}) {
|
|
59
|
+
Object.assign(this.event, options);
|
|
60
|
+
this.event.path = path;
|
|
61
|
+
this.event.httpMethod = "PUT";
|
|
62
|
+
this.body(body);
|
|
63
|
+
return this;
|
|
64
|
+
}
|
|
65
|
+
delete(path, body = {}, options = {}) {
|
|
66
|
+
Object.assign(this.event, options);
|
|
67
|
+
this.event.path = path;
|
|
68
|
+
this.event.httpMethod = "DELETE";
|
|
69
|
+
this.body(body);
|
|
70
|
+
return this;
|
|
71
|
+
}
|
|
72
|
+
query(query) {
|
|
73
|
+
this.event.queryStringParameters = {
|
|
74
|
+
...this.event.queryStringParameters,
|
|
75
|
+
...JSON.parse(JSON.stringify(query))
|
|
76
|
+
};
|
|
77
|
+
return this;
|
|
78
|
+
}
|
|
79
|
+
params(pathParameters) {
|
|
80
|
+
this.event.pathParameters = {
|
|
81
|
+
...this.event.pathParameters,
|
|
82
|
+
...JSON.parse(JSON.stringify(pathParameters))
|
|
83
|
+
};
|
|
84
|
+
return this;
|
|
85
|
+
}
|
|
86
|
+
headers(headers) {
|
|
87
|
+
this.event.headers = {
|
|
88
|
+
...this.event.headers,
|
|
89
|
+
...JSON.parse(JSON.stringify(headers))
|
|
90
|
+
};
|
|
91
|
+
return this;
|
|
92
|
+
}
|
|
93
|
+
body(body) {
|
|
94
|
+
if (body !== undefined) {
|
|
95
|
+
this.event.headers["content-type"] = "application/json";
|
|
96
|
+
this.event.body = JSON.stringify(body);
|
|
97
|
+
}
|
|
98
|
+
return this;
|
|
99
|
+
}
|
|
100
|
+
init(lambda, resolve, reject) {
|
|
101
|
+
setTimeout(async () => {
|
|
102
|
+
try {
|
|
103
|
+
const result = await PlatformServerlessTest.callbacks[lambda](this.event, this.context, resolve);
|
|
104
|
+
resolve(result);
|
|
105
|
+
}
|
|
106
|
+
catch (er) {
|
|
107
|
+
reject(er);
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
exports.LambdaClientRequest = LambdaClientRequest;
|
|
113
|
+
class PlatformServerlessTest extends di_1.DITest {
|
|
114
|
+
static bootstrap(serverless, { server, ...settings }) {
|
|
115
|
+
return async function before() {
|
|
116
|
+
settings = di_1.DITest.configure(settings);
|
|
117
|
+
const isServerlessHttp = (0, core_1.nameOf)(serverless).includes("Http");
|
|
118
|
+
// @ts-ignore
|
|
119
|
+
const instance = isServerlessHttp ? serverless.bootstrap(server, settings) : serverless.bootstrap(settings);
|
|
120
|
+
PlatformServerlessTest.instance = instance;
|
|
121
|
+
PlatformServerlessTest.callbacks = {};
|
|
122
|
+
if (!isServerlessHttp) {
|
|
123
|
+
PlatformServerlessTest.callbacks = instance.callbacks();
|
|
124
|
+
}
|
|
125
|
+
PlatformServerlessTest.callbacks.handler = instance.handler();
|
|
126
|
+
// used by inject method
|
|
127
|
+
di_1.DITest.injector = instance.injector;
|
|
128
|
+
return instance.promise;
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Resets the test injector of the test context, so it won't pollute your next test. Call this in your `tearDown` logic.
|
|
133
|
+
*/
|
|
134
|
+
static async reset() {
|
|
135
|
+
if (PlatformServerlessTest.instance) {
|
|
136
|
+
await PlatformServerlessTest.instance.stop();
|
|
137
|
+
}
|
|
138
|
+
if (di_1.DITest.hasInjector()) {
|
|
139
|
+
await di_1.DITest.injector.destroy();
|
|
140
|
+
di_1.DITest._injector = null;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
exports.PlatformServerlessTest = PlatformServerlessTest;
|
|
145
|
+
PlatformServerlessTest.callbacks = {};
|
|
146
|
+
PlatformServerlessTest.request = LambdaClientRequest;
|
|
147
|
+
//# sourceMappingURL=PlatformServerlessTest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PlatformServerlessTest.js","sourceRoot":"","sources":["../../src/PlatformServerlessTest.ts"],"names":[],"mappings":";;;AAAA,iCAAgC;AAGhC,uDAAkD;AAClD,2DAAsD;AACtD,qCAAwC;AAKxC,MAAa,mBAAoB,SAAQ,OAA8B;IAAvE;;QACE,UAAK,GAAG,IAAA,iCAAe,GAAE,CAAC;QAC1B,YAAO,GAAG,IAAA,qCAAiB,GAAE,CAAC;IAsIhC,CAAC;IApIC,MAAM,CAAC,IAAI,CAAC,UAAkB;QAC5B,MAAM,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Q,CAAC,OAAO,EAAE,CAAC;YAC9D,wBAAwB;YACxB,WAAM,CAAC,QAAQ,GAAG,QAAQ,CAAC,QAAQ,CAAC;YAEpC,OAAO,QAAQ,CAAC,OAAO,CAAC;QAC1B,CAAC,CAAC;IACJ,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,KAAK,CAAC,KAAK;QAChB,IAAI,sBAAsB,CAAC,QAAQ,EAAE;YACnC,MAAM,sBAAsB,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC;SAC9C;QACD,IAAI,WAAM,CAAC,WAAW,EAAE,EAAE;YACxB,MAAM,WAAM,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC;YAChC,WAAM,CAAC,SAAS,GAAG,IAAI,CAAC;SACzB;IACH,CAAC;;AAhDH,wDAiDC;AAhDQ,gCAAS,GAA2C,EAAE,CAAC;AAEvD,8BAAO,GAAG,mBAAmB,CAAC","sourcesContent":["import {DITest} from \"@tsed/di\";\nimport {APIGatewayEventDefaultAuthorizerContext, APIGatewayProxyEventBase, APIGatewayProxyHandler} from \"aws-lambda\";\nimport {APIGatewayProxyResult} from \"aws-lambda/trigger/api-gateway-proxy\";\nimport {createFakeEvent} from \"./createFakeEvent\";\nimport {createFakeContext} from \"./createFakeContext\";\nimport {nameOf, Type} from \"@tsed/core\";\nimport {PlatformBuilder, PlatformBuilderSettings} from \"@tsed/common\";\n\nexport interface LambdaPromiseResult extends Promise<APIGatewayProxyResult> {}\n\nexport class LambdaClientRequest extends Promise<APIGatewayProxyResult> {\n event = createFakeEvent();\n context = createFakeContext();\n\n static call(lambdaName: string) {\n const resolvers: any = {};\n const promise = new LambdaClientRequest((resolve, reject) => {\n resolvers.resolve = resolve;\n resolvers.reject = reject;\n });\n\n promise.init(lambdaName, resolvers.resolve, resolvers.reject);\n\n return promise;\n }\n\n static get(path: string, options: Partial<APIGatewayProxyEventBase<APIGatewayEventDefaultAuthorizerContext>> = {}) {\n return this.call(\"handler\").get(path, options);\n }\n\n static post(path: string, body?: any, options: Partial<APIGatewayProxyEventBase<APIGatewayEventDefaultAuthorizerContext>> = {}) {\n return this.call(\"handler\").post(path, body, options);\n }\n\n static put(path: string, body?: any, options: Partial<APIGatewayProxyEventBase<APIGatewayEventDefaultAuthorizerContext>> = {}) {\n return this.call(\"handler\").put(path, body, options);\n }\n\n static patch(path: string, body?: any, options: Partial<APIGatewayProxyEventBase<APIGatewayEventDefaultAuthorizerContext>> = {}) {\n return this.call(\"handler\").patch(path, body, options);\n }\n\n static delete(path: string, body?: any, options: Partial<APIGatewayProxyEventBase<APIGatewayEventDefaultAuthorizerContext>> = {}) {\n return this.call(\"handler\").delete(path, body, options);\n }\n\n get(path: string, options: Partial<APIGatewayProxyEventBase<APIGatewayEventDefaultAuthorizerContext>> = {}) {\n Object.assign(this.event, options);\n\n this.event.path = path;\n this.event.httpMethod = \"GET\";\n\n return this;\n }\n\n post(path: string, body: any = {}, options: Partial<APIGatewayProxyEventBase<APIGatewayEventDefaultAuthorizerContext>> = {}) {\n Object.assign(this.event, options);\n\n this.event.path = path;\n this.event.httpMethod = \"POST\";\n\n this.body(body);\n\n return this;\n }\n\n patch(path: string, body: any = {}, options: Partial<APIGatewayProxyEventBase<APIGatewayEventDefaultAuthorizerContext>> = {}) {\n Object.assign(this.event, options);\n\n this.event.path = path;\n this.event.httpMethod = \"PATCH\";\n\n this.body(body);\n\n return this;\n }\n\n put(path: string, body: any = {}, options: Partial<APIGatewayProxyEventBase<APIGatewayEventDefaultAuthorizerContext>> = {}) {\n Object.assign(this.event, options);\n\n this.event.path = path;\n this.event.httpMethod = \"PUT\";\n\n this.body(body);\n\n return this;\n }\n\n delete(path: string, body: any = {}, options: Partial<APIGatewayProxyEventBase<APIGatewayEventDefaultAuthorizerContext>> = {}) {\n Object.assign(this.event, options);\n\n this.event.path = path;\n this.event.httpMethod = \"DELETE\";\n\n this.body(body);\n\n return this;\n }\n\n query(query: any) {\n this.event.queryStringParameters = {\n ...this.event.queryStringParameters,\n ...JSON.parse(JSON.stringify(query))\n };\n\n return this;\n }\n\n params(pathParameters: any) {\n this.event.pathParameters = {\n ...this.event.pathParameters,\n ...JSON.parse(JSON.stringify(pathParameters))\n };\n\n return this;\n }\n\n headers(headers: Record<string, any>) {\n this.event.headers = {\n ...this.event.headers,\n ...JSON.parse(JSON.stringify(headers))\n };\n\n return this;\n }\n\n body(body: any) {\n if (body !== undefined) {\n this.event.headers[\"content-type\"] = \"application/json\";\n\n this.event.body = JSON.stringify(body);\n }\n\n return this;\n }\n\n protected init(lambda: string, resolve: Function, reject: Function) {\n setTimeout(async () => {\n try {\n const result = await PlatformServerlessTest.callbacks[lambda](this.event, this.context, resolve as any);\n resolve(result as any);\n } catch (er) {\n reject(er);\n }\n });\n }\n}\n\nexport class PlatformServerlessTest extends DITest {\n static callbacks: Record<string, APIGatewayProxyHandler> = {};\n static instance: any;\n static request = LambdaClientRequest;\n\n static bootstrap(\n serverless: {bootstrap: (server: Type<any>, settings: PlatformBuilderSettings) => PlatformBuilder},\n {server, ...settings}: PlatformBuilderSettings & {server: Type<any>}\n ): () => Promise<any>;\n static bootstrap(\n serverless: {bootstrap: (settings: Partial<TsED.Configuration> & {lambda?: Type[]}) => any},\n {server, ...settings}: PlatformBuilderSettings\n ): () => Promise<any>;\n static bootstrap(serverless: any, {server, ...settings}: PlatformBuilderSettings) {\n return async function before(): Promise<void> {\n settings = DITest.configure(settings);\n\n const isServerlessHttp = nameOf(serverless).includes(\"Http\");\n\n // @ts-ignore\n const instance = isServerlessHttp ? serverless.bootstrap(server, settings) : serverless.bootstrap(settings);\n\n PlatformServerlessTest.instance = instance;\n PlatformServerlessTest.callbacks = {};\n\n if (!isServerlessHttp) {\n PlatformServerlessTest.callbacks = instance.callbacks();\n }\n\n PlatformServerlessTest.callbacks.handler = instance.handler();\n // used by inject method\n DITest.injector = instance.injector;\n\n return instance.promise;\n };\n }\n\n /**\n * Resets the test injector of the test context, so it won't pollute your next test. Call this in your `tearDown` logic.\n */\n static async reset() {\n if (PlatformServerlessTest.instance) {\n await PlatformServerlessTest.instance.stop();\n }\n if (DITest.hasInjector()) {\n await DITest.injector.destroy();\n DITest._injector = null;\n }\n }\n}\n"]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createFakeContext = void 0;
|
|
4
|
+
function createFakeContext(context) {
|
|
5
|
+
return {
|
|
6
|
+
awsRequestId: "awsRequestId",
|
|
7
|
+
callbackWaitsForEmptyEventLoop: false,
|
|
8
|
+
functionName: "",
|
|
9
|
+
functionVersion: "",
|
|
10
|
+
invokedFunctionArn: "",
|
|
11
|
+
logGroupName: "",
|
|
12
|
+
logStreamName: "",
|
|
13
|
+
memoryLimitInMB: "",
|
|
14
|
+
...(context || {})
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
exports.createFakeContext = createFakeContext;
|
|
18
|
+
//# sourceMappingURL=createFakeContext.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createFakeContext.js","sourceRoot":"","sources":["../../src/createFakeContext.ts"],"names":[],"mappings":";;;AAEA,SAAgB,iBAAiB,CAAC,OAAiB;IACjD,OAAO;QACL,YAAY,EAAE,cAAc;QAC5B,8BAA8B,EAAE,KAAK;QACrC,YAAY,EAAE,EAAE;QAChB,eAAe,EAAE,EAAE;QACnB,kBAAkB,EAAE,EAAE;QACtB,YAAY,EAAE,EAAE;QAChB,aAAa,EAAE,EAAE;QACjB,eAAe,EAAE,EAAE;QACnB,GAAG,CAAC,OAAO,IAAI,EAAE,CAAC;KACR,CAAC;AACf,CAAC;AAZD,8CAYC","sourcesContent":["import {Context} from \"aws-lambda\";\n\nexport function createFakeContext(context?: Context): Context {\n return {\n awsRequestId: \"awsRequestId\",\n callbackWaitsForEmptyEventLoop: false,\n functionName: \"\",\n functionVersion: \"\",\n invokedFunctionArn: \"\",\n logGroupName: \"\",\n logStreamName: \"\",\n memoryLimitInMB: \"\",\n ...(context || {})\n } as Context;\n}\n"]}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { APIGatewayEventDefaultAuthorizerContext, APIGatewayProxyEventBase } from "aws-lambda";
|
|
2
|
+
export declare function createFakeEvent(event?: Partial<APIGatewayProxyEventBase<APIGatewayEventDefaultAuthorizerContext>>): APIGatewayProxyEventBase<APIGatewayEventDefaultAuthorizerContext>;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createFakeEvent = void 0;
|
|
4
|
+
function createFakeEvent(event = {}) {
|
|
5
|
+
return {
|
|
6
|
+
body: "",
|
|
7
|
+
headers: {},
|
|
8
|
+
httpMethod: "",
|
|
9
|
+
isBase64Encoded: false,
|
|
10
|
+
multiValueHeaders: {},
|
|
11
|
+
multiValueQueryStringParameters: {},
|
|
12
|
+
path: event.path || "/",
|
|
13
|
+
pathParameters: {},
|
|
14
|
+
queryStringParameters: {},
|
|
15
|
+
resource: "",
|
|
16
|
+
stageVariables: {},
|
|
17
|
+
...event,
|
|
18
|
+
requestContext: {
|
|
19
|
+
...event === null || event === void 0 ? void 0 : event.requestContext,
|
|
20
|
+
accountId: "",
|
|
21
|
+
apiId: "",
|
|
22
|
+
protocol: "https",
|
|
23
|
+
httpMethod: "",
|
|
24
|
+
identity: {},
|
|
25
|
+
path: event.path || "/",
|
|
26
|
+
stage: "",
|
|
27
|
+
requestId: "requestId",
|
|
28
|
+
requestTimeEpoch: 0,
|
|
29
|
+
resourceId: 1,
|
|
30
|
+
resourcePath: event.path || "/"
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
exports.createFakeEvent = createFakeEvent;
|
|
35
|
+
//# sourceMappingURL=createFakeEvent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createFakeEvent.js","sourceRoot":"","sources":["../../src/createFakeEvent.ts"],"names":[],"mappings":";;;AAEA,SAAgB,eAAe,CAAC,QAAoF,EAAE;IACpH,OAAO;QACL,IAAI,EAAE,EAAE;QACR,OAAO,EAAE,EAAE;QACX,UAAU,EAAE,EAAE;QACd,eAAe,EAAE,KAAK;QACtB,iBAAiB,EAAE,EAAE;QACrB,+BAA+B,EAAE,EAAE;QACnC,IAAI,EAAE,KAAK,CAAC,IAAI,IAAI,GAAG;QACvB,cAAc,EAAE,EAAE;QAClB,qBAAqB,EAAE,EAAE;QACzB,QAAQ,EAAE,EAAE;QACZ,cAAc,EAAE,EAAE;QAClB,GAAG,KAAK;QACR,cAAc,EAAE;YACd,GAAG,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,cAAc;YACxB,SAAS,EAAE,EAAE;YACb,KAAK,EAAE,EAAE;YACT,QAAQ,EAAE,OAAO;YACjB,UAAU,EAAE,EAAE;YACd,QAAQ,EAAE,EAAS;YACnB,IAAI,EAAE,KAAK,CAAC,IAAI,IAAI,GAAG;YACvB,KAAK,EAAE,EAAE;YACT,SAAS,EAAE,WAAW;YACtB,gBAAgB,EAAE,CAAC;YACnB,UAAU,EAAE,CAAC;YACb,YAAY,EAAE,KAAK,CAAC,IAAI,IAAI,GAAG;SACzB;KAC4D,CAAC;AACzE,CAAC;AA7BD,0CA6BC","sourcesContent":["import {APIGatewayEventDefaultAuthorizerContext, APIGatewayProxyEventBase} from \"aws-lambda\";\n\nexport function createFakeEvent(event: Partial<APIGatewayProxyEventBase<APIGatewayEventDefaultAuthorizerContext>> = {}) {\n return {\n body: \"\",\n headers: {},\n httpMethod: \"\",\n isBase64Encoded: false,\n multiValueHeaders: {},\n multiValueQueryStringParameters: {},\n path: event.path || \"/\",\n pathParameters: {},\n queryStringParameters: {},\n resource: \"\",\n stageVariables: {},\n ...event,\n requestContext: {\n ...event?.requestContext,\n accountId: \"\",\n apiId: \"\",\n protocol: \"https\",\n httpMethod: \"\",\n identity: {} as any,\n path: event.path || \"/\",\n stage: \"\",\n requestId: \"requestId\",\n requestTimeEpoch: 0,\n resourceId: 1,\n resourcePath: event.path || \"/\"\n } as any\n } as APIGatewayProxyEventBase<APIGatewayEventDefaultAuthorizerContext>;\n}\n"]}
|
package/lib/cjs/index.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
(0, tslib_1.__exportStar)(require("./createFakeEvent"), exports);
|
|
5
|
+
(0, tslib_1.__exportStar)(require("./createFakeContext"), exports);
|
|
6
|
+
(0, tslib_1.__exportStar)(require("./PlatformServerlessTest"), exports);
|
|
7
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA,iEAAkC;AAClC,mEAAoC;AACpC,wEAAyC","sourcesContent":["export * from \"./createFakeEvent\";\nexport * from \"./createFakeContext\";\nexport * from \"./PlatformServerlessTest\";\n"]}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { DITest } from "@tsed/di";
|
|
2
|
+
import { createFakeEvent } from "./createFakeEvent";
|
|
3
|
+
import { createFakeContext } from "./createFakeContext";
|
|
4
|
+
import { nameOf } from "@tsed/core";
|
|
5
|
+
export class LambdaClientRequest extends Promise {
|
|
6
|
+
constructor() {
|
|
7
|
+
super(...arguments);
|
|
8
|
+
this.event = createFakeEvent();
|
|
9
|
+
this.context = createFakeContext();
|
|
10
|
+
}
|
|
11
|
+
static call(lambdaName) {
|
|
12
|
+
const resolvers = {};
|
|
13
|
+
const promise = new LambdaClientRequest((resolve, reject) => {
|
|
14
|
+
resolvers.resolve = resolve;
|
|
15
|
+
resolvers.reject = reject;
|
|
16
|
+
});
|
|
17
|
+
promise.init(lambdaName, resolvers.resolve, resolvers.reject);
|
|
18
|
+
return promise;
|
|
19
|
+
}
|
|
20
|
+
static get(path, options = {}) {
|
|
21
|
+
return this.call("handler").get(path, options);
|
|
22
|
+
}
|
|
23
|
+
static post(path, body, options = {}) {
|
|
24
|
+
return this.call("handler").post(path, body, options);
|
|
25
|
+
}
|
|
26
|
+
static put(path, body, options = {}) {
|
|
27
|
+
return this.call("handler").put(path, body, options);
|
|
28
|
+
}
|
|
29
|
+
static patch(path, body, options = {}) {
|
|
30
|
+
return this.call("handler").patch(path, body, options);
|
|
31
|
+
}
|
|
32
|
+
static delete(path, body, options = {}) {
|
|
33
|
+
return this.call("handler").delete(path, body, options);
|
|
34
|
+
}
|
|
35
|
+
get(path, options = {}) {
|
|
36
|
+
Object.assign(this.event, options);
|
|
37
|
+
this.event.path = path;
|
|
38
|
+
this.event.httpMethod = "GET";
|
|
39
|
+
return this;
|
|
40
|
+
}
|
|
41
|
+
post(path, body = {}, options = {}) {
|
|
42
|
+
Object.assign(this.event, options);
|
|
43
|
+
this.event.path = path;
|
|
44
|
+
this.event.httpMethod = "POST";
|
|
45
|
+
this.body(body);
|
|
46
|
+
return this;
|
|
47
|
+
}
|
|
48
|
+
patch(path, body = {}, options = {}) {
|
|
49
|
+
Object.assign(this.event, options);
|
|
50
|
+
this.event.path = path;
|
|
51
|
+
this.event.httpMethod = "PATCH";
|
|
52
|
+
this.body(body);
|
|
53
|
+
return this;
|
|
54
|
+
}
|
|
55
|
+
put(path, body = {}, options = {}) {
|
|
56
|
+
Object.assign(this.event, options);
|
|
57
|
+
this.event.path = path;
|
|
58
|
+
this.event.httpMethod = "PUT";
|
|
59
|
+
this.body(body);
|
|
60
|
+
return this;
|
|
61
|
+
}
|
|
62
|
+
delete(path, body = {}, options = {}) {
|
|
63
|
+
Object.assign(this.event, options);
|
|
64
|
+
this.event.path = path;
|
|
65
|
+
this.event.httpMethod = "DELETE";
|
|
66
|
+
this.body(body);
|
|
67
|
+
return this;
|
|
68
|
+
}
|
|
69
|
+
query(query) {
|
|
70
|
+
this.event.queryStringParameters = {
|
|
71
|
+
...this.event.queryStringParameters,
|
|
72
|
+
...JSON.parse(JSON.stringify(query))
|
|
73
|
+
};
|
|
74
|
+
return this;
|
|
75
|
+
}
|
|
76
|
+
params(pathParameters) {
|
|
77
|
+
this.event.pathParameters = {
|
|
78
|
+
...this.event.pathParameters,
|
|
79
|
+
...JSON.parse(JSON.stringify(pathParameters))
|
|
80
|
+
};
|
|
81
|
+
return this;
|
|
82
|
+
}
|
|
83
|
+
headers(headers) {
|
|
84
|
+
this.event.headers = {
|
|
85
|
+
...this.event.headers,
|
|
86
|
+
...JSON.parse(JSON.stringify(headers))
|
|
87
|
+
};
|
|
88
|
+
return this;
|
|
89
|
+
}
|
|
90
|
+
body(body) {
|
|
91
|
+
if (body !== undefined) {
|
|
92
|
+
this.event.headers["content-type"] = "application/json";
|
|
93
|
+
this.event.body = JSON.stringify(body);
|
|
94
|
+
}
|
|
95
|
+
return this;
|
|
96
|
+
}
|
|
97
|
+
init(lambda, resolve, reject) {
|
|
98
|
+
setTimeout(async () => {
|
|
99
|
+
try {
|
|
100
|
+
const result = await PlatformServerlessTest.callbacks[lambda](this.event, this.context, resolve);
|
|
101
|
+
resolve(result);
|
|
102
|
+
}
|
|
103
|
+
catch (er) {
|
|
104
|
+
reject(er);
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
export class PlatformServerlessTest extends DITest {
|
|
110
|
+
static bootstrap(serverless, { server, ...settings }) {
|
|
111
|
+
return async function before() {
|
|
112
|
+
settings = DITest.configure(settings);
|
|
113
|
+
const isServerlessHttp = nameOf(serverless).includes("Http");
|
|
114
|
+
// @ts-ignore
|
|
115
|
+
const instance = isServerlessHttp ? serverless.bootstrap(server, settings) : serverless.bootstrap(settings);
|
|
116
|
+
PlatformServerlessTest.instance = instance;
|
|
117
|
+
PlatformServerlessTest.callbacks = {};
|
|
118
|
+
if (!isServerlessHttp) {
|
|
119
|
+
PlatformServerlessTest.callbacks = instance.callbacks();
|
|
120
|
+
}
|
|
121
|
+
PlatformServerlessTest.callbacks.handler = instance.handler();
|
|
122
|
+
// used by inject method
|
|
123
|
+
DITest.injector = instance.injector;
|
|
124
|
+
return instance.promise;
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Resets the test injector of the test context, so it won't pollute your next test. Call this in your `tearDown` logic.
|
|
129
|
+
*/
|
|
130
|
+
static async reset() {
|
|
131
|
+
if (PlatformServerlessTest.instance) {
|
|
132
|
+
await PlatformServerlessTest.instance.stop();
|
|
133
|
+
}
|
|
134
|
+
if (DITest.hasInjector()) {
|
|
135
|
+
await DITest.injector.destroy();
|
|
136
|
+
DITest._injector = null;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
PlatformServerlessTest.callbacks = {};
|
|
141
|
+
PlatformServerlessTest.request = LambdaClientRequest;
|
|
142
|
+
//# sourceMappingURL=PlatformServerlessTest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PlatformServerlessTest.js","sourceRoot":"","sources":["../../src/PlatformServerlessTest.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,MAAM,EAAC,MAAM,UAAU,CAAC;AAGhC,OAAO,EAAC,eAAe,EAAC,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAC,iBAAiB,EAAC,MAAM,qBAAqB,CAAC;AACtD,OAAO,EAAC,MAAM,EAAO,MAAM,YAAY,CAAC;AAKxC,MAAM,OAAO,mBAAoB,SAAQ,OAA8B;IAAvE;;QACE,UAAK,GAAG,eAAe,EAAE,CAAC;QAC1B,YAAO,GAAG,iBAAiB,EAAE,CAAC;IAsIhC,CAAC;IApIC,MAAM,CAAC,IAAI,CAAC,UAAkB;QAC5B,MAAM,SAAS,GAAQ,EAAE,CAAC;QAC1B,MAAM,OAAO,GAAG,IAAI,mBAAmB,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YAC1D,SAAS,CAAC,OAAO,GAAG,OAAO,CAAC;YAC5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;IAED;;OAEG;IACH,MAAM,CAAC,KAAK,CAAC,KAAK;QAChB,IAAI,sBAAsB,CAAC,QAAQ,EAAE;YACnC,MAAM,sBAAsB,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC;SAC9C;QACD,IAAI,MAAM,CAAC,WAAW,EAAE,EAAE;YACxB,MAAM,MAAM,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC;YAChC,MAAM,CAAC,SAAS,GAAG,IAAI,CAAC;SACzB;IACH,CAAC;;AA/CM,gCAAS,GAA2C,EAAE,CAAC;AAEvD,8BAAO,GAAG,mBAAmB,CAAC","sourcesContent":["import {DITest} from \"@tsed/di\";\nimport {APIGatewayEventDefaultAuthorizerContext, APIGatewayProxyEventBase, APIGatewayProxyHandler} from \"aws-lambda\";\nimport {APIGatewayProxyResult} from \"aws-lambda/trigger/api-gateway-proxy\";\nimport {createFakeEvent} from \"./createFakeEvent\";\nimport {createFakeContext} from \"./createFakeContext\";\nimport {nameOf, Type} from \"@tsed/core\";\nimport {PlatformBuilder, PlatformBuilderSettings} from \"@tsed/common\";\n\nexport interface LambdaPromiseResult extends Promise<APIGatewayProxyResult> {}\n\nexport class LambdaClientRequest extends Promise<APIGatewayProxyResult> {\n event = createFakeEvent();\n context = createFakeContext();\n\n static call(lambdaName: string) {\n const resolvers: any = {};\n const promise = new LambdaClientRequest((resolve, reject) => {\n resolvers.resolve = resolve;\n resolvers.reject = reject;\n });\n\n promise.init(lambdaName, resolvers.resolve, resolvers.reject);\n\n return promise;\n }\n\n static get(path: string, options: Partial<APIGatewayProxyEventBase<APIGatewayEventDefaultAuthorizerContext>> = {}) {\n return this.call(\"handler\").get(path, options);\n }\n\n static post(path: string, body?: any, options: Partial<APIGatewayProxyEventBase<APIGatewayEventDefaultAuthorizerContext>> = {}) {\n return this.call(\"handler\").post(path, body, options);\n }\n\n static put(path: string, body?: any, options: Partial<APIGatewayProxyEventBase<APIGatewayEventDefaultAuthorizerContext>> = {}) {\n return this.call(\"handler\").put(path, body, options);\n }\n\n static patch(path: string, body?: any, options: Partial<APIGatewayProxyEventBase<APIGatewayEventDefaultAuthorizerContext>> = {}) {\n return this.call(\"handler\").patch(path, body, options);\n }\n\n static delete(path: string, body?: any, options: Partial<APIGatewayProxyEventBase<APIGatewayEventDefaultAuthorizerContext>> = {}) {\n return this.call(\"handler\").delete(path, body, options);\n }\n\n get(path: string, options: Partial<APIGatewayProxyEventBase<APIGatewayEventDefaultAuthorizerContext>> = {}) {\n Object.assign(this.event, options);\n\n this.event.path = path;\n this.event.httpMethod = \"GET\";\n\n return this;\n }\n\n post(path: string, body: any = {}, options: Partial<APIGatewayProxyEventBase<APIGatewayEventDefaultAuthorizerContext>> = {}) {\n Object.assign(this.event, options);\n\n this.event.path = path;\n this.event.httpMethod = \"POST\";\n\n this.body(body);\n\n return this;\n }\n\n patch(path: string, body: any = {}, options: Partial<APIGatewayProxyEventBase<APIGatewayEventDefaultAuthorizerContext>> = {}) {\n Object.assign(this.event, options);\n\n this.event.path = path;\n this.event.httpMethod = \"PATCH\";\n\n this.body(body);\n\n return this;\n }\n\n put(path: string, body: any = {}, options: Partial<APIGatewayProxyEventBase<APIGatewayEventDefaultAuthorizerContext>> = {}) {\n Object.assign(this.event, options);\n\n this.event.path = path;\n this.event.httpMethod = \"PUT\";\n\n this.body(body);\n\n return this;\n }\n\n delete(path: string, body: any = {}, options: Partial<APIGatewayProxyEventBase<APIGatewayEventDefaultAuthorizerContext>> = {}) {\n Object.assign(this.event, options);\n\n this.event.path = path;\n this.event.httpMethod = \"DELETE\";\n\n this.body(body);\n\n return this;\n }\n\n query(query: any) {\n this.event.queryStringParameters = {\n ...this.event.queryStringParameters,\n ...JSON.parse(JSON.stringify(query))\n };\n\n return this;\n }\n\n params(pathParameters: any) {\n this.event.pathParameters = {\n ...this.event.pathParameters,\n ...JSON.parse(JSON.stringify(pathParameters))\n };\n\n return this;\n }\n\n headers(headers: Record<string, any>) {\n this.event.headers = {\n ...this.event.headers,\n ...JSON.parse(JSON.stringify(headers))\n };\n\n return this;\n }\n\n body(body: any) {\n if (body !== undefined) {\n this.event.headers[\"content-type\"] = \"application/json\";\n\n this.event.body = JSON.stringify(body);\n }\n\n return this;\n }\n\n protected init(lambda: string, resolve: Function, reject: Function) {\n setTimeout(async () => {\n try {\n const result = await PlatformServerlessTest.callbacks[lambda](this.event, this.context, resolve as any);\n resolve(result as any);\n } catch (er) {\n reject(er);\n }\n });\n }\n}\n\nexport class PlatformServerlessTest extends DITest {\n static callbacks: Record<string, APIGatewayProxyHandler> = {};\n static instance: any;\n static request = LambdaClientRequest;\n\n static bootstrap(\n serverless: {bootstrap: (server: Type<any>, settings: PlatformBuilderSettings) => PlatformBuilder},\n {server, ...settings}: PlatformBuilderSettings & {server: Type<any>}\n ): () => Promise<any>;\n static bootstrap(\n serverless: {bootstrap: (settings: Partial<TsED.Configuration> & {lambda?: Type[]}) => any},\n {server, ...settings}: PlatformBuilderSettings\n ): () => Promise<any>;\n static bootstrap(serverless: any, {server, ...settings}: PlatformBuilderSettings) {\n return async function before(): Promise<void> {\n settings = DITest.configure(settings);\n\n const isServerlessHttp = nameOf(serverless).includes(\"Http\");\n\n // @ts-ignore\n const instance = isServerlessHttp ? serverless.bootstrap(server, settings) : serverless.bootstrap(settings);\n\n PlatformServerlessTest.instance = instance;\n PlatformServerlessTest.callbacks = {};\n\n if (!isServerlessHttp) {\n PlatformServerlessTest.callbacks = instance.callbacks();\n }\n\n PlatformServerlessTest.callbacks.handler = instance.handler();\n // used by inject method\n DITest.injector = instance.injector;\n\n return instance.promise;\n };\n }\n\n /**\n * Resets the test injector of the test context, so it won't pollute your next test. Call this in your `tearDown` logic.\n */\n static async reset() {\n if (PlatformServerlessTest.instance) {\n await PlatformServerlessTest.instance.stop();\n }\n if (DITest.hasInjector()) {\n await DITest.injector.destroy();\n DITest._injector = null;\n }\n }\n}\n"]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export function createFakeContext(context) {
|
|
2
|
+
return {
|
|
3
|
+
awsRequestId: "awsRequestId",
|
|
4
|
+
callbackWaitsForEmptyEventLoop: false,
|
|
5
|
+
functionName: "",
|
|
6
|
+
functionVersion: "",
|
|
7
|
+
invokedFunctionArn: "",
|
|
8
|
+
logGroupName: "",
|
|
9
|
+
logStreamName: "",
|
|
10
|
+
memoryLimitInMB: "",
|
|
11
|
+
...(context || {})
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=createFakeContext.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createFakeContext.js","sourceRoot":"","sources":["../../src/createFakeContext.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,iBAAiB,CAAC,OAAiB;IACjD,OAAO;QACL,YAAY,EAAE,cAAc;QAC5B,8BAA8B,EAAE,KAAK;QACrC,YAAY,EAAE,EAAE;QAChB,eAAe,EAAE,EAAE;QACnB,kBAAkB,EAAE,EAAE;QACtB,YAAY,EAAE,EAAE;QAChB,aAAa,EAAE,EAAE;QACjB,eAAe,EAAE,EAAE;QACnB,GAAG,CAAC,OAAO,IAAI,EAAE,CAAC;KACR,CAAC;AACf,CAAC","sourcesContent":["import {Context} from \"aws-lambda\";\n\nexport function createFakeContext(context?: Context): Context {\n return {\n awsRequestId: \"awsRequestId\",\n callbackWaitsForEmptyEventLoop: false,\n functionName: \"\",\n functionVersion: \"\",\n invokedFunctionArn: \"\",\n logGroupName: \"\",\n logStreamName: \"\",\n memoryLimitInMB: \"\",\n ...(context || {})\n } as Context;\n}\n"]}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export function createFakeEvent(event = {}) {
|
|
2
|
+
return {
|
|
3
|
+
body: "",
|
|
4
|
+
headers: {},
|
|
5
|
+
httpMethod: "",
|
|
6
|
+
isBase64Encoded: false,
|
|
7
|
+
multiValueHeaders: {},
|
|
8
|
+
multiValueQueryStringParameters: {},
|
|
9
|
+
path: event.path || "/",
|
|
10
|
+
pathParameters: {},
|
|
11
|
+
queryStringParameters: {},
|
|
12
|
+
resource: "",
|
|
13
|
+
stageVariables: {},
|
|
14
|
+
...event,
|
|
15
|
+
requestContext: {
|
|
16
|
+
...event === null || event === void 0 ? void 0 : event.requestContext,
|
|
17
|
+
accountId: "",
|
|
18
|
+
apiId: "",
|
|
19
|
+
protocol: "https",
|
|
20
|
+
httpMethod: "",
|
|
21
|
+
identity: {},
|
|
22
|
+
path: event.path || "/",
|
|
23
|
+
stage: "",
|
|
24
|
+
requestId: "requestId",
|
|
25
|
+
requestTimeEpoch: 0,
|
|
26
|
+
resourceId: 1,
|
|
27
|
+
resourcePath: event.path || "/"
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=createFakeEvent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createFakeEvent.js","sourceRoot":"","sources":["../../src/createFakeEvent.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,eAAe,CAAC,QAAoF,EAAE;IACpH,OAAO;QACL,IAAI,EAAE,EAAE;QACR,OAAO,EAAE,EAAE;QACX,UAAU,EAAE,EAAE;QACd,eAAe,EAAE,KAAK;QACtB,iBAAiB,EAAE,EAAE;QACrB,+BAA+B,EAAE,EAAE;QACnC,IAAI,EAAE,KAAK,CAAC,IAAI,IAAI,GAAG;QACvB,cAAc,EAAE,EAAE;QAClB,qBAAqB,EAAE,EAAE;QACzB,QAAQ,EAAE,EAAE;QACZ,cAAc,EAAE,EAAE;QAClB,GAAG,KAAK;QACR,cAAc,EAAE;YACd,GAAG,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,cAAc;YACxB,SAAS,EAAE,EAAE;YACb,KAAK,EAAE,EAAE;YACT,QAAQ,EAAE,OAAO;YACjB,UAAU,EAAE,EAAE;YACd,QAAQ,EAAE,EAAS;YACnB,IAAI,EAAE,KAAK,CAAC,IAAI,IAAI,GAAG;YACvB,KAAK,EAAE,EAAE;YACT,SAAS,EAAE,WAAW;YACtB,gBAAgB,EAAE,CAAC;YACnB,UAAU,EAAE,CAAC;YACb,YAAY,EAAE,KAAK,CAAC,IAAI,IAAI,GAAG;SACzB;KAC4D,CAAC;AACzE,CAAC","sourcesContent":["import {APIGatewayEventDefaultAuthorizerContext, APIGatewayProxyEventBase} from \"aws-lambda\";\n\nexport function createFakeEvent(event: Partial<APIGatewayProxyEventBase<APIGatewayEventDefaultAuthorizerContext>> = {}) {\n return {\n body: \"\",\n headers: {},\n httpMethod: \"\",\n isBase64Encoded: false,\n multiValueHeaders: {},\n multiValueQueryStringParameters: {},\n path: event.path || \"/\",\n pathParameters: {},\n queryStringParameters: {},\n resource: \"\",\n stageVariables: {},\n ...event,\n requestContext: {\n ...event?.requestContext,\n accountId: \"\",\n apiId: \"\",\n protocol: \"https\",\n httpMethod: \"\",\n identity: {} as any,\n path: event.path || \"/\",\n stage: \"\",\n requestId: \"requestId\",\n requestTimeEpoch: 0,\n resourceId: 1,\n resourcePath: event.path || \"/\"\n } as any\n } as APIGatewayProxyEventBase<APIGatewayEventDefaultAuthorizerContext>;\n}\n"]}
|
package/lib/esm/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,0BAA0B,CAAC","sourcesContent":["export * from \"./createFakeEvent\";\nexport * from \"./createFakeContext\";\nexport * from \"./PlatformServerlessTest\";\n"]}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { DITest } from "@tsed/di";
|
|
2
|
+
import { APIGatewayEventDefaultAuthorizerContext, APIGatewayProxyEventBase, APIGatewayProxyHandler } from "aws-lambda";
|
|
3
|
+
import { APIGatewayProxyResult } from "aws-lambda/trigger/api-gateway-proxy";
|
|
4
|
+
import { Type } from "@tsed/core";
|
|
5
|
+
import { PlatformBuilder, PlatformBuilderSettings } from "@tsed/common";
|
|
6
|
+
export interface LambdaPromiseResult extends Promise<APIGatewayProxyResult> {
|
|
7
|
+
}
|
|
8
|
+
export declare class LambdaClientRequest extends Promise<APIGatewayProxyResult> {
|
|
9
|
+
event: APIGatewayProxyEventBase<APIGatewayEventDefaultAuthorizerContext>;
|
|
10
|
+
context: import("aws-lambda").Context;
|
|
11
|
+
static call(lambdaName: string): LambdaClientRequest;
|
|
12
|
+
static get(path: string, options?: Partial<APIGatewayProxyEventBase<APIGatewayEventDefaultAuthorizerContext>>): LambdaClientRequest;
|
|
13
|
+
static post(path: string, body?: any, options?: Partial<APIGatewayProxyEventBase<APIGatewayEventDefaultAuthorizerContext>>): LambdaClientRequest;
|
|
14
|
+
static put(path: string, body?: any, options?: Partial<APIGatewayProxyEventBase<APIGatewayEventDefaultAuthorizerContext>>): LambdaClientRequest;
|
|
15
|
+
static patch(path: string, body?: any, options?: Partial<APIGatewayProxyEventBase<APIGatewayEventDefaultAuthorizerContext>>): LambdaClientRequest;
|
|
16
|
+
static delete(path: string, body?: any, options?: Partial<APIGatewayProxyEventBase<APIGatewayEventDefaultAuthorizerContext>>): LambdaClientRequest;
|
|
17
|
+
get(path: string, options?: Partial<APIGatewayProxyEventBase<APIGatewayEventDefaultAuthorizerContext>>): this;
|
|
18
|
+
post(path: string, body?: any, options?: Partial<APIGatewayProxyEventBase<APIGatewayEventDefaultAuthorizerContext>>): this;
|
|
19
|
+
patch(path: string, body?: any, options?: Partial<APIGatewayProxyEventBase<APIGatewayEventDefaultAuthorizerContext>>): this;
|
|
20
|
+
put(path: string, body?: any, options?: Partial<APIGatewayProxyEventBase<APIGatewayEventDefaultAuthorizerContext>>): this;
|
|
21
|
+
delete(path: string, body?: any, options?: Partial<APIGatewayProxyEventBase<APIGatewayEventDefaultAuthorizerContext>>): this;
|
|
22
|
+
query(query: any): this;
|
|
23
|
+
params(pathParameters: any): this;
|
|
24
|
+
headers(headers: Record<string, any>): this;
|
|
25
|
+
body(body: any): this;
|
|
26
|
+
protected init(lambda: string, resolve: Function, reject: Function): void;
|
|
27
|
+
}
|
|
28
|
+
export declare class PlatformServerlessTest extends DITest {
|
|
29
|
+
static callbacks: Record<string, APIGatewayProxyHandler>;
|
|
30
|
+
static instance: any;
|
|
31
|
+
static request: typeof LambdaClientRequest;
|
|
32
|
+
static bootstrap(serverless: {
|
|
33
|
+
bootstrap: (server: Type<any>, settings: PlatformBuilderSettings) => PlatformBuilder;
|
|
34
|
+
}, { server, ...settings }: PlatformBuilderSettings & {
|
|
35
|
+
server: Type<any>;
|
|
36
|
+
}): () => Promise<any>;
|
|
37
|
+
static bootstrap(serverless: {
|
|
38
|
+
bootstrap: (settings: Partial<TsED.Configuration> & {
|
|
39
|
+
lambda?: Type[];
|
|
40
|
+
}) => any;
|
|
41
|
+
}, { server, ...settings }: PlatformBuilderSettings): () => Promise<any>;
|
|
42
|
+
/**
|
|
43
|
+
* Resets the test injector of the test context, so it won't pollute your next test. Call this in your `tearDown` logic.
|
|
44
|
+
*/
|
|
45
|
+
static reset(): Promise<void>;
|
|
46
|
+
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { APIGatewayEventDefaultAuthorizerContext, APIGatewayProxyEventBase } from "aws-lambda";
|
|
2
|
+
export declare function createFakeEvent(event?: Partial<APIGatewayProxyEventBase<APIGatewayEventDefaultAuthorizerContext>>): APIGatewayProxyEventBase<APIGatewayEventDefaultAuthorizerContext>;
|
package/package.json
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tsed/platform-serverless-testing",
|
|
3
|
+
"version": "6.91.0",
|
|
4
|
+
"description": "Module to test Serverless function with Ts.ED",
|
|
5
|
+
"source": "./src/index.ts",
|
|
6
|
+
"main": "./lib/cjs/index.js",
|
|
7
|
+
"typings": "./lib/types/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
"types": "./lib/types/index.d.ts",
|
|
10
|
+
"import": "./lib/esm/index.js",
|
|
11
|
+
"require": "./lib/cjs/index.js",
|
|
12
|
+
"default": "./lib/esm/index.js"
|
|
13
|
+
},
|
|
14
|
+
"scripts": {
|
|
15
|
+
"build": "yarn run build:esm && yarn run build:cjs",
|
|
16
|
+
"build:cjs": "tsc --build tsconfig.compile.json",
|
|
17
|
+
"build:esm": "tsc --build tsconfig.compile.esm.json"
|
|
18
|
+
},
|
|
19
|
+
"private": false,
|
|
20
|
+
"keywords": [
|
|
21
|
+
"aws",
|
|
22
|
+
"lambda",
|
|
23
|
+
"functions",
|
|
24
|
+
"TypeScript",
|
|
25
|
+
"typescript",
|
|
26
|
+
"Decorator",
|
|
27
|
+
"decorators",
|
|
28
|
+
"decorator",
|
|
29
|
+
"express",
|
|
30
|
+
"koa",
|
|
31
|
+
"Controller",
|
|
32
|
+
"Inject",
|
|
33
|
+
"ioc",
|
|
34
|
+
"di",
|
|
35
|
+
"mvc",
|
|
36
|
+
"swagger",
|
|
37
|
+
"swagger ui",
|
|
38
|
+
"ES2015",
|
|
39
|
+
"ES6",
|
|
40
|
+
"server",
|
|
41
|
+
"rest",
|
|
42
|
+
"api",
|
|
43
|
+
"validation"
|
|
44
|
+
],
|
|
45
|
+
"author": "Romain Lenzotti",
|
|
46
|
+
"license": "MIT",
|
|
47
|
+
"bugs": {
|
|
48
|
+
"url": "https://github.com/tsedio/tsed/issues"
|
|
49
|
+
},
|
|
50
|
+
"homepage": "https://github.com/tsedio/tsed/tree/production/packages/platform/platform-serverless-testing",
|
|
51
|
+
"repository": "https://github.com/tsedio/tsed",
|
|
52
|
+
"devDependencies": {
|
|
53
|
+
"@tsed/common": "6.91.0",
|
|
54
|
+
"@tsed/core": "6.91.0",
|
|
55
|
+
"@tsed/di": "6.91.0",
|
|
56
|
+
"@tsed/schema": "6.91.0"
|
|
57
|
+
},
|
|
58
|
+
"dependencies": {
|
|
59
|
+
"aws-lambda": "^1.0.7",
|
|
60
|
+
"tslib": "2.2.0"
|
|
61
|
+
},
|
|
62
|
+
"peerDependencies": {
|
|
63
|
+
"@tsed/common": "^6.91.0",
|
|
64
|
+
"@tsed/core": "^6.91.0",
|
|
65
|
+
"@tsed/di": "^6.91.0",
|
|
66
|
+
"@tsed/json-mapper": "^6.91.0",
|
|
67
|
+
"@tsed/logger": ">=6.0.0",
|
|
68
|
+
"@tsed/openspec": "^6.91.0",
|
|
69
|
+
"@tsed/schema": "^6.91.0"
|
|
70
|
+
}
|
|
71
|
+
}
|
package/readme.md
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
<p style="text-align: center" align="center">
|
|
2
|
+
<a href="https://tsed.io" target="_blank"><img src="https://tsed.io/tsed-og.png" width="200" alt="Ts.ED logo"/></a>
|
|
3
|
+
</p>
|
|
4
|
+
|
|
5
|
+
<div align="center">
|
|
6
|
+
<h1>Platform Serverless testing</h1>
|
|
7
|
+
|
|
8
|
+
[](https://github.com/tsedio/tsed/actions?query=workflow%3A%22Build+%26+Release%22)
|
|
9
|
+
[](https://github.com/tsedio/tsed/blob/master/CONTRIBUTING.md)
|
|
10
|
+
[](https://coveralls.io/github/tsedio/tsed?branch=production)
|
|
11
|
+
[](https://badge.fury.io/js/%40tsed%2Fcommon)
|
|
12
|
+
[](https://github.com/semantic-release/semantic-release)
|
|
13
|
+
[](https://github.com/prettier/prettier)
|
|
14
|
+
[](https://opencollective.com/tsed)
|
|
15
|
+
|
|
16
|
+
</div>
|
|
17
|
+
|
|
18
|
+
<div align="center">
|
|
19
|
+
<a href="https://tsed.io/">Website</a>
|
|
20
|
+
<span> • </span>
|
|
21
|
+
<a href="https://tsed.io/getting-started/">Getting started</a>
|
|
22
|
+
<span> • </span>
|
|
23
|
+
<a href="https://api.tsed.io/rest/slack/tsedio/tsed">Slack</a>
|
|
24
|
+
<span> • </span>
|
|
25
|
+
<a href="https://twitter.com/TsED_io">Twitter</a>
|
|
26
|
+
</div>
|
|
27
|
+
|
|
28
|
+
<hr />
|
|
29
|
+
|
|
30
|
+
A package of Ts.ED framework. See website: https://tsed.io/tutorials/aws.html
|
|
31
|
+
|
|
32
|
+
## Features
|
|
33
|
+
|
|
34
|
+
This package allows testing serverless function with Ts.ED
|
|
35
|
+
|
|
36
|
+
## Installation
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
npm install --save-dev @tsed/platform-serverless-testing
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## Contributors
|
|
43
|
+
|
|
44
|
+
Please read [contributing guidelines here](https://tsed.io/CONTRIBUTING.html)
|
|
45
|
+
|
|
46
|
+
<a href="https://github.com/tsedio/ts-express-decorators/graphs/contributors"><img src="https://opencollective.com/tsed/contributors.svg?width=890" /></a>
|
|
47
|
+
|
|
48
|
+
## Backers
|
|
49
|
+
|
|
50
|
+
Thank you to all our backers! 🙏 [[Become a backer](https://opencollective.com/tsed#backer)]
|
|
51
|
+
|
|
52
|
+
<a href="https://opencollective.com/tsed#backers" target="_blank"><img src="https://opencollective.com/tsed/backers.svg?width=890"></a>
|
|
53
|
+
|
|
54
|
+
## Sponsors
|
|
55
|
+
|
|
56
|
+
Support this project by becoming a sponsor. Your logo will show up here with a link to your
|
|
57
|
+
website. [[Become a sponsor](https://opencollective.com/tsed#sponsor)]
|
|
58
|
+
|
|
59
|
+
## License
|
|
60
|
+
|
|
61
|
+
The MIT License (MIT)
|
|
62
|
+
|
|
63
|
+
Copyright (c) 2016 - 2018 Romain Lenzotti
|
|
64
|
+
|
|
65
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
|
|
66
|
+
documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
|
|
67
|
+
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
|
|
68
|
+
persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
69
|
+
|
|
70
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
|
|
71
|
+
Software.
|
|
72
|
+
|
|
73
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
|
|
74
|
+
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
75
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
76
|
+
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import {DITest} from "@tsed/di";
|
|
2
|
+
import {APIGatewayEventDefaultAuthorizerContext, APIGatewayProxyEventBase, APIGatewayProxyHandler} from "aws-lambda";
|
|
3
|
+
import {APIGatewayProxyResult} from "aws-lambda/trigger/api-gateway-proxy";
|
|
4
|
+
import {createFakeEvent} from "./createFakeEvent";
|
|
5
|
+
import {createFakeContext} from "./createFakeContext";
|
|
6
|
+
import {nameOf, Type} from "@tsed/core";
|
|
7
|
+
import {PlatformBuilder, PlatformBuilderSettings} from "@tsed/common";
|
|
8
|
+
|
|
9
|
+
export interface LambdaPromiseResult extends Promise<APIGatewayProxyResult> {}
|
|
10
|
+
|
|
11
|
+
export class LambdaClientRequest extends Promise<APIGatewayProxyResult> {
|
|
12
|
+
event = createFakeEvent();
|
|
13
|
+
context = createFakeContext();
|
|
14
|
+
|
|
15
|
+
static call(lambdaName: string) {
|
|
16
|
+
const resolvers: any = {};
|
|
17
|
+
const promise = new LambdaClientRequest((resolve, reject) => {
|
|
18
|
+
resolvers.resolve = resolve;
|
|
19
|
+
resolvers.reject = reject;
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
promise.init(lambdaName, resolvers.resolve, resolvers.reject);
|
|
23
|
+
|
|
24
|
+
return promise;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
static get(path: string, options: Partial<APIGatewayProxyEventBase<APIGatewayEventDefaultAuthorizerContext>> = {}) {
|
|
28
|
+
return this.call("handler").get(path, options);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
static post(path: string, body?: any, options: Partial<APIGatewayProxyEventBase<APIGatewayEventDefaultAuthorizerContext>> = {}) {
|
|
32
|
+
return this.call("handler").post(path, body, options);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
static put(path: string, body?: any, options: Partial<APIGatewayProxyEventBase<APIGatewayEventDefaultAuthorizerContext>> = {}) {
|
|
36
|
+
return this.call("handler").put(path, body, options);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
static patch(path: string, body?: any, options: Partial<APIGatewayProxyEventBase<APIGatewayEventDefaultAuthorizerContext>> = {}) {
|
|
40
|
+
return this.call("handler").patch(path, body, options);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
static delete(path: string, body?: any, options: Partial<APIGatewayProxyEventBase<APIGatewayEventDefaultAuthorizerContext>> = {}) {
|
|
44
|
+
return this.call("handler").delete(path, body, options);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
get(path: string, options: Partial<APIGatewayProxyEventBase<APIGatewayEventDefaultAuthorizerContext>> = {}) {
|
|
48
|
+
Object.assign(this.event, options);
|
|
49
|
+
|
|
50
|
+
this.event.path = path;
|
|
51
|
+
this.event.httpMethod = "GET";
|
|
52
|
+
|
|
53
|
+
return this;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
post(path: string, body: any = {}, options: Partial<APIGatewayProxyEventBase<APIGatewayEventDefaultAuthorizerContext>> = {}) {
|
|
57
|
+
Object.assign(this.event, options);
|
|
58
|
+
|
|
59
|
+
this.event.path = path;
|
|
60
|
+
this.event.httpMethod = "POST";
|
|
61
|
+
|
|
62
|
+
this.body(body);
|
|
63
|
+
|
|
64
|
+
return this;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
patch(path: string, body: any = {}, options: Partial<APIGatewayProxyEventBase<APIGatewayEventDefaultAuthorizerContext>> = {}) {
|
|
68
|
+
Object.assign(this.event, options);
|
|
69
|
+
|
|
70
|
+
this.event.path = path;
|
|
71
|
+
this.event.httpMethod = "PATCH";
|
|
72
|
+
|
|
73
|
+
this.body(body);
|
|
74
|
+
|
|
75
|
+
return this;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
put(path: string, body: any = {}, options: Partial<APIGatewayProxyEventBase<APIGatewayEventDefaultAuthorizerContext>> = {}) {
|
|
79
|
+
Object.assign(this.event, options);
|
|
80
|
+
|
|
81
|
+
this.event.path = path;
|
|
82
|
+
this.event.httpMethod = "PUT";
|
|
83
|
+
|
|
84
|
+
this.body(body);
|
|
85
|
+
|
|
86
|
+
return this;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
delete(path: string, body: any = {}, options: Partial<APIGatewayProxyEventBase<APIGatewayEventDefaultAuthorizerContext>> = {}) {
|
|
90
|
+
Object.assign(this.event, options);
|
|
91
|
+
|
|
92
|
+
this.event.path = path;
|
|
93
|
+
this.event.httpMethod = "DELETE";
|
|
94
|
+
|
|
95
|
+
this.body(body);
|
|
96
|
+
|
|
97
|
+
return this;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
query(query: any) {
|
|
101
|
+
this.event.queryStringParameters = {
|
|
102
|
+
...this.event.queryStringParameters,
|
|
103
|
+
...JSON.parse(JSON.stringify(query))
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
return this;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
params(pathParameters: any) {
|
|
110
|
+
this.event.pathParameters = {
|
|
111
|
+
...this.event.pathParameters,
|
|
112
|
+
...JSON.parse(JSON.stringify(pathParameters))
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
return this;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
headers(headers: Record<string, any>) {
|
|
119
|
+
this.event.headers = {
|
|
120
|
+
...this.event.headers,
|
|
121
|
+
...JSON.parse(JSON.stringify(headers))
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
return this;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
body(body: any) {
|
|
128
|
+
if (body !== undefined) {
|
|
129
|
+
this.event.headers["content-type"] = "application/json";
|
|
130
|
+
|
|
131
|
+
this.event.body = JSON.stringify(body);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
return this;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
protected init(lambda: string, resolve: Function, reject: Function) {
|
|
138
|
+
setTimeout(async () => {
|
|
139
|
+
try {
|
|
140
|
+
const result = await PlatformServerlessTest.callbacks[lambda](this.event, this.context, resolve as any);
|
|
141
|
+
resolve(result as any);
|
|
142
|
+
} catch (er) {
|
|
143
|
+
reject(er);
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
export class PlatformServerlessTest extends DITest {
|
|
150
|
+
static callbacks: Record<string, APIGatewayProxyHandler> = {};
|
|
151
|
+
static instance: any;
|
|
152
|
+
static request = LambdaClientRequest;
|
|
153
|
+
|
|
154
|
+
static bootstrap(
|
|
155
|
+
serverless: {bootstrap: (server: Type<any>, settings: PlatformBuilderSettings) => PlatformBuilder},
|
|
156
|
+
{server, ...settings}: PlatformBuilderSettings & {server: Type<any>}
|
|
157
|
+
): () => Promise<any>;
|
|
158
|
+
static bootstrap(
|
|
159
|
+
serverless: {bootstrap: (settings: Partial<TsED.Configuration> & {lambda?: Type[]}) => any},
|
|
160
|
+
{server, ...settings}: PlatformBuilderSettings
|
|
161
|
+
): () => Promise<any>;
|
|
162
|
+
static bootstrap(serverless: any, {server, ...settings}: PlatformBuilderSettings) {
|
|
163
|
+
return async function before(): Promise<void> {
|
|
164
|
+
settings = DITest.configure(settings);
|
|
165
|
+
|
|
166
|
+
const isServerlessHttp = nameOf(serverless).includes("Http");
|
|
167
|
+
|
|
168
|
+
// @ts-ignore
|
|
169
|
+
const instance = isServerlessHttp ? serverless.bootstrap(server, settings) : serverless.bootstrap(settings);
|
|
170
|
+
|
|
171
|
+
PlatformServerlessTest.instance = instance;
|
|
172
|
+
PlatformServerlessTest.callbacks = {};
|
|
173
|
+
|
|
174
|
+
if (!isServerlessHttp) {
|
|
175
|
+
PlatformServerlessTest.callbacks = instance.callbacks();
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
PlatformServerlessTest.callbacks.handler = instance.handler();
|
|
179
|
+
// used by inject method
|
|
180
|
+
DITest.injector = instance.injector;
|
|
181
|
+
|
|
182
|
+
return instance.promise;
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Resets the test injector of the test context, so it won't pollute your next test. Call this in your `tearDown` logic.
|
|
188
|
+
*/
|
|
189
|
+
static async reset() {
|
|
190
|
+
if (PlatformServerlessTest.instance) {
|
|
191
|
+
await PlatformServerlessTest.instance.stop();
|
|
192
|
+
}
|
|
193
|
+
if (DITest.hasInjector()) {
|
|
194
|
+
await DITest.injector.destroy();
|
|
195
|
+
DITest._injector = null;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import {Context} from "aws-lambda";
|
|
2
|
+
|
|
3
|
+
export function createFakeContext(context?: Context): Context {
|
|
4
|
+
return {
|
|
5
|
+
awsRequestId: "awsRequestId",
|
|
6
|
+
callbackWaitsForEmptyEventLoop: false,
|
|
7
|
+
functionName: "",
|
|
8
|
+
functionVersion: "",
|
|
9
|
+
invokedFunctionArn: "",
|
|
10
|
+
logGroupName: "",
|
|
11
|
+
logStreamName: "",
|
|
12
|
+
memoryLimitInMB: "",
|
|
13
|
+
...(context || {})
|
|
14
|
+
} as Context;
|
|
15
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import {APIGatewayEventDefaultAuthorizerContext, APIGatewayProxyEventBase} from "aws-lambda";
|
|
2
|
+
|
|
3
|
+
export function createFakeEvent(event: Partial<APIGatewayProxyEventBase<APIGatewayEventDefaultAuthorizerContext>> = {}) {
|
|
4
|
+
return {
|
|
5
|
+
body: "",
|
|
6
|
+
headers: {},
|
|
7
|
+
httpMethod: "",
|
|
8
|
+
isBase64Encoded: false,
|
|
9
|
+
multiValueHeaders: {},
|
|
10
|
+
multiValueQueryStringParameters: {},
|
|
11
|
+
path: event.path || "/",
|
|
12
|
+
pathParameters: {},
|
|
13
|
+
queryStringParameters: {},
|
|
14
|
+
resource: "",
|
|
15
|
+
stageVariables: {},
|
|
16
|
+
...event,
|
|
17
|
+
requestContext: {
|
|
18
|
+
...event?.requestContext,
|
|
19
|
+
accountId: "",
|
|
20
|
+
apiId: "",
|
|
21
|
+
protocol: "https",
|
|
22
|
+
httpMethod: "",
|
|
23
|
+
identity: {} as any,
|
|
24
|
+
path: event.path || "/",
|
|
25
|
+
stage: "",
|
|
26
|
+
requestId: "requestId",
|
|
27
|
+
requestTimeEpoch: 0,
|
|
28
|
+
resourceId: 1,
|
|
29
|
+
resourcePath: event.path || "/"
|
|
30
|
+
} as any
|
|
31
|
+
} as APIGatewayProxyEventBase<APIGatewayEventDefaultAuthorizerContext>;
|
|
32
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "./tsconfig.compile.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"baseUrl": ".",
|
|
5
|
+
"module": "ES2020",
|
|
6
|
+
"rootDir": "src",
|
|
7
|
+
"outDir": "./lib/esm",
|
|
8
|
+
"declaration": true,
|
|
9
|
+
"declarationDir": "./lib/types"
|
|
10
|
+
},
|
|
11
|
+
"exclude": [
|
|
12
|
+
"node_modules",
|
|
13
|
+
"test",
|
|
14
|
+
"lib",
|
|
15
|
+
"benchmark",
|
|
16
|
+
"coverage",
|
|
17
|
+
"spec",
|
|
18
|
+
"**/*.benchmark.ts",
|
|
19
|
+
"**/*.spec.ts",
|
|
20
|
+
"keys",
|
|
21
|
+
"jest.config.js"
|
|
22
|
+
]
|
|
23
|
+
}
|