Skip to content

Commit

Permalink
Merge branch 'master' into next
Browse files Browse the repository at this point in the history
  • Loading branch information
Uzlopak committed Aug 14, 2023
2 parents 01ad896 + ed940d7 commit 9f7e970
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 9 deletions.
12 changes: 5 additions & 7 deletions boot.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
14 changes: 13 additions & 1 deletion lib/debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@

const { debuglog } = require('util')

/**
* @callback DebugLogger
* @param {string} msg
* @param {...unknown} param
* @returns {void}
*/

/**
* @type {DebugLogger}
*/
const debug = debuglog('avvio')

module.exports = {
debug: debuglog('avvio')
debug
}
31 changes: 30 additions & 1 deletion test/basic.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit 9f7e970

Please sign in to comment.