-
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.
- Loading branch information
Showing
2 changed files
with
105 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
'use strict'; | ||
|
||
const proxyquire = require('proxyquire'); | ||
|
||
describe('PluginDecoratePipes', () => { | ||
let PluginDecoratePipes = null; | ||
let noopPipe = null; | ||
|
||
function getHelper(pipes, plugins) { | ||
const pluginDecoratePipes = new PluginDecoratePipes(pipes, plugins); | ||
|
||
return pluginDecoratePipes.decorateHelper({ helper: {} }).helper; | ||
} | ||
|
||
function errorMatching(str) { | ||
return { | ||
asymmetricMatch(actual) { | ||
expect(actual).toEqual(jasmine.any(Error)); | ||
expect(actual.message).toEqual(jasmine.stringMatching(str)); | ||
return true; | ||
}, | ||
}; | ||
} | ||
|
||
beforeEach(() => { | ||
noopPipe = { id: Symbol('someId') }; | ||
PluginDecoratePipes = proxyquire( | ||
'../../../lib/plugins/decoratePipes/PluginDecoratePipes', | ||
{ | ||
'./noopPipe': noopPipe, | ||
} | ||
); | ||
}); | ||
|
||
it('decorates a getPipe method to helper', () => { | ||
const helper = getHelper([], []); | ||
|
||
expect(helper.getPipe).toEqual(jasmine.any(Function)); | ||
}); | ||
|
||
describe('getPipe', () => { | ||
it('provides pipes passed to constructor', () => { | ||
const name = 'foo'; | ||
const fakePipe = Symbol('fakePipe'); | ||
const fakePipeProvider = { | ||
meta: { | ||
name: `gulp-toolbox-pipe-${name}`, | ||
}, | ||
get() { | ||
return fakePipe; | ||
}, | ||
}; | ||
const helper = getHelper([fakePipeProvider], []); | ||
|
||
expect(helper.getPipe(name)).toBe(fakePipe); | ||
}); | ||
|
||
it('throws if pipe is not registered', () => { | ||
const helper = getHelper([], []); | ||
const name = 'bar'; | ||
|
||
expect(() => { | ||
helper.getPipe(name); | ||
}).toThrow(errorMatching(`Pipe '${name}' not defined`)); | ||
}); | ||
|
||
it('provides a noop-pipe if called with optional param', () => { | ||
expect(getHelper([], []).getPipe('bar', { optional: true })) | ||
.toBe(noopPipe); | ||
}); | ||
}); | ||
}); |
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,33 @@ | ||
'use strict'; | ||
|
||
const proxyquire = require('proxyquire'); | ||
|
||
describe('noopPipe', () => { | ||
it('passes noop callbacks to through2', () => { | ||
const throughWrappedThing = Symbol('throughWrappedThing'); | ||
const obj = jasmine.createSpy('through2.obj') | ||
.and.returnValue(throughWrappedThing); | ||
const noopPipe = proxyquire( | ||
'../../../lib/plugins/decoratePipes/noopPipe', | ||
{ | ||
through2: { obj }, | ||
} | ||
); | ||
|
||
expect(noopPipe).toBe(throughWrappedThing); | ||
expect(obj).toHaveBeenCalledWith( | ||
jasmine.any(Function), | ||
jasmine.any(Function) | ||
); | ||
|
||
const cb1 = jasmine.createSpy('cb1'); | ||
const someChunk = Symbol('someChunk'); | ||
|
||
obj.calls.argsFor(0)[0](someChunk, undefined, cb1); | ||
expect(cb1).toHaveBeenCalledWith(null, someChunk); | ||
|
||
const cb2 = jasmine.createSpy('cb2'); | ||
obj.calls.argsFor(0)[1](cb2); | ||
expect(cb2).toHaveBeenCalled(); | ||
}); | ||
}); |