Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Actually rejects when await app.after() or await app.register() #97

Merged
merged 2 commits into from
Feb 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ Plugin.prototype._pushToAsyncQ = function (fn) {
debug('_pushToAsyncQ', this.name)
if (this.asyncQ.length() === 0) {
this.server.after((err, cb) => {
this._error = err
this.q.pause()
debug('resuming asyncQ', this.name)
this.asyncQ.resume()
Expand Down
8 changes: 5 additions & 3 deletions test/after-pass-through.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,17 @@ boot(app)

t.plan(5)

const e = new Error('kaboom')

app.use(function (f, opts) {
return Promise.reject(new Error('kaboom'))
return Promise.reject(e)
}).after(function (err, cb) {
t.pass('this is just called')
t.is(err, e)
cb(err)
}).after(function () {
t.pass('this is just called')
}).after(function (err, cb) {
t.pass('this is just called')
t.is(err, e)
cb(err)
})

Expand Down
46 changes: 27 additions & 19 deletions test/await-after.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,89 +138,95 @@ test('await after - error handling, async throw', async (t) => {
const app = {}
boot(app)

t.plan(1)
t.plan(2)

const e = new Error('kaboom')

app.use(async (f, opts) => {
throw Error('kaboom')
})

await app.after()
await t.rejects(app.after(), e)

t.rejects(() => app.ready(), Error('kaboom'))
await t.rejects(() => app.ready(), Error('kaboom'))
})

test('await after - error handling, async throw, nested', async (t) => {
const app = {}
boot(app)

t.plan(1)
t.plan(2)

const e = new Error('kaboom')

app.use(async (f, opts) => {
app.use(async (f, opts) => {
throw Error('kaboom')
throw e
})
})
await app.after()

t.rejects(() => app.ready(), Error('kaboom'))
await t.rejects(app.after())
await t.rejects(() => app.ready(), e)
})

test('await after - error handling, same tick cb err', async (t) => {
const app = {}
boot(app)

t.plan(1)
t.plan(2)

app.use((f, opts, cb) => {
cb(Error('kaboom'))
})
await app.after()
t.rejects(() => app.ready(), Error('kaboom'))
await t.rejects(app.after())
await t.rejects(app.ready(), Error('kaboom'))
})

test('await after - error handling, same tick cb err, nested', async (t) => {
const app = {}
boot(app)

t.plan(1)
t.plan(2)

app.use((f, opts, cb) => {
app.use((f, opts, cb) => {
cb(Error('kaboom'))
})
cb()
})
await app.after()
t.rejects(() => app.ready(), Error('kaboom'))

await t.rejects(app.after())
await t.rejects(app.ready(), Error('kaboom'))
})

test('await after - error handling, future tick cb err', async (t) => {
const app = {}
boot(app)

t.plan(1)
t.plan(2)

app.use((f, opts, cb) => {
setImmediate(() => { cb(Error('kaboom')) })
})
await app.after()
t.rejects(() => app.ready(), Error('kaboom'))

await t.rejects(app.after())
await t.rejects(app.ready(), Error('kaboom'))
})

test('await after - error handling, future tick cb err, nested', async (t) => {
const app = {}
boot(app)

t.plan(1)
t.plan(2)

app.use((f, opts, cb) => {
app.use((f, opts, cb) => {
setImmediate(() => { cb(Error('kaboom')) })
})
cb()
})
await app.after()
t.rejects(() => app.ready(), Error('kaboom'))
await t.rejects(app.after(), Error('kaboom'))
await t.rejects(app.ready(), Error('kaboom'))
})

test('await after complex scenario', async (t) => {
Expand Down Expand Up @@ -332,6 +338,8 @@ test('without autostart and with override', async (t) => {
})

test('stop processing after errors', async (t) => {
t.plan(2)

const app = boot()

try {
Expand Down
46 changes: 25 additions & 21 deletions test/await-use.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,30 +104,34 @@ test('await use - await and use chaining', async (t) => {
t.pass('reachable')
})

function thenableRejects (t, thenable, err) {
return t.rejects(async () => { await thenable }, err)
}

test('await use - error handling, async throw', async (t) => {
const app = {}
boot(app)

t.plan(1)
t.plan(2)

await app.use(async (f, opts) => {
await thenableRejects(t, app.use(async (f, opts) => {
throw Error('kaboom')
})
}), Error('kaboom'))

t.rejects(() => app.ready(), Error('kaboom'))
await t.rejects(app.ready(), Error('kaboom'))
})

test('await use - error handling, async throw, nested', async (t) => {
const app = {}
boot(app)

t.plan(1)
t.plan(3)

await app.use(async (f, opts) => {
await app.use(async (f, opts) => {
await thenableRejects(t, app.use(async (f, opts) => {
await thenableRejects(t, app.use(async (f, opts) => {
throw Error('kaboom')
})
})
}), Error('kaboom'))
}, Error('kaboom')))

t.rejects(() => app.ready(), Error('kaboom'))
})
Expand All @@ -136,11 +140,11 @@ test('await use - error handling, same tick cb err', async (t) => {
const app = {}
boot(app)

t.plan(1)
t.plan(2)

await app.use((f, opts, cb) => {
await thenableRejects(t, app.use((f, opts, cb) => {
cb(Error('kaboom'))
})
}), Error('kaboom'))

t.rejects(() => app.ready(), Error('kaboom'))
})
Expand All @@ -149,14 +153,14 @@ test('await use - error handling, same tick cb err, nested', async (t) => {
const app = {}
boot(app)

t.plan(1)
t.plan(2)

await app.use((f, opts, cb) => {
await thenableRejects(t, app.use((f, opts, cb) => {
app.use((f, opts, cb) => {
cb(Error('kaboom'))
})
cb()
})
}), Error('kaboom'))

t.rejects(() => app.ready(), Error('kaboom'))
})
Expand All @@ -165,11 +169,11 @@ test('await use - error handling, future tick cb err', async (t) => {
const app = {}
boot(app)

t.plan(1)
t.plan(2)

await app.use((f, opts, cb) => {
await thenableRejects(t, app.use((f, opts, cb) => {
setImmediate(() => { cb(Error('kaboom')) })
})
}), Error('kaboom'))

t.rejects(() => app.ready(), Error('kaboom'))
})
Expand All @@ -178,14 +182,14 @@ test('await use - error handling, future tick cb err, nested', async (t) => {
const app = {}
boot(app)

t.plan(1)
t.plan(2)

await app.use((f, opts, cb) => {
await thenableRejects(t, app.use((f, opts, cb) => {
app.use((f, opts, cb) => {
setImmediate(() => { cb(Error('kaboom')) })
})
cb()
})
}), Error('kaboom'))

t.rejects(() => app.ready(), Error('kaboom'))
})
Expand Down