Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@middy/do-not-wait-for-empty-event-loop

Package Overview
Dependencies
Maintainers
10
Versions
223
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@middy/do-not-wait-for-empty-event-loop - npm Package Compare versions

Comparing version 1.0.0-alpha.42 to 1.0.0-alpha.43

97

__tests__/index.js

@@ -0,1 +1,2 @@

const { invoke } = require('../../test-helpers')
const middy = require('../../core')

@@ -6,31 +7,28 @@ const doNotWaitForEmptyEventLoop = require('../')

describe('👌 With Default Options', () => {
test('It should set callbackWaitsForEmptyEventLoop to false by default', () => {
test('It should set callbackWaitsForEmptyEventLoop to false by default', async () => {
const handler = middy((event, context, cb) => {
cb()
})
handler.use(doNotWaitForEmptyEventLoop())
}).use(doNotWaitForEmptyEventLoop())
const event = {}
const context = {}
handler(event, context, () => {
expect(context.callbackWaitsForEmptyEventLoop).toEqual(false)
})
await invoke(handler, {}, context)
expect(context.callbackWaitsForEmptyEventLoop).toEqual(false)
})
test('callbackWaitsForEmptyEventLoop should remain true if was overridden by user in handler', () => {
test('callbackWaitsForEmptyEventLoop should remain true if was overridden by user in handler', async () => {
const handler = middy((event, context, cb) => {
context.callbackWaitsForEmptyEventLoop = true
cb()
})
}).use(doNotWaitForEmptyEventLoop())
handler.use(doNotWaitForEmptyEventLoop())
const context = {}
const event = {}
const context = {}
handler(event, context, () => {
expect(context.callbackWaitsForEmptyEventLoop).toEqual(true)
})
await invoke(handler, {}, context)
expect(context.callbackWaitsForEmptyEventLoop).toEqual(true)
})
test('callbackWaitsForEmptyEventLoop should stay false if handler has error', () => {
test('callbackWaitsForEmptyEventLoop should stay false if handler has error', async () => {
const handler = middy((event, context, cb) => {

@@ -42,7 +40,9 @@ cb(new Error('!'))

const event = {}
const context = {}
handler(event, context, () => {
expect(context.callbackWaitsForEmptyEventLoop).toEqual(false)
})
try {
await invoke(handler, {}, context)
} catch (e) {}
expect(context.callbackWaitsForEmptyEventLoop).toEqual(false)
})

@@ -52,3 +52,3 @@ })

describe('✍️ With Overridden Options', () => {
test('callbackWaitsForEmptyEventLoop should be false when runOnAfter is true in options', () => {
test('callbackWaitsForEmptyEventLoop should be false when runOnAfter is true in options', async () => {
const handler = middy((event, context, cb) => {

@@ -63,10 +63,10 @@ context.callbackWaitsForEmptyEventLoop = true

const event = {}
const context = {}
handler(event, context, () => {
expect(context.callbackWaitsForEmptyEventLoop).toEqual(false)
})
await invoke(handler, {}, context)
expect(context.callbackWaitsForEmptyEventLoop).toEqual(false)
})
test('callbackWaitsForEmptyEventLoop should remain true when error occurs even if runOnAfter is true', () => {
test('callbackWaitsForEmptyEventLoop should remain true when error occurs even if runOnAfter is true', async () => {
const handler = middy((event, context, cb) => {

@@ -81,10 +81,12 @@ context.callbackWaitsForEmptyEventLoop = true

const event = {}
const context = {}
handler(event, context, () => {
expect(context.callbackWaitsForEmptyEventLoop).toEqual(true)
})
try {
await invoke(handler, {}, context)
} catch (e) {}
expect(context.callbackWaitsForEmptyEventLoop).toEqual(true)
})
test('callbackWaitsForEmptyEventLoop should be false when error occurs but runOnError is true', () => {
test('callbackWaitsForEmptyEventLoop should be false when error occurs but runOnError is true', async () => {
const handler = middy((event, context, cb) => {

@@ -100,10 +102,14 @@ context.callbackWaitsForEmptyEventLoop = true

const event = {}
const context = {}
handler(event, context, () => {
expect(context.callbackWaitsForEmptyEventLoop).toEqual(false)
})
try {
await invoke(handler, {}, context)
} catch (e) {}
expect(context.callbackWaitsForEmptyEventLoop).toEqual(false)
})
test('thrown error should be propagated when it occurs & runOnError is true', (done) => {
test('thrown error should be propagated when it occurs & runOnError is true', async () => {
expect.assertions(1)
const handler = middy((event, context, cb) => {

@@ -119,11 +125,12 @@ context.callbackWaitsForEmptyEventLoop = true

const event = {}
const context = {}
handler(event, context, (error) => {
try {
await invoke(handler, {}, context)
} catch (error) {
expect(error.message).toEqual('!')
done()
})
}
})
test('callbackWaitsForEmptyEventLoop should be false in handler but true after if set by options', () => {
test('callbackWaitsForEmptyEventLoop should be false in handler but true after if set by options', async () => {
expect.assertions(2)

@@ -141,11 +148,11 @@

const event = {}
const context = {
callbackWaitsForEmptyEventLoop: true
}
handler(event, context, () => {
expect(context.callbackWaitsForEmptyEventLoop).toEqual(false)
})
await invoke(handler, {}, context)
expect(context.callbackWaitsForEmptyEventLoop).toEqual(false)
})
})
})
{
"name": "@middy/do-not-wait-for-empty-event-loop",
"version": "1.0.0-alpha.42",
"version": "1.0.0-alpha.43",
"description": "Middleware for the middy framework that allows to easily disable the wait for empty event loop in a Lambda function",

@@ -44,5 +44,6 @@ "engines": {

"devDependencies": {
"@middy/core": "^1.0.0-alpha.42"
"@middy/core": "^1.0.0-alpha.43",
"es6-promisify": "^6.0.2"
},
"gitHead": "c9e64d026e86359bb3f78c4a3783569e1241728c"
"gitHead": "d6bbe8d97ee90856bb5a4da07ccb81d1a570a513"
}
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