diff --git a/component.json b/component.json index 502efca3c..e62e47e6d 100644 --- a/component.json +++ b/component.json @@ -28,6 +28,7 @@ "lib/Network.js", "components/GetElement.js", "components/Callback.js", + "components/Kick.js", "components/Split.js", "components/Merge.js" ], @@ -35,6 +36,7 @@ "components": { "GetElement": "components/GetElement.js", "Callback": "components/Callback.js", + "Kick": "components/Kick.js", "Split": "components/Split.js", "Merge": "components/Merge.js" } diff --git a/components.js b/components.js index 1a6867841..c0bc449d6 100644 --- a/components.js +++ b/components.js @@ -6,4 +6,5 @@ exports.register = function (loader) { loader.registerComponent('', 'Merge', '/noflo/components/Merge.js'); loader.registerComponent('', 'Callback', '/noflo/components/Callback.js'); loader.registerComponent('', 'GetElement', '/noflo/components/GetElement.js'); + loader.registerComponent('', 'Kick', '/noflo/components/Kick.js'); }; diff --git a/spec/Kick.coffee b/spec/Kick.coffee new file mode 100644 index 000000000..585062558 --- /dev/null +++ b/spec/Kick.coffee @@ -0,0 +1,48 @@ +if typeof process is 'object' and process.title is 'node' + chai = require 'chai' unless chai + kick = require '../src/components/Kick.coffee' + socket = require '../src/lib/InternalSocket.coffee' +else + kick = require 'noflo/components/Kick.js' + socket = require 'noflo/lib/InternalSocket.js' + +describe 'Kick component', -> + c = null + ins = null + data = null + out = null + beforeEach -> + c = kick.getComponent() + ins = socket.createSocket() + data = socket.createSocket() + out = socket.createSocket() + c.inPorts.in.attach ins + c.inPorts.data.attach data + c.outPorts.out.attach out + + it 'should not send packets before disconnect', (done) -> + sent = false + out.once 'data', (d) -> + sent = true + setTimeout -> + chai.expect(sent).to.be.false + done() + , 5 + data.send 'Bar' + ins.send 'Foo' + + it 'should send a null on disconnect when no data has been specified', (done) -> + out.once 'data', (d) -> + chai.expect(d).to.be.null + done() + ins.send 'Foo' + ins.disconnect() + + it 'should send correct data on disconnect', (done) -> + out.once 'data', (d) -> + chai.expect(d).to.equal 'Baz' + done() + data.send 'Bar' + data.send 'Baz' + ins.send 'Foo' + ins.disconnect() diff --git a/spec/runner.html b/spec/runner.html index 1c9491006..7fcb075ab 100644 --- a/spec/runner.html +++ b/spec/runner.html @@ -26,6 +26,7 @@ +