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

Skip override #11

Merged
merged 4 commits into from
Mar 19, 2017
Merged
Show file tree
Hide file tree
Changes from 3 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
3 changes: 2 additions & 1 deletion boot.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ function Plugin (parent, func, opts, callback) {
this.deferred = false
this.onFinish = null
this.parent = parent
this.skipOverride = !!func[Symbol.for('skip-override')]

this.q = fastq(parent, loadPlugin, 1)
this.q.pause()
Expand All @@ -186,7 +187,7 @@ function Plugin (parent, func, opts, callback) {

Plugin.prototype.exec = function (server, cb) {
const func = this.func
this.server = this.parent.override(server)
this.server = this.skipOverride ? server : this.parent.override(server)
func(this.server, this.opts, cb)
}

Expand Down
20 changes: 20 additions & 0 deletions test/override.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,23 @@ test('fastify test case', (t) => {
t.notOk(instance.test)
})
})

test('skip override', (t) => {
t.plan(2)

const server = { my: 'server' }
const app = boot(server)

app.override = function (s) {
return Object.create(s)
}

first[Symbol.for('skip-override')] = true
app.use(first)

function first (s, opts, cb) {
t.equal(s, server)
t.notOk(server.isPrototypeOf(s))
cb()
}
})