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

Registering plugins inside after should trigger override #116

Merged
merged 1 commit into from
Jul 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
}
})
})