Advertisement
Guest User

Untitled

a guest
Mar 30th, 2017
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. function callWithCbOrNextTick (func, cb, context) {
  2. if (this && this._server) {
  3. context = this._server
  4. }
  5.  
  6. if (func.length === 0) {
  7. if (this._error) throw this._error
  8. func()
  9. process.nextTick(cb)
  10. } else if (func.length === 1) {
  11. func(this._error)
  12. process.nextTick(cb)
  13. } else if (func.length === 2) {
  14. func(this._error, cb)
  15. } else {
  16. func(this.rerror, context, cb)
  17. }
  18. // with this the error will appear just in the next after/ready callback
  19. this._error = null
  20. }
  21.  
  22.  
  23. ___________________________
  24.  
  25. const app = boot(server) [19/736]
  26.  
  27. app.use(function (s, opts, done) {
  28. done(new Error('err'))
  29. })
  30.  
  31. app.after(function (err, cb) {
  32. t.ok(err instanceof Error)
  33. t.is(err.message, 'err')
  34. cb()
  35. })
  36.  
  37. app.ready(function (err) {
  38. t.error(err)
  39. })
  40. })
  41.  
  42. test('error should come in the first ready', (t) => {
  43. t.plan(2)
  44.  
  45. const server = { my: 'server' }
  46. const app = boot(server)
  47.  
  48. app.use(function (s, opts, done) {
  49. done(new Error('err'))
  50. })
  51.  
  52. app.ready(function (err) {
  53. t.ok(err instanceof Error)
  54. t.is(err.message, 'err')
  55. })
  56. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement