Skip to content

Commit

Permalink
Port Objectify tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bergie committed May 25, 2016
1 parent d536195 commit a07bee0
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 27 deletions.
69 changes: 69 additions & 0 deletions spec/Objectify.coffee
@@ -0,0 +1,69 @@
noflo = require 'noflo'

unless noflo.isBrowser()
chai = require 'chai'
path = require 'path'
baseDir = path.resolve __dirname, '../'
else
baseDir = 'noflo-groups'

describe 'Objectify component', ->
c = null
regexp = null
ins = null
out = null
before (done) ->
@timeout 4000
loader = new noflo.ComponentLoader baseDir
loader.load 'groups/Objectify', (err, instance) ->
return done err if err
c = instance
regexp = noflo.internalSocket.createSocket()
ins = noflo.internalSocket.createSocket()
c.inPorts.regexp.attach regexp
c.inPorts.in.attach ins
done()
beforeEach ->
out = noflo.internalSocket.createSocket()
c.outPorts.out.attach out
afterEach ->
c.outPorts.out.detach out

describe 'with groups matching regexp', ->
it 'should make an object and retain groups', (done) ->
groups = []
out.on 'begingroup', (grp) ->
groups.push grp
out.on 'data', (data) ->
chai.expect(data).to.eql
a: 'whatever'
chai.expect(groups).to.eql [
'abc'
]
out.on 'endgroup', ->
groups.pop()
done() unless groups.length

regexp.send '^(a)'
ins.beginGroup 'abc'
ins.data 'whatever'
ins.endGroup()

describe 'with groups not matching regexp', ->
it 'should send packet as-is and retain groups', (done) ->
groups = []
out.on 'begingroup', (grp) ->
groups.push grp
out.on 'data', (data) ->
chai.expect(data).to.equal 'whatever'
chai.expect(groups).to.eql [
'xyz'
]
out.on 'endgroup', ->
groups.pop()
done() unless groups.length

regexp.send '^(a)'
ins.beginGroup 'xyz'
ins.data 'whatever'
ins.endGroup()
1 change: 1 addition & 0 deletions spec/runner.html
Expand Up @@ -28,6 +28,7 @@
<script src="./GenerateGroup.js"></script>
<script src="./GroupZip.js"></script>
<script src="./LastGroup.js"></script>
<script src="./Objectify.js"></script>
<script src="./ReadGroup.js"></script>
<script>
mocha.run();
Expand Down
27 changes: 0 additions & 27 deletions test/Objectify.coffee

This file was deleted.

0 comments on commit a07bee0

Please sign in to comment.