{"name":"tape-cluster","version":"3.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","opn":"^1.0.1","request":"2.55.0","standardx":"^3.0.1","tap":"^12.6.0","tap-spec":"^2.1.1","tape":"^3.4.0"},"eslintConfig":{"rules":{"indent":["error",4]}},"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":"standardx","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":"445061f4d26cf37b9f1efe3604dd2712334cb95d","_id":"tape-cluster@3.0.0","_npmVersion":"6.4.1","_nodeVersion":"10.15.3","_npmUser":{"name":"raynos","email":"raynos2@gmail.com"},"dist":{"integrity":"sha512-Uz0G92KFA2F16+tpjMKJ4JZ5FBsSwOPcH5A5BHro2vkVqjKNLOuiYtbBw8fjlDBlWZImu8Nv6J9O5fidYj5flg==","shasum":"d50aeba40f2fabf8fcdfa1340ef42da28b1286db","tarball":"http://registry-npm.ywwl.com/tape-cluster/download/tape-cluster-3.0.0.tgz","fileCount":7,"unpackedSize":16394,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJchoTgCRA9TVsSAnZWagAA734P/29Gn2bNz/oTaBLYDXlP\n7VcUOvTINu0chHVzeOkh1iKH/EwjOpMSvUitBxQy7G4x2ws/AdLKLbVVkeJA\nv55/FNb+a0QtNwq/LY8LUxeKBCYBiFs/T6kHrieN24Va5TmH5VbYRckEnXzi\n6E1zWzxajzHeLGTb5Si99r6jlC0kBvRYzBXh0mWJ6CjDWyWFz+b1tFQxfi7z\nR1ABRooGl20yP5BBtsoCx2q0cNMXyJJtmHqbjQ+g7MhDgZgSZEPh9zSPSPAA\nOhtzI5AiyjIM1T1avq/9xlYglZ/U7BM0uXN6fX7OYDQfp8AG8FcWuptjg8J+\n9XRWbs1bHeZNlhgacH0EfT3keTIOFU660mdjg5l2LK+3kcRSwzr0lmXCwRaw\nnmPR3rYEJk1UtqIcljb/s+3nWdgiExEPaSE8Dk2z3IJQ6dJITsaBI2nKss11\nipMuLryTZoAppOollI72yBN6Bhqj0vw/sBxz1PKqddH7BO7dH6+ooK0MkbfG\nB4xm4QouEi1vWo2kyE4vvcbOPD5aN9dGnn122eT0WUaVnoB93AhvcaXOhqig\nLCGTOoTznlMG/cWGeNmi4vcBKf7nc9qOoD9EJN/LXGMAI1kCfbNetKlZYBaf\neOjSO7G2rBI19RuI0Ul7R/WCTTeg08JF0qiIuIhCOSrAuN1uRKC2gmkm1PAg\nXBUx\r\n=iP4B\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQC9xlRoNTM/xQnj7gYGjvGEeo1N501s+xYnJFhtJCyCmQIgJ2pCmF+aA+8zkPfB3OtYVsvgy9iY80ardEt1i35K5ps="}],"size":4244,"noattachment":false,"key":"/tape-cluster/-/tape-cluster-3.0.0.tgz"},"maintainers":[{"name":"raynos","email":"raynos2@gmail.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/tape-cluster_3.0.0_1552319712069_0.8156514969066133"},"_hasShrinkwrap":false,"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":1552319712219,"_cnpm_publish_time":1552319712219,"dist-tags":{"latest":"3.2.1"}}