Skip to content

Commit

Permalink
Registering plugins inside after should trigger override (#116)
Browse files Browse the repository at this point in the history
  • Loading branch information
mcollina authored Jul 12, 2020
1 parent 7c01ac5 commit 2d307a7
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
2 changes: 2 additions & 0 deletions plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ Plugin.prototype.exec = function (server, cb) {
debug('override errored', name)
return cb(err)
}
} else {
this.server = server
}

this.opts = typeof this.opts === 'function' ? this.opts(this.server) : this.opts
Expand Down
32 changes: 32 additions & 0 deletions test/override.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -340,3 +340,35 @@ test('after trigger override', t => {
t.equals(overrideCalls, 1, 'async after with 2 parameters should not trigger override')
})
})

test('custom inheritance override in after', (t) => {
t.plan(6)

const server = { count: 0 }
const app = boot(server)

app.override = function (s) {
const res = Object.create(s)
res.count = res.count + 1

return res
}

app.use(function first (s1, opts, cb) {
t.notEqual(s1, server)
t.ok(server.isPrototypeOf(s1))
t.equal(s1.count, 1)
s1.after(() => {
s1.use(second)
})

cb()

function second (s2, opts, cb) {
t.notEqual(s2, s1)
t.ok(s1.isPrototypeOf(s2))
t.equal(s2.count, 2)
cb()
}
})
})

0 comments on commit 2d307a7

Please sign in to comment.