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

Added app.override() to create plugin inheritance chain #9

Merged
merged 1 commit into from
Mar 18, 2017

Conversation

mcollina
Copy link
Member

@delvedor delvedor mentioned this pull request Mar 18, 2017
@delvedor
Copy link
Member

LGTM, if you want you can add the following test case for override, which is specific for the fastify use case.

test('fastify test case', (t) => {
  t.plan(7)

  const noop = () => {}

  function build () {
    const app = boot(server, {})
    app.override = function (s) {
      return Object.create(s)
    }

    server.add = function (name, fn, cb) {
      if (this[name]) return cb(new Error('already existent'))
      this[name] = fn
      cb()
    }

    return server

    function server (req, res) {}
  }

  const instance = build()
  t.ok(instance.add)
  t.ok(instance.use)

  instance.use((i, opts, cb) => {
    t.notEqual(i, instance)
    t.ok(instance.isPrototypeOf(i))

    i.add('test', noop, (err) => {
      t.error(err)
      t.ok(i.test)
      cb()
    })
  })

  instance.ready(() => {
    t.notOk(instance.test)
  })
})

@mcollina mcollina merged commit 8365d6a into master Mar 18, 2017
@delvedor delvedor mentioned this pull request Mar 18, 2017
@delvedor delvedor deleted the override branch March 18, 2017 17:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants