Skip to content

Commit

Permalink
fix SyncTransform, more specs
Browse files Browse the repository at this point in the history
  • Loading branch information
andreypopp committed Apr 2, 2013
1 parent 65fc122 commit f6342a8
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 8 deletions.
23 changes: 20 additions & 3 deletions spec/spec.coffee
Expand Up @@ -51,18 +51,18 @@ describe 'Channel', ->
chan = new TestChannel()

chan.out.write({hello: 'world'})

chan.on 'open', ->
chan.sock.on 'data', (chunk) ->
data = JSON.parse(chunk)
deepEqual(data, {hello: 'world'})
done()

chan.start()

describe 'reconnection logic', ->

it 're-establishes connection on end of a socket stream', (done) ->
it 'maintains in channel connected to current socket', (done) ->

first = true

Expand All @@ -78,3 +78,20 @@ describe 'Channel', ->
first = false
else
chan.sock.write(JSON.stringify({hello: 'world'}))

it 'maintains out channel connected to current socket', (done) ->

first = true

chan = new TestChannel(start: true)

chan.on 'open', ->
if first
chan.sock.end()
first = false
else
chan.sock.on 'data', (data) ->
message = JSON.parse(data)
deepEqual(message, {hello: 'world'})
done()
chan.out.write({hello: 'world'})
29 changes: 28 additions & 1 deletion spec/spec.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions ws-chan.coffee
Expand Up @@ -14,9 +14,10 @@ class SyncTransform extends Transform

_transform: (chunk, encoding, cb) ->
try
cb(null, if this.fn? then this.fn(chunk) else chunk)
this.push(if this.fn? then this.fn(chunk) else chunk)
cb()
catch e
cb(e, null)
cb(e)

class Channel extends EventEmitter

Expand Down
5 changes: 3 additions & 2 deletions ws-chan.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f6342a8

Please sign in to comment.