Comparing version 0.27.1 to 0.28.0
@@ -84,2 +84,3 @@ import { SSM } from 'aws-sdk' | ||
onWarmup?: (event: any) => void; | ||
waitForEmptyEventLoop?: boolean; | ||
} | ||
@@ -86,0 +87,0 @@ |
{ | ||
"name": "middy", | ||
"version": "0.27.1", | ||
"version": "0.28.0", | ||
"description": "🛵 The stylish Node.js middleware engine for AWS Lambda", | ||
@@ -5,0 +5,0 @@ "main": "./index.js", |
@@ -78,2 +78,67 @@ const middy = require('../../middy') | ||
}) | ||
test(`Should execute handler with callbackWaitsForEmptyEventLoop if waitForEmptyEventLoop true`, (endTest) => { | ||
console.log = jest.fn() | ||
const handler = middy((event, context, cb) => { | ||
cb() | ||
}) | ||
handler.use(lambdaIsWarmingUp({ | ||
waitForEmptyEventLoop: true | ||
})) | ||
const event = { | ||
source: 'serverless-plugin-warmup' | ||
} | ||
const context = {} | ||
handler(event, context, (_, response) => { | ||
expect(context.callbackWaitsForEmptyEventLoop).toBe(true) | ||
expect(response).toBe('warmup') | ||
endTest() | ||
}) | ||
}) | ||
test(`Should execute handler with callbackWaitsForEmptyEventLoop if waitForEmptyEventLoop false`, (endTest) => { | ||
console.log = jest.fn() | ||
const handler = middy((event, context, cb) => { | ||
cb() | ||
}) | ||
handler.use(lambdaIsWarmingUp({ | ||
waitForEmptyEventLoop: false | ||
})) | ||
const event = { | ||
source: 'serverless-plugin-warmup' | ||
} | ||
const context = { | ||
callbackWaitsForEmptyEventLoop: true | ||
} | ||
handler(event, context, (_, response) => { | ||
expect(context.callbackWaitsForEmptyEventLoop).toBe(false) | ||
expect(response).toBe('warmup') | ||
endTest() | ||
}) | ||
}) | ||
test(`Should execute handler with callbackWaitsForEmptyEventLoop unchanged if waitForEmptyEventLoop is not set`, (endTest) => { | ||
console.log = jest.fn() | ||
const handler = middy((event, context, cb) => { | ||
cb() | ||
}) | ||
handler.use(lambdaIsWarmingUp({})) | ||
const event = { | ||
source: 'serverless-plugin-warmup' | ||
} | ||
const context = { | ||
callbackWaitsForEmptyEventLoop: true | ||
} | ||
handler(event, context, (_, response) => { | ||
expect(context.callbackWaitsForEmptyEventLoop).toBe(true) | ||
expect(response).toBe('warmup') | ||
endTest() | ||
}) | ||
}) | ||
}) |
module.exports = (config) => { | ||
const defaults = { | ||
isWarmingUp: (event) => event.source === 'serverless-plugin-warmup', | ||
onWarmup: (event) => console.log('Exiting early via warmup Middleware') | ||
onWarmup: (event) => console.log('Exiting early via warmup Middleware'), | ||
waitForEmptyEventLoop: null | ||
} | ||
@@ -13,2 +14,5 @@ | ||
options.onWarmup(handler.event) | ||
if (options.waitForEmptyEventLoop !== null) { | ||
handler.context.callbackWaitsForEmptyEventLoop = Boolean(options.waitForEmptyEventLoop) | ||
} | ||
return handler.callback(null, 'warmup') | ||
@@ -15,0 +19,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
184321
4656