Skip to content

Commit

Permalink
Merge pull request #1 from 75lb/master
Browse files Browse the repository at this point in the history
inherit the original middleware's name
  • Loading branch information
gyson committed Nov 16, 2015
2 parents 47548f5 + 2339659 commit d0d6649
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
4 changes: 3 additions & 1 deletion index.js
Expand Up @@ -13,9 +13,11 @@ function convert (mw) {
// assume it's Promise-based middleware
return mw
}
return function (ctx, next) {
const converted = function (ctx, next) {
return co.call(ctx, mw.call(ctx, createGenerator(next)))
}
converted._name = mw._name || mw.name
return converted
}

function * createGenerator (next) {
Expand Down
5 changes: 5 additions & 0 deletions test.js
Expand Up @@ -25,6 +25,11 @@ describe('convert()', () => {
})
})

it('should inherit the original middleware name', () => {
let mw = convert(function * testing (next) {})
assert.strictEqual(mw._name, 'testing')
})

it('should work with `yield next`', () => {
let call = []
let ctx = {}
Expand Down

0 comments on commit d0d6649

Please sign in to comment.