Skip to content

Commit

Permalink
Removal of check that plugin functions need to have 3 arguments (#201)
Browse files Browse the repository at this point in the history
  • Loading branch information
piranna authored and Eomm committed Aug 28, 2019
1 parent 7fc6f58 commit 64c11be
Show file tree
Hide file tree
Showing 5 changed files with 1 addition and 47 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -59,7 +59,7 @@ module.exports = function (fastify, options, next) {
}
```

If you are using Node 8+, you can use `async` functions too:
If you are using Node 8+, you can use `Promises` or `async` functions too:

```js
// async-await-plugin.js
Expand Down
12 changes: 0 additions & 12 deletions test/data/incorrect-plugin.js

This file was deleted.

12 changes: 0 additions & 12 deletions test/print-routes.test.js
Expand Up @@ -39,18 +39,6 @@ test('should warn on file not found', t => {
printRoutes.printRoutes(argv)
})

test('should only accept plugin functions with 3 arguments', t => {
t.plan(1)

const oldStop = printRoutes.stop
t.tearDown(() => { printRoutes.stop = oldStop })
printRoutes.stop = function (err) {
t.equal(err.message, 'Plugin function should contain 3 arguments. Refer to documentation for more information.')
}

printRoutes.printRoutes(['./test/data/incorrect-plugin.js'])
})

test('should throw on package not found', t => {
t.plan(1)

Expand Down
13 changes: 0 additions & 13 deletions test/start.test.js
Expand Up @@ -114,19 +114,6 @@ test('should start fastify at given socket path', { skip: process.platform === '
})
})

test('should only accept plugin functions with 3 arguments', t => {
t.plan(1)

const oldStop = start.stop
t.tearDown(() => { start.stop = oldStop })
start.stop = function (err) {
t.equal(err.message, 'Plugin function should contain 3 arguments. Refer to documentation for more information.')
}

const argv = ['-p', getPort(), './test/data/incorrect-plugin.js']
start.start(argv)
})

test('should error with a good timeout value', t => {
t.plan(1)

Expand Down
9 changes: 0 additions & 9 deletions util.js
Expand Up @@ -27,10 +27,6 @@ function requireFastifyForModule (modulePath) {
}
}

function isInvalidCallbackPlugin (plugin) {
return plugin.length !== 3 && plugin.constructor.name === 'Function'
}

function isInvalidAsyncPlugin (plugin) {
return plugin.length !== 2 && plugin.constructor.name === 'AsyncFunction'
}
Expand All @@ -44,11 +40,6 @@ function requireServerPluginFromPath (modulePath) {

const serverPlugin = require(resolvedModulePath)

if (isInvalidCallbackPlugin(serverPlugin)) {
throw new Error('Plugin function should contain 3 arguments. Refer to ' +
'documentation for more information.')
}

if (isInvalidAsyncPlugin(serverPlugin)) {
return new Error('Async/Await plugin function should contain 2 arguments.' +
'Refer to documentation for more information.')
Expand Down

0 comments on commit 64c11be

Please sign in to comment.