Skip to content

Commit

Permalink
Merge a41de91 into 426034a
Browse files Browse the repository at this point in the history
  • Loading branch information
nazarhussain committed Jun 29, 2018
2 parents 426034a + a41de91 commit 2cc1d19
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/fittingTypes/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ var assert = require('assert');
module.exports = function createFitting(pipes, fittingDef) {

assert(fittingDef.name, util.format('name is required on fitting: %j', fittingDef));

// If there is pre-initialized fittings modules available, return these
if (pipes.config.fittings && pipes.config.fittings[fittingDef.name]) {
debug('loaded user fitting %s from pre-initialized modules', fittingDef.name);
return pipes.config.fittings[fittingDef.name](fittingDef, pipes);
}

if (!pipes.config.userFittingsDirs) { return null; }

for (var i = 0; i < pipes.config.userFittingsDirs.length; i++) {
Expand Down
13 changes: 13 additions & 0 deletions test/bagpipes.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,19 @@ describe('bagpipes', function() {
done();
});

it('should load pre-initialized fittings', function(done) {
var emitFitting = function create() {
return function (context, cb) {
cb(null, 'pre-initialized');
}};
var pipe = [ 'emit' ];
var bagpipes = Bagpipes.create({ pipe: pipe }, {fittings: { emit: emitFitting}});
var context = {};
bagpipes.play(bagpipes.getPipe('pipe'), context);
context.output.should.eql('pre-initialized');
done();
});

it('should allow user fittings to override system fittings', function(done) {
var userFittingsDirs = [ path.resolve(__dirname, './fixtures/fittings') ];
var pipe = [ 'test' ];
Expand Down

0 comments on commit 2cc1d19

Please sign in to comment.