forked from karma-runner/karma
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(plugins): refactor instantiatePlugin from preproprocessor (karma-…
…runner#3628) add unit test for plugin.js add comments on role of function and cache
- Loading branch information
1 parent
8d589ed
commit e02858a
Showing
5 changed files
with
219 additions
and
208 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
'use strict' | ||
|
||
const createInstantiatePlugin = require('../../lib/plugin').createInstantiatePlugin | ||
|
||
describe('plugin', () => { | ||
describe('createInstantiatePlugin', () => { | ||
it('creates the instantiatePlugin function', () => { | ||
const fakeGet = sinon.stub() | ||
const fakeInjector = { get: fakeGet } | ||
|
||
expect(typeof createInstantiatePlugin(fakeInjector)).to.be.equal('function') | ||
expect(fakeGet).to.have.been.calledWith('emitter') | ||
}) | ||
|
||
it('creates the instantiatePlugin function', () => { | ||
const fakes = { | ||
emitter: { emit: sinon.stub() } | ||
} | ||
const fakeInjector = { get: (id) => fakes[id] } | ||
|
||
const instantiatePlugin = createInstantiatePlugin(fakeInjector) | ||
expect(typeof instantiatePlugin('kind', 'name')).to.be.equal('undefined') | ||
expect(fakes.emitter.emit).to.have.been.calledWith('load_error', 'kind', 'name') | ||
}) | ||
|
||
it('caches plugins', () => { | ||
const fakes = { | ||
emitter: { emit: sinon.stub() }, | ||
'kind:name': { my: 'plugin' } | ||
} | ||
const fakeInjector = { | ||
get: (id) => { | ||
return fakes[id] | ||
} | ||
} | ||
|
||
const instantiatePlugin = createInstantiatePlugin(fakeInjector) | ||
expect(instantiatePlugin('kind', 'name')).to.be.equal(fakes['kind:name']) | ||
fakeInjector.get = (id) => { throw new Error('failed to cache') } | ||
expect(instantiatePlugin('kind', 'name')).to.be.equal(fakes['kind:name']) | ||
}) | ||
|
||
it('errors if the injector errors', () => { | ||
const fakes = { | ||
emitter: { emit: sinon.stub() } | ||
} | ||
const fakeInjector = { | ||
get: (id) => { | ||
if (id in fakes) { | ||
return fakes[id] | ||
} | ||
throw new Error('fail') | ||
} | ||
} | ||
|
||
const instantiatePlugin = createInstantiatePlugin(fakeInjector) | ||
expect(typeof instantiatePlugin('unknown', 'name')).to.be.equal('undefined') | ||
expect(fakes.emitter.emit).to.have.been.calledWith('load_error', 'unknown', 'name') | ||
}) | ||
}) | ||
}) |
Oops, something went wrong.