<commit_before>if typeof process is 'object' and process.title is 'node'
  chai = require 'chai' unless chai
  subgraph = require '../src/components/Graph.coffee'
  graph = require '../src/lib/Graph.coffee'
  socket = require '../src/lib/InternalSocket.coffee'
  path = require 'path'
  root = path.resolve __dirname, '../'
else
  subgraph = require 'noflo/src/components/Graph.js'
  graph = require 'noflo/src/lib/Graph.js'
  socket = require 'noflo/src/lib/InternalSocket.js'
  root = 'noflo'

describe 'Graph component', ->
  c = null
  g = null
  beforeEach ->
    c = subgraph.getComponent()
    g = socket.createSocket()
    c.inPorts.graph.attach g

  describe 'initially', ->
    it 'should be ready', ->
      chai.expect(c.ready).to.be.true
    it 'should not contain a network', ->
      chai.expect(c.network).to.be.null
    it 'should not have a baseDir', ->
      chai.expect(c.baseDir).to.be.null
    it 'should only have the graph inport', ->
      chai.expect(c.inPorts).to.have.keys ['graph']
      chai.expect(c.outPorts).to.be.empty

  describe 'with JSON graph definition', ->
    it 'should emit a ready event after network has been loaded', (done) ->
      c.baseDir = root
      c.once 'ready', ->
        chai.expect(c.network).not.to.be.null
        chai.expect(c.ready).to.be.true
        done()
      g.send
        processes:
          Split:
            component: 'Split'
          Merge:
            component: 'Merge'
      chai.expect(c.ready).to.be.false
    it 'should expose available ports', (done) ->
      c.baseDir = root
      c.once 'ready', ->
        chai.expect(c.inPorts).to.have.keys [
          'graph'
          'merge.in'
        ]
        chai.expect(c.outPorts).to.have.keys [
          'split.out'
        ]
        done()
      g.send
        processes:
          Split:
            component: 'Split'
          Merge:
            component: 'Merge'<commit_msg>Test port aliasing via exports<commit_after>if typeof process is 'object' and process.title is 'node'
  chai = require 'chai' unless chai
  subgraph = require '../src/components/Graph.coffee'
  graph = require '../src/lib/Graph.coffee'
  socket = require '../src/lib/InternalSocket.coffee'
  path = require 'path'
  root = path.resolve __dirname, '../'
else
  subgraph = require 'noflo/src/components/Graph.js'
  graph = require 'noflo/src/lib/Graph.js'
  socket = require 'noflo/src/lib/InternalSocket.js'
  root = 'noflo'

describe 'Graph component', ->
  c = null
  g = null
  beforeEach ->
    c = subgraph.getComponent()
    g = socket.createSocket()
    c.inPorts.graph.attach g

  describe 'initially', ->
    it 'should be ready', ->
      chai.expect(c.ready).to.be.true
    it 'should not contain a network', ->
      chai.expect(c.network).to.be.null
    it 'should not have a baseDir', ->
      chai.expect(c.baseDir).to.be.null
    it 'should only have the graph inport', ->
      chai.expect(c.inPorts).to.have.keys ['graph']
      chai.expect(c.outPorts).to.be.empty

  describe 'with JSON graph definition', ->
    it 'should emit a ready event after network has been loaded', (done) ->
      c.baseDir = root
      c.once 'ready', ->
        chai.expect(c.network).not.to.be.null
        chai.expect(c.ready).to.be.true
        done()
      g.send
        processes:
          Split:
            component: 'Split'
          Merge:
            component: 'Merge'
      chai.expect(c.ready).to.be.false
    it 'should expose available ports', (done) ->
      c.baseDir = root
      c.once 'ready', ->
        chai.expect(c.inPorts).to.have.keys [
          'graph'
          'merge.in'
        ]
        chai.expect(c.outPorts).to.have.keys [
          'split.out'
        ]
        done()
      g.send
        processes:
          Split:
            component: 'Split'
          Merge:
            component: 'Merge'
        connections: [
          src:
            process: 'Merge'
            port: 'out'
          tgt:
            process: 'Split'
            port: 'in'
        ]
    it 'should expose only exported ports when they exist', (done) ->
      c.baseDir = root
      c.once 'ready', ->
        chai.expect(c.inPorts).to.have.keys [
          'graph'
        ]
        chai.expect(c.outPorts).to.have.keys [
          'out'
        ]
        done()
      g.send
        exports: [
          public: 'out'
          private: 'split.out'
        ]
        processes:
          Split:
            component: 'Split'
          Merge:
            component: 'Merge'
{'fraction_non_alphanumeric': 0.13395431359503215, 'fraction_numerical': 0.0, 'mean_word_length': 1.8562381253958202, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3177901', 'n_tokens_mistral': 1469, 'n_tokens_neox': 1450, 'n_words': 332}