diff --git a/lib/fittingTypes/user.js b/lib/fittingTypes/user.js index 3b68179..dfff512 100644 --- a/lib/fittingTypes/user.js +++ b/lib/fittingTypes/user.js @@ -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++) { diff --git a/test/bagpipes.js b/test/bagpipes.js index 4b627fc..8d1dd7b 100644 --- a/test/bagpipes.js +++ b/test/bagpipes.js @@ -45,6 +45,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' ];