UNPKG

noflo

Version:

Flow-Based Programming environment for JavaScript

96 lines (93 loc) 2.9 kB
var chai, noflo; if (typeof process !== 'undefined' && process.execPath && process.execPath.match(/node|iojs/)) { if (!chai) { chai = require('chai'); } noflo = require('../src/lib/NoFlo.coffee'); } else { noflo = require('noflo'); } describe('MergeObjects component', function() { var c, obj1, obj2, sin1, sin2, sin3, sout1, sout2; c = null; sin1 = null; sin2 = null; sin3 = null; sout1 = null; sout2 = null; obj1 = { name: 'Patrick', age: 21 }; obj2 = { title: 'Attorney', age: 33 }; before(function(done) { var MergeObjects; if (noflo.isBrowser()) { return this.skip(); } MergeObjects = require('./components/MergeObjects.coffee'); c = MergeObjects.getComponent(); sin1 = new noflo.internalSocket.InternalSocket; sin2 = new noflo.internalSocket.InternalSocket; sin3 = new noflo.internalSocket.InternalSocket; sout1 = new noflo.internalSocket.InternalSocket; sout2 = new noflo.internalSocket.InternalSocket; c.inPorts.obj1.attach(sin1); c.inPorts.obj2.attach(sin2); c.inPorts.overwrite.attach(sin3); c.outPorts.result.attach(sout1); c.outPorts.error.attach(sout2); return done(); }); beforeEach(function(done) { sout1.removeAllListeners(); sout2.removeAllListeners(); return done(); }); it('should not trigger if input is not complete', function(done) { sout1.once('ip', function(ip) { return done(new Error("Premature result")); }); sout2.once('ip', function(ip) { return done(new Error("Premature error")); }); sin1.post(new noflo.IP('data', obj1)); sin2.post(new noflo.IP('data', obj2)); return setTimeout(done, 10); }); it('should merge objects when input is complete', function(done) { sout1.once('ip', function(ip) { chai.expect(ip).to.be.an('object'); chai.expect(ip.type).to.equal('data'); chai.expect(ip.data).to.be.an('object'); chai.expect(ip.data.name).to.equal(obj1.name); chai.expect(ip.data.title).to.equal(obj2.title); chai.expect(ip.data.age).to.equal(obj1.age); return done(); }); sout2.once('ip', function(ip) { return done(ip); }); return sin3.post(new noflo.IP('data', false)); }); return it('should obey the overwrite control', function(done) { sout1.once('ip', function(ip) { chai.expect(ip).to.be.an('object'); chai.expect(ip.type).to.equal('data'); chai.expect(ip.data).to.be.an('object'); chai.expect(ip.data.name).to.equal(obj1.name); chai.expect(ip.data.title).to.equal(obj2.title); chai.expect(ip.data.age).to.equal(obj2.age); return done(); }); sout2.once('ip', function(ip) { return done(ip); }); sin3.post(new noflo.IP('data', true)); sin1.post(new noflo.IP('data', obj1)); return sin2.post(new noflo.IP('data', obj2)); }); });