@middy/do-not-wait-for-empty-event-loop
Advanced tools
Comparing version 1.0.0-alpha.42 to 1.0.0-alpha.43
@@ -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" | ||
} |
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
11053
2
146