Skip to content

Commit

Permalink
Port Kick component to work on browser, refs noflo#63
Browse files Browse the repository at this point in the history
  • Loading branch information
bergie committed Apr 19, 2013
1 parent 42b1d0f commit ea1a4e5
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 1 deletion.
2 changes: 2 additions & 0 deletions component.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,15 @@
"lib/Network.js",
"components/GetElement.js",
"components/Callback.js",
"components/Kick.js",
"components/Split.js",
"components/Merge.js"
],
"noflo": {
"components": {
"GetElement": "components/GetElement.js",
"Callback": "components/Callback.js",
"Kick": "components/Kick.js",
"Split": "components/Split.js",
"Merge": "components/Merge.js"
}
Expand Down
1 change: 1 addition & 0 deletions components.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
};
48 changes: 48 additions & 0 deletions spec/Kick.coffee
Original file line number Diff line number Diff line change
@@ -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()
1 change: 1 addition & 0 deletions spec/runner.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
<script src="./ComponentLoader.js"></script>
<script src="./Network.js"></script>
<script src="./Callback.js"></script>
<script src="./Kick.js"></script>
<script src="./GetElement.js"></script>
<script>
if (window.mochaPhantomJS) {
Expand Down
5 changes: 4 additions & 1 deletion src/components/Kick.coffee
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
noflo = require "../../lib/NoFlo"
if typeof process is 'object' and process.title is 'node'
noflo = require "../../lib/NoFlo"
else
noflo = require '/noflo'

class Kick extends noflo.Component
description: "This component generates a single packet and sends
Expand Down

0 comments on commit ea1a4e5

Please sign in to comment.