Skip to content
This repository has been archived by the owner on Aug 31, 2024. It is now read-only.

Commit

Permalink
inherit original name for convert.back
Browse files Browse the repository at this point in the history
  • Loading branch information
gyson committed Nov 16, 2015
1 parent d0d6649 commit fe140c0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
4 changes: 3 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ convert.back = function (mw) {
// assume it's generator middleware
return mw
}
return function * (next) {
const converted = function * (next) {
let ctx = this
let called = false
// no need try...catch here, it's ok even `mw()` throw exception
Expand All @@ -55,4 +55,6 @@ convert.back = function (mw) {
return co.call(ctx, next)
}))
}
converted._name = mw._name || mw.name
return converted
}
5 changes: 5 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,11 @@ describe('convert.back()', () => {
.expect(200, [1, 2, 'next() called multiple times'])
.end(done)
})

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

describe('migration snippet', () => {
Expand Down

0 comments on commit fe140c0

Please sign in to comment.