Socket
Socket
Sign inDemoInstall

middy

Package Overview
Dependencies
Maintainers
8
Versions
147
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

middy - npm Package Compare versions

Comparing version 0.27.1 to 0.28.0

1

middlewares.d.ts

@@ -84,2 +84,3 @@ import { SSM } from 'aws-sdk'

onWarmup?: (event: any) => void;
waitForEmptyEventLoop?: boolean;
}

@@ -86,0 +87,0 @@

2

package.json
{
"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 @@ }

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc