<commit_before>noflo = require 'noflo'

unless noflo.isBrowser()
  chai = require 'chai' unless chai
  ComponentLoader = require '../src/ComponentLoader'
  RemoteSubGraph = require '../src/RemoteSubGraph'
else
  ComponentLoader = require 'noflo-runtime/src/ComponentLoader'
  RemoteSubGraph = require 'noflo-runtime/src/RemoteSubGraph'

describe 'ComponentLoader', ->

  it 'should export a function', ->
    chai.expect(ComponentLoader).to.be.a 'function'

  describe 'runtimes specified in project file', ->
    baseDir = if noflo.isBrowser() then '/noflo-runtime/spec/data' else require('path').resolve __dirname, './data/'
    names = null
    loader = new noflo.ComponentLoader baseDir
    compName = 'runtime/2ef763ff-1f28-49b8-b58f-5c6a5c54af2d'
    it 'should be listed', (done) ->
        @timeout 5000
        loader.listComponents () ->
            # initialized
            ComponentLoader loader, (err) ->
                chai.expect(err).to.equal null
                loader.listComponents (err, components) ->
                    chai.expect(err).to.not.exist
                    names = Object.keys(components).filter (c) -> return c.indexOf('runtime/') == 0
                    chai.expect(names).to.have.length 1
                    chai.expect(names[0]).to.equal compName
                    done()
    it 'should be a RemoteSubGraph', ->
        component = loader.load compName, (err, instance) ->
            chai.expect(err).to.equal null
            chai.expect(instance).to.not.equal null
            chai.expect(instance).to.be.instanceOf RemoteSubGraph.RemoteSubGraph<commit_msg>Mocha 3 compat<commit_after>noflo = require 'noflo'

unless noflo.isBrowser()
  chai = require 'chai' unless chai
  ComponentLoader = require '../src/ComponentLoader'
  RemoteSubGraph = require '../src/RemoteSubGraph'
else
  ComponentLoader = require 'noflo-runtime/src/ComponentLoader'
  RemoteSubGraph = require 'noflo-runtime/src/RemoteSubGraph'

describe 'ComponentLoader', ->

  it 'should export a function', ->
    chai.expect(ComponentLoader).to.be.a 'function'

  describe 'runtimes specified in project file', ->
    baseDir = if noflo.isBrowser() then '/noflo-runtime/spec/data' else require('path').resolve __dirname, './data/'
    names = null
    loader = new noflo.ComponentLoader baseDir
    compName = 'runtime/2ef763ff-1f28-49b8-b58f-5c6a5c54af2d'
    it 'should be listed', (done) ->
        @timeout 5000
        loader.listComponents () ->
            # initialized
            ComponentLoader loader, (err) ->
                chai.expect(err).to.equal null
                loader.listComponents (err, components) ->
                    chai.expect(err).to.not.exist
                    names = Object.keys(components).filter (c) -> return c.indexOf('runtime/') == 0
                    chai.expect(names).to.have.length 1
                    chai.expect(names[0]).to.equal compName
                    done()
        return
    it 'should be a RemoteSubGraph', ->
        component = loader.load compName, (err, instance) ->
            chai.expect(err).to.equal null
            chai.expect(instance).to.not.equal null
            chai.expect(instance).to.be.instanceOf RemoteSubGraph.RemoteSubGraph
{'fraction_non_alphanumeric': 0.11895910780669144, 'fraction_numerical': 0.015799256505576207, 'mean_word_length': 2.4424307036247335, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 23, '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': '4010553', 'n_tokens_mistral': 981, 'n_tokens_neox': 926, 'n_words': 202}