serverless-spy 2.2.1 → 2.2.3
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/.jsii +2 -2
- package/common/SpyEventSender.ts +3 -1
- package/common/spyEvents/DynamoDBSpyEvent.ts +1 -1
- package/dist/releasetag.txt +1 -1
- package/extension/aws/UserFunction.js +0 -3
- package/lib/common/SpyEventSender.js +4 -2
- package/lib/common/SpyEventSender.mjs +4 -2
- package/lib/common/spyEvents/DynamoDBSpyEvent.d.ts +1 -1
- package/lib/common/spyEvents/DynamoDBSpyEvent.js +1 -1
- package/lib/common/spyEvents/DynamoDBSpyEvent.mjs +1 -1
- package/lib/extension/dist/layer/nodejs/node_modules/interceptor.js +1 -1
- package/lib/extension/dist/layer/nodejs/node_modules/interceptor.js.map +2 -2
- package/lib/listener/WsListener.js +27 -23
- package/lib/listener/WsListener.mjs +27 -23
- package/lib/src/ServerlessSpy.js +1 -1
- package/listener/WsListener.ts +30 -31
- package/package.json +1 -1
package/listener/WsListener.ts
CHANGED
|
@@ -5,7 +5,6 @@ import { ServerlessSpyListenerParams } from './ServerlessSpyListenerParams';
|
|
|
5
5
|
import { getTopic } from './topic';
|
|
6
6
|
import { WaitForParams } from './WaitForParams';
|
|
7
7
|
import { FunctionRequestSpyEvent } from '../common/spyEvents/FunctionRequestSpyEvent';
|
|
8
|
-
import { SpyEvent } from '../common/spyEvents/SpyEvent';
|
|
9
8
|
import { SpyMessage } from '../common/spyEvents/SpyMessage';
|
|
10
9
|
|
|
11
10
|
export class WsListener<TSpyEvents> {
|
|
@@ -229,46 +228,49 @@ export class WsListener<TSpyEvents> {
|
|
|
229
228
|
serviceKeyForFunction: string,
|
|
230
229
|
functionContextAwsRequestId?: string
|
|
231
230
|
) {
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
231
|
+
return (paramsW?: WaitForParams) => {
|
|
232
|
+
let resolve: (value: void | PromiseLike<any>) => void;
|
|
233
|
+
const promise = new Promise((res) => {
|
|
234
|
+
resolve = res;
|
|
235
|
+
});
|
|
236
|
+
const tracker: Tracker = {
|
|
236
237
|
finished: false,
|
|
238
|
+
// @ts-ignore
|
|
237
239
|
promiseResolve: resolve,
|
|
238
|
-
promiseReject: reject,
|
|
239
240
|
serviceKeyForFunction,
|
|
240
241
|
functionContextAwsRequestId,
|
|
241
242
|
};
|
|
242
|
-
});
|
|
243
243
|
|
|
244
|
-
return (paramsW?: WaitForParams<SpyEvent>) => {
|
|
245
244
|
tracker.condition = paramsW?.condition;
|
|
246
245
|
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
}, paramsW?.timoutMs || 10000);
|
|
246
|
+
let timeoutPid: NodeJS.Timeout | undefined;
|
|
247
|
+
const timer = new Promise((_, reject) => {
|
|
248
|
+
timeoutPid = setTimeout(() => {
|
|
249
|
+
if (tracker.finished) return;
|
|
250
|
+
tracker.finished = true;
|
|
251
|
+
let message = `Timeout waiting for Serverless Spy message ${serviceKeyForFunction}.`;
|
|
252
|
+
|
|
253
|
+
if (tracker.possibleSpyMessageDataForDebugging) {
|
|
254
|
+
message += ` Similar matching spy event data: ${JSON.stringify(
|
|
255
|
+
tracker.possibleSpyMessageDataForDebugging,
|
|
256
|
+
null,
|
|
257
|
+
2
|
|
258
|
+
)}`;
|
|
259
|
+
}
|
|
262
260
|
|
|
263
|
-
|
|
264
|
-
|
|
261
|
+
reject(new Error(message));
|
|
262
|
+
}, paramsW?.timoutMs || 10000);
|
|
265
263
|
});
|
|
266
264
|
|
|
267
265
|
if (!this.resolveTrackerInOldMessages(tracker)) {
|
|
268
266
|
this.trackers.push(tracker);
|
|
269
267
|
}
|
|
270
268
|
|
|
271
|
-
return promise
|
|
269
|
+
return Promise.race([promise, timer]).finally(() => {
|
|
270
|
+
if (!!timeoutPid) {
|
|
271
|
+
clearTimeout(timeoutPid);
|
|
272
|
+
}
|
|
273
|
+
});
|
|
272
274
|
};
|
|
273
275
|
}
|
|
274
276
|
|
|
@@ -279,10 +281,10 @@ export class WsListener<TSpyEvents> {
|
|
|
279
281
|
await this.stop();
|
|
280
282
|
};
|
|
281
283
|
|
|
282
|
-
|
|
284
|
+
return new Proxy<ServerlessSpyListener<TSpyEvents>>(spyListener, {
|
|
283
285
|
get: (target: any, objectKey: string) => {
|
|
284
286
|
if (target.hasOwnProperty(objectKey)) {
|
|
285
|
-
return target[objectKey];
|
|
287
|
+
return target[objectKey].bind(target);
|
|
286
288
|
} else if (
|
|
287
289
|
typeof objectKey === 'string' &&
|
|
288
290
|
objectKey.startsWith(this.functionPrefix)
|
|
@@ -295,8 +297,6 @@ export class WsListener<TSpyEvents> {
|
|
|
295
297
|
}
|
|
296
298
|
},
|
|
297
299
|
});
|
|
298
|
-
|
|
299
|
-
return proxy as ServerlessSpyListener<TSpyEvents>;
|
|
300
300
|
}
|
|
301
301
|
|
|
302
302
|
private log(message: string, ...optionalParams: any[]) {
|
|
@@ -313,7 +313,6 @@ export class WsListener<TSpyEvents> {
|
|
|
313
313
|
|
|
314
314
|
type Tracker = {
|
|
315
315
|
promiseResolve: (data: any) => void;
|
|
316
|
-
promiseReject: (data: any) => void;
|
|
317
316
|
finished: boolean;
|
|
318
317
|
serviceKey?: string;
|
|
319
318
|
serviceKeyForFunction?: string;
|