Skip to content

Commit

Permalink
fix error on undefined plugin (#649)
Browse files Browse the repository at this point in the history
* fix error on undefined plugin

* Apply suggestions from code review
  • Loading branch information
dancastillo authored Jul 28, 2023
1 parent 2fd8518 commit 9ad8855
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions test/data/object.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = {}
12 changes: 12 additions & 0 deletions test/start.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1034,3 +1034,15 @@ test('should start fastify with custom plugin options with a CJS plugin with pac
t.pass('server closed')
t.end()
})

test('should throw error for invalid fastify plugin (object)', async t => {
t.plan(1)
try {
const port = getPort()
const argv = ['-p', port, '-T', '100', './test/data/object.js']
await start.start(argv)
t.fail('should not start')
} catch (err) {
t.equal(err.code, 'AVV_ERR_PLUGIN_NOT_VALID')
}
})
2 changes: 1 addition & 1 deletion util.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function requireFastifyForModule (modulePath) {
}

function isInvalidAsyncPlugin (plugin) {
return plugin.length !== 2 && plugin.constructor.name === 'AsyncFunction'
return plugin && plugin.length !== 2 && plugin.constructor.name === 'AsyncFunction'
}

async function getPackageType (cwd) {
Expand Down

0 comments on commit 9ad8855

Please sign in to comment.