@middy/core
Advanced tools
Comparing version 1.0.0-alpha.11 to 1.0.0-alpha.12
@@ -432,2 +432,35 @@ const middy = require('../') | ||
describe('A callback passed to an async handler should only be called once', () => { | ||
const checkHandler = (handler, endTest) => { | ||
let calls = 0 | ||
handler({}, {}, () => calls++) | ||
setTimeout(() => { | ||
expect(calls).toBe(1) | ||
endTest() | ||
}, 100) | ||
} | ||
test('onSuccess', (endTest) => { | ||
const handler = middy((event, context, callback) => { | ||
return new Promise(resolve => setTimeout(() => { | ||
callback() | ||
resolve() | ||
}, 50)) | ||
}) | ||
checkHandler(handler, endTest) | ||
}) | ||
test('onError', (endTest) => { | ||
const handler = middy((event, context, callback) => { | ||
return new Promise((resolve, reject) => setTimeout(() => { | ||
const error = new Error('Async error') | ||
callback(error) | ||
reject(error) | ||
}, 50)) | ||
}) | ||
checkHandler(handler, endTest) | ||
}) | ||
}) | ||
test('A handler that returns a rejected promise will behave as an errored execution', (endTest) => { | ||
@@ -434,0 +467,0 @@ const handler = middy((event, context) => { |
const isPromise = require('./isPromise') | ||
const once = require('once') | ||
@@ -165,8 +166,8 @@ /** | ||
const onHandlerError = (err) => { | ||
const onHandlerError = once((err) => { | ||
instance.response = null | ||
return errorHandler(err) | ||
} | ||
}) | ||
const onHandlerSuccess = (response) => { | ||
const onHandlerSuccess = once((response) => { | ||
instance.response = response | ||
@@ -178,3 +179,3 @@ runMiddlewares(afterMiddlewares, instance, (err) => { | ||
}) | ||
} | ||
}) | ||
@@ -181,0 +182,0 @@ const handlerReturnValue = handler.call(instance, instance.event, context, (err, response) => { |
@@ -9,4 +9,17 @@ { | ||
"integrity": "sha512-p6pNNZ/VERiboy/S9ygkmimqZC082RzDE9SXcTUbsKRW5p0kbq+Yrt8IVlf49CM/F45nRPdCCPJtGembGHYtWg==" | ||
}, | ||
"once": { | ||
"version": "1.4.0", | ||
"resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", | ||
"integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=", | ||
"requires": { | ||
"wrappy": "1" | ||
} | ||
}, | ||
"wrappy": { | ||
"version": "1.0.2", | ||
"resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", | ||
"integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=" | ||
} | ||
} | ||
} |
{ | ||
"name": "@middy/core", | ||
"version": "1.0.0-alpha.11", | ||
"version": "1.0.0-alpha.12", | ||
"description": "🛵 The stylish Node.js middleware engine for AWS Lambda (core package)", | ||
@@ -39,4 +39,5 @@ "engines": { | ||
"dependencies": { | ||
"@types/aws-lambda": "^8.10.3" | ||
"@types/aws-lambda": "^8.10.3", | ||
"once": "^1.4.0" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
29673
800
2
+ Addedonce@^1.4.0
+ Addedonce@1.4.0(transitive)
+ Addedwrappy@1.0.2(transitive)