diff --git a/test/data/object.js b/test/data/object.js new file mode 100644 index 00000000..4ba52ba2 --- /dev/null +++ b/test/data/object.js @@ -0,0 +1 @@ +module.exports = {} diff --git a/test/start.test.js b/test/start.test.js index b37ef5f1..454e6732 100644 --- a/test/start.test.js +++ b/test/start.test.js @@ -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') + } +}) diff --git a/util.js b/util.js index fcf06de5..c86ebe36 100644 --- a/util.js +++ b/util.js @@ -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) {