diff --git a/plugin.js b/plugin.js index 7496a88..e7ffe7b 100644 --- a/plugin.js +++ b/plugin.js @@ -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 diff --git a/test/override.test.js b/test/override.test.js index 10ef7ec..73a5c2b 100644 --- a/test/override.test.js +++ b/test/override.test.js @@ -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() + } + }) +})