{"name":"tape-cluster","version":"2.0.0","description":"A helper to run tests against a cluster","keywords":[],"author":{"name":"Raynos","email":"raynos2@gmail.com"},"repository":{"type":"git","url":"git://github.com/Raynos/tape-cluster.git"},"main":"index","homepage":"https://github.com/Raynos/tape-cluster","bugs":{"url":"https://github.com/Raynos/tape-cluster/issues","email":"raynos2@gmail.com"},"contributors":[{"name":"Raynos"}],"dependencies":{},"devDependencies":{"coveralls":"^2.10.0","istanbul":"^0.3.5","lint-trap":"^1.0.0","opn":"^1.0.1","request":"2.55.0","tap-spec":"^2.1.1","tape":"^3.4.0"},"licenses":[{"type":"MIT","url":"http://github.com/Raynos/tape-cluster/raw/master/LICENSE"}],"scripts":{"test":"npm run jshint -s && npm run cover -s","unit-test":"node test/index.js | tap-spec","jshint":"lint-trap .","cover":"istanbul cover --report html --print detail -- test/index.js && npm run check-cover -s","check-cover":"istanbul check-coverage --branches=100 --lines=100 --functions=100","view-cover":"opn ./coverage/index.html","travis":"npm run cover -s && istanbul report lcov && ((cat coverage/lcov.info | coveralls) || exit 0)"},"engine":{"node":">= 0.8.x"},"pre-commit":["test"],"pre-commit.silent":true,"ngen-version":"5.1.0","gitHead":"94cb8e03d5bf047de6fec35a09937021588d91de","_id":"tape-cluster@2.0.0","_shasum":"8b98faab8a01292ee00366fa138cd5ffe4e4cd96","_from":".","_npmVersion":"2.8.4","_nodeVersion":"0.10.32","_npmUser":{"name":"raynos","email":"raynos2@gmail.com"},"maintainers":[{"name":"raynos","email":"raynos2@gmail.com"}],"dist":{"shasum":"8b98faab8a01292ee00366fa138cd5ffe4e4cd96","tarball":"http://registry-npm.ywwl.com/tape-cluster/download/tape-cluster-2.0.0.tgz","integrity":"sha512-5NLEDaQ3aeP6hYDSCgoat1S6NAq2nrKOVLqPO85k6ep+uIRGDk88qJr0DBMKLUZ8IM2dQPrXll7dBqXpoQhHrQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCi6DpgzdCHmuiCIbj9DlMisxoKJWP2/eNlePrv85cSMAIgXBEjBddNk8+mzO/i61N2WY52KybEz3DWBVvYSPmZiEo="}],"size":3500,"noattachment":false,"key":"/tape-cluster/-/tape-cluster-2.0.0.tgz"},"directories":{},"readme":"# tape-cluster\n\n<!--\n    [![build status][build-png]][build]\n    [![Coverage Status][cover-png]][cover]\n    [![Davis Dependency status][dep-png]][dep]\n-->\n\n<!-- [![NPM][npm-png]][npm] -->\n\nA helper to run integration tests against an application\n\n## Motivation\n\nWhen writing integration tests against a service you generally\nwant to spawn up an instance of the application or spawn up\na cluster of applications.\n\nWriting tests against such a cluster can be tedious without\na helper to setup your cluster before and after every test.\n\nThe `tape-cluster` package will setup your test harness / runner / application before each test block and spin them down after each test block.\n\nThis functionality is similar to `beforeEach` or `afterEach` that might exist in other testing libraries but is instead implemented as a standalone library that's compatible with vanilla `tape` and `tap`\n\n## Example\n\nYour test file\n\n```js\n// test/what.js\n'use strict';\n\nvar tape = require('tape');\nvar request = require('request');\n\nvar MyTestCluster = require('./lib/test-cluster.js');\n\nMyTestCluster.test('a test', {\n    port: 8000\n}, function t(cluster, assert) {\n    request({\n        url: 'http://localhost:' + cluster.port + '/foo'\n    }, function onResponse(err, resp, body) {\n        assert.ifError(err);\n\n        assert.equal(resp.statusCode, 200);\n        assert.equal(resp.body, '/foo');\n\n        assert.end();\n    });\n});\n\ntape('a test without tape-cluster', function t(assert) {\n    var cluster = new MyTestCluster({\n        port: 8000\n    });\n    cluster.bootstrap(function (err) {\n        assert.ifError(err);\n        request({\n            url: 'http://localhost:' + cluster.port + '/foo'\n        }, function onResponse(err, resp, body) {\n            assert.ifError(err);\n\n            assert.equal(resp.statusCode, 200);\n            assert.equal(resp.body, '/foo');\n\n            cluster.close(function (err) {\n                assert.ifError(err);\n                assert.end();\n            });\n        });\n    });\n});\n```\n\nYour actual `test-cluster.js`\n\n```js\n// test-cluster.js\n'use strict';\n\nvar tape = require('tape');\nvar http = require('http');\nvar tapeCluster = require('tape-cluster');\n\nMyTestCluster.test = tapeCluster(tape, MyTestCluster);\n\nmodule.exports = MyTestCluster;\n\nfunction MyTestCluster(opts) {\n    if (!(this instanceof MyTestCluster)) {\n        return new MyTestCluster(opts);\n    }\n\n    var self = this;\n\n    self.assert = opts.assert;\n    self.port = opts.port;\n    self.server = http.createServer();\n\n    self.server.on('request', onRequest);\n\n    function onRequest(req, res) {\n        res.end(req.url);\n    }\n}\n\nMyTestCluster.prototype.bootstrap = function bootstrap(cb) {\n    var self = this;\n\n    self.server.once('listening', cb);\n    self.server.listen(self.port);\n};\n\nMyTestCluster.prototype.close = function close(cb) {\n    var self = this;\n\n    self.server.close(cb);\n};\n```\n\n## ES6 example\n\n```js\nconst fetch = require('node-fetch')\n\nconst MyTestCluster = require('./lib/test-cluster.js');\n\nMyTestCluster.test('a test', {\n    port: 8000\n}, async function t(cluster, assert) {\n    const res = await fetch(`http://localhost:${cluster.port}/foo`)\n\n    const text = await res.text()\n    assert.equal(res.status, 200)\n    assert.equal(text, '/foo')\n});\n```\n\n```js\nconst tape = require('tape');\nconst http = require('http');\nconst tapeCluster = require('tape-cluster');\n\nclass TestCluster {\n    constructor(opts) {\n        this.port = opts.port\n        this.server = http.createServer()\n\n        this.server.on('request', (req, res) => {\n            res.end(req.url)\n        })\n    }\n\n    async bootstrap() {\n        return new Promise((resolve) => {\n            this.server.once('listening', resolve)\n            this.server.listen(this.port)\n        })\n    }\n\n    async close() {\n        return new Promise((resolve, reject) => {\n            this.server.close((err) => {\n                if (err) return reject(err)\n                resolve()\n            })\n        })\n    }\n}\n\nTestCluster.test = tapeCluster(tape, TestCluster)\n```\n\n## Installation\n\n`npm install tape-cluster`\n\n## Tests\n\n`npm test`\n\n## Contributors\n\n - Raynos\n\n## MIT Licensed\n\n  [build-png]: https://secure.travis-ci.org/Raynos/tape-cluster.png\n  [build]: https://travis-ci.org/Raynos/tape-cluster\n  [cover-png]: https://coveralls.io/repos/Raynos/tape-cluster/badge.png\n  [cover]: https://coveralls.io/r/Raynos/tape-cluster\n  [dep-png]: https://david-dm.org/Raynos/tape-cluster.png\n  [dep]: https://david-dm.org/Raynos/tape-cluster\n  [npm-png]: https://nodei.co/npm/tape-cluster.png?stars&downloads\n  [npm]: https://nodei.co/npm/tape-cluster\n","publish_time":1432431983630,"_cnpm_publish_time":1432431983630,"dist-tags":{"latest":"3.2.1"}}