Skip to content

Commit

Permalink
Port waitForEmptyEventLoop in Warmup middlware (middyjs#345) to v.1.0…
Browse files Browse the repository at this point in the history
….0 branch (middyjs#354)

* Port waitForEmptyEventLoop in Warmup middlware (middyjs#345) to v.1.0.0 branch

* version bump
  • Loading branch information
lmammino authored and benjifs committed May 21, 2020
1 parent 33c2020 commit 545690f
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions packages/warmup/__tests__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,69 @@ describe('🥃 Warmup', () => {
endTest()
})
})

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()
})
})
})

0 comments on commit 545690f

Please sign in to comment.