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

fix: calling avvio with new #230

Merged
merged 1 commit into from
Aug 14, 2023
Merged
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
12 changes: 5 additions & 7 deletions boot.js
Original file line number Diff line number Diff line change
@@ -101,14 +101,12 @@ function Boot (server, opts, done) {

opts = opts || {}

if (!(this instanceof Boot)) {
const instance = new Boot(server, opts, done)

if (server) {
wrap(server, opts, instance)
}
if (!new.target) {
return new Boot(server, opts, done)
}

return instance
if (server) {
wrap(server, opts, this)
}

if (opts.autostart !== false) {
31 changes: 30 additions & 1 deletion test/basic.test.js
Original file line number Diff line number Diff line change
@@ -97,7 +97,7 @@ test('boot a plugin with a custom server', (t) => {
})
})

test('custom instance should inherits avvio methods', (t) => {
test('custom instance should inherits avvio methods /1', (t) => {
t.plan(6)

const server = {}
@@ -126,6 +126,35 @@ test('custom instance should inherits avvio methods', (t) => {
})
})

test('custom instance should inherits avvio methods /2', (t) => {
t.plan(6)

const server = {}
const app = new boot(server, {}) // eslint-disable-line new-cap

server.use(function (s, opts, done) {
t.equal(s, server, 'the first argument is the server')
t.same(opts, {}, 'no options')
done()
}).after(() => {
t.ok('after called')
})

server.onClose(() => {
t.ok('onClose called')
})

server.ready(() => {
t.ok('ready called')
})

app.on('start', () => {
server.close(() => {
t.pass('booted')
})
})
})

test('boot a plugin with options', (t) => {
t.plan(3)