{"id":17148785,"url":"https://github.com/trustmaster/noflo-tester","last_synced_at":"2025-04-13T11:42:21.850Z","repository":{"id":23808621,"uuid":"27184898","full_name":"trustmaster/noflo-tester","owner":"trustmaster","description":"Tester wraps a NoFlo component/graph and provides a testing interface","archived":false,"fork":false,"pushed_at":"2020-09-14T10:19:07.000Z","size":18,"stargazers_count":4,"open_issues_count":1,"forks_count":3,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-27T02:51:15.321Z","etag":null,"topics":["noflo","testing"],"latest_commit_sha":null,"homepage":null,"language":"CoffeeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/trustmaster.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-11-26T16:11:52.000Z","updated_at":"2020-11-09T06:52:05.000Z","dependencies_parsed_at":"2022-08-22T05:30:50.728Z","dependency_job_id":null,"html_url":"https://github.com/trustmaster/noflo-tester","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trustmaster%2Fnoflo-tester","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trustmaster%2Fnoflo-tester/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trustmaster%2Fnoflo-tester/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trustmaster%2Fnoflo-tester/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/trustmaster","download_url":"https://codeload.github.com/trustmaster/noflo-tester/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248709615,"owners_count":21149179,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["noflo","testing"],"created_at":"2024-10-14T21:29:50.938Z","updated_at":"2025-04-13T11:42:21.825Z","avatar_url":"https://github.com/trustmaster.png","language":"CoffeeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"NoFlo component/graph testing wrapper\n============\n\n[![Build Status](https://travis-ci.org/trustmaster/noflo-tester.svg?branch=master)](https://travis-ci.org/trustmaster/noflo-tester)\n\nTester wraps a component to provide a convenient interface compatible with any testing paradigm: TDD/BDD/whatever.\n\n# Deprecation warning\n\n**This project has been moved to [noflo-wrapper](https://github.com/noflo/noflo-wrapper) package under [NoFlo](https://github.com/noflo) organization.**\n\nPlease consider updating your dependencies to use `noflo-wrapper` instead of `noflo-tester`.\n\n## Benefits\n\n* Reduces boilerplate to set up a component testbed.\n* Provides common high-level methods.\n* Provides low-level access to the component, ports and events.\n* Compatible with different testing frameworks and complex test cases.\n\n## Getting started\n\nInstall `noflo-tester` and add it to your project's dev dependecies:\n\n```\nnpm install --save-dev noflo-tester\n```\n\nRequire it in your specs/tests:\n\n```coffeescript\nTester = require 'noflo-tester'\n```\n\nUse methods described below and run the tests just as you do it normally with your favorite testing framework.\n\n## API\n\nExplanations below contain examples in CoffeeScript using Mocha and Chai in BDD style. You can also write your tests in JavaScript, using any other framework or style.\n\n### Loading a component\n\nFirst you need to create a new Tester object to wrap your component or graph:\n\n```coffeescript\nt = new Tester 'my-noflo-app/Multiplier'\n```\n\nThe constructor accepts either a full component name (including namespace prefix), or an already instantiated component object, or a function returning such an object.\n\nIn general, components are loaded and wired up asynchronously, so you need to start the tester like this before running any tests:\n\n```coffeescript\nbefore (done) -\u003e\n  t.start (err, instance) -\u003e\n    return done err if err # Error handling, optional\n    # instance contains a ready to use component\n    done()\n```\n\n**Advanced options**\n\nIf the component to be tested is a NoFlo graph, you can pass custom event handlers to the Tester constructor:\n\n```coffeescript\nt = new Tester 'my-noflo-app/Multiplier',\n  load: (err, instance) -\u003e\n    # This is call after loading the graph\n  ready: (err, instance) -\u003e\n    # This is called when the network is ready to be attached\n```\n\n### Sending inputs and expecting output\n\nA high-level `receive` method listens on output ports for data and groups until a `disconnect` event.\n\nA high-level `send` methods sends data followed by a disconnect to one or more input ports.\n\nHere is an example that tests a simple multiplier component:\n\n```coffeescript\nt.receive 'xy', (data) -\u003e\n  chai.expect(data).to.equal 30\n  done()\n\nt.send\n  x: 5\n  y: 6\n```\n\nNote that `receive` is called before `send`, because it binds event handlers asynchronously, while `send` is almost an instant operation.\n\nShort syntax for `send` method to send data and disconnect to just one inport looks like this:\n\n```coffeescript\nt.send 'x', 123\n```\n\n### Direct access to component, ports and events\n\nIn more complex test cases you might want to send IPs and handle particular events manually:\n\n```coffeescript\nt.outs.xy.on 'data', (data) -\u003e\n  chai.expect(data).to.equal 24\n  done()\n\nt.ins.x.send 8\nt.ins.x.disconnect()\nt.ins.y.send 3\nt.ins.y.disconnect()\n```\n\nTester object provides `ins` and `outs` hashmaps of sockets attached to the component.\n\nYou can also access the component directly via `c` property:\n\n```coffeescript\nif t.c.outPorts.error.isAttached()\n  # Do something\n```\n\n### Receiving multiple data chunks and groups\n\nAs `receive` is triggered by a `disconnect` event, there might be multiple `data` packets in the transmission and also some `group` bracket IPs. In such case they are available as arrays and counts in the callback arguments:\n\n```coffeescript\nt.receive 'xy', (data, groups, dataCount, groupCount) -\u003e\n  chai.expect(data).to.eql [4, 10, 18]\n  chai.expect(dataCount).to.equal 3\n  chai.expect(groups).to.eql ['foo', 'bar']\n  chai.expect(groupCount).to.equal 2\n  done()\n```\n\nNote that `groupCount` counts only closed groups via `endGroup` events, while `groups` contains unique groups sent to the output.\n\n### Receiving from multiple output ports\n\nIf a component sends output to multiple ports at the same time and you need to test results from all of them at once, that may require some syncrhonization spaghetti in your specs. But `receive` simplifies it by accepting a hashmap and returning a Promise that is resolved when results from all outputs in the map have been received:\n\n```coffeescript\ndiv = null\nmod = null\n\nt.receive\n  quotient: (data) -\u003e\n    div = data\n  remainder: (data) -\u003e\n    mod = data\n.then -\u003e\n  chai.expect(div).to.equal 3\n  chai.expect(mod).to.equal 2\n  done()\n\nt.send\n  dividend: 11\n  divisor: 3\n```\n\n### Using promises to chain subsequent receives\n\nThe `receive` method returns a Promise resolved when a transmission is received, so you can chain subsequent transmissions in a thenable way, e.g.:\n\n```coffeescript\nt.receive 'quotient', (data) -\u003e\n  chai.expect(data).to.equal 5\n.then -\u003e\n  t.receive 'quotient', (data) -\u003e\n    chai.expect(data).to.equal 8\n    done()\n  t.send\n    dividend: 56\n    divisor: 7\nt.send\n  dividend: 30\n  divisor: 6\n```\n\n### Examples\n\nSee complete BDD-style examples in `spec` folder.\n\n## Development\n\nThe first thing to start developing this package is:\n\n```\nnpm install\n```\n\nThen run bundled Mocha specs:\n\n```\nnpm test\n```\n\nThen feel free to hack on the `lib` and `specs`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftrustmaster%2Fnoflo-tester","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftrustmaster%2Fnoflo-tester","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftrustmaster%2Fnoflo-tester/lists"}