Skip to content

Commit

Permalink
fix: do not load the same plugin again
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon Grondin authored and gr2m committed Jan 12, 2019
1 parent c068824 commit b4c38e2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/register-plugin.js
Expand Up @@ -3,5 +3,5 @@ module.exports = registerPlugin
const factory = require('./factory')

function registerPlugin (plugins, pluginFunction) {
return factory(plugins.concat(pluginFunction))
return factory(plugins.includes(pluginFunction) ? plugins : plugins.concat(pluginFunction))
}
14 changes: 13 additions & 1 deletion test/integration/plugins-test.js
Expand Up @@ -11,7 +11,7 @@ describe('plugins', () => {
expect(myClient.foo).to.equal('bar')
})

it('it does not override plugins of original constructor', () => {
it('does not override plugins of original constructor', () => {
const MyOctokit = Octokit.plugin((octokit) => {
octokit.foo = 'bar'
})
Expand All @@ -28,4 +28,16 @@ describe('plugins', () => {
})
MyOctokit({ foo: 'bar' })
})

it('does not load the same plugin more than once', () => {
const myPlugin = (octokit, options) => {
if (octokit.customKey) {
throw new Error('Boom!')
} else {
octokit.customKey = true
}
}
const MyOctokit = Octokit.plugin(myPlugin).plugin(myPlugin)
expect(MyOctokit).to.not.throw()
})
})

0 comments on commit b4c38e2

Please sign in to comment.