{"_id":"mock-spawn","_rev":"15-75df39d6a328cd9626dbc9e2fec37981","name":"mock-spawn","description":"A mock for child_process.spawn","dist-tags":{"latest":"0.2.6"},"versions":{"0.2.1":{"name":"mock-spawn","description":"A mock for child_process.spawn","version":"0.2.1","keywords":["child_process","child process","spawn","mock"],"author":{"name":"Krishnan Anantheswaran","email":"kananthmail-github@yahoo.com"},"contributors":[],"repository":{"type":"git","url":"git://github.com/gotwarlost/mock-spawn.git"},"scripts":{"pretest":"jshint --config ./jshint.json index.js examples/simple/*js examples/complete/*js","test":"./run-tests.sh"},"dependencies":{"through":"2.3.x"},"devDependencies":{"async":"0.2.x","mockery":"1.4.x","mocha":"1.x","istanbul":"0.x","jshint":"2.4.x"},"license":"BSD","bugs":{"url":"https://github.com/gotwarlost/mock-spawn/issues"},"homepage":"https://github.com/gotwarlost/mock-spawn","_id":"mock-spawn@0.2.1","dist":{"shasum":"eb6f4a91e963ba4bf1bea4745fa7a346dab4dd11","tarball":"https://registry.npmjs.org/mock-spawn/-/mock-spawn-0.2.1.tgz","integrity":"sha512-ev8B4JRD5ab+jjBKHC/gHOvBS0MS2fc83YaS85oRHabdgChIGsIx2604KH5LVFtxDBDJ9/K4WkWCrYm2vhRrzA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIHvuaDuxjMsMsqdmSMLxTxI81629fbbcWQ5je4+s2yd6AiBUalXAaM+uCoUsMh+NeG7i2vEb3IKfRKActIalGmWyvg=="}]},"_from":".","_npmVersion":"1.4.3","_npmUser":{"name":"gotwarlost","email":"kananthmail-github@yahoo.com"},"maintainers":[{"name":"gotwarlost","email":"kananthmail-github@yahoo.com"}]},"0.2.2":{"name":"mock-spawn","description":"A mock for child_process.spawn","version":"0.2.2","keywords":["child_process","child process","spawn","mock"],"author":{"name":"Krishnan Anantheswaran","email":"kananthmail-github@yahoo.com"},"contributors":[{"name":"Greg Cochard","email":"greg.cochard@gmail.com"}],"repository":{"type":"git","url":"git://github.com/gotwarlost/mock-spawn.git"},"scripts":{"pretest":"jshint --config ./jshint.json index.js examples/simple/*js examples/complete/*js","test":"./run-tests.sh"},"dependencies":{"through":"2.3.x"},"devDependencies":{"async":"0.2.x","mockery":"1.4.x","mocha":"1.x","istanbul":"0.x","jshint":"2.4.x"},"license":"BSD","gitHead":"8ec5c0820b1a92e6a47305915fe640e5cdcffe91","bugs":{"url":"https://github.com/gotwarlost/mock-spawn/issues"},"homepage":"https://github.com/gotwarlost/mock-spawn","_id":"mock-spawn@0.2.2","_shasum":"314e393e73989a76e265d258f4c84b6fb9f0990e","_from":".","_npmVersion":"1.4.25","_npmUser":{"name":"gotwarlost","email":"kananthmail-github@yahoo.com"},"maintainers":[{"name":"gotwarlost","email":"kananthmail-github@yahoo.com"}],"dist":{"shasum":"314e393e73989a76e265d258f4c84b6fb9f0990e","tarball":"https://registry.npmjs.org/mock-spawn/-/mock-spawn-0.2.2.tgz","integrity":"sha512-B0l26OLq3SjnZzlIODgW9VyvArlUU0iXl9lxkY5KsZpnxsRHs1UqrBVgmGx8LdgwAgbDF7+euBQ/sDFWomqOaQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCICOlNA83PUejPuW06o4ZzDaD7Omdz2k47O1Cm601AkdgAiAZl2YhgUDICbbcQ8ZPO1aU3MeszrmbdxcbeG8oNAcvUQ=="}]}},"0.2.3":{"name":"mock-spawn","description":"A mock for child_process.spawn","version":"0.2.3","keywords":["child_process","child process","spawn","mock"],"author":{"name":"Krishnan Anantheswaran","email":"kananthmail-github@yahoo.com"},"contributors":[{"name":"Greg Cochard","email":"greg.cochard@gmail.com"}],"repository":{"type":"git","url":"git://github.com/gotwarlost/mock-spawn.git"},"scripts":{"pretest":"jshint --config ./jshint.json index.js examples/simple/*js examples/complete/*js","test":"./run-tests.sh"},"dependencies":{"through":"2.3.x"},"devDependencies":{"async":"0.2.x","mockery":"1.4.x","mocha":"1.x","istanbul":"0.x","jshint":"2.4.x"},"license":"BSD","gitHead":"f240d20a798ed97dc99e213a2caf75b5280baf24","bugs":{"url":"https://github.com/gotwarlost/mock-spawn/issues"},"homepage":"https://github.com/gotwarlost/mock-spawn","_id":"mock-spawn@0.2.3","_shasum":"e2470e3fea003670e1ddd2c74a7ef177cc0240f6","_from":".","_npmVersion":"1.4.25","_npmUser":{"name":"gotwarlost","email":"kananthmail-github@yahoo.com"},"maintainers":[{"name":"gotwarlost","email":"kananthmail-github@yahoo.com"}],"dist":{"shasum":"e2470e3fea003670e1ddd2c74a7ef177cc0240f6","tarball":"https://registry.npmjs.org/mock-spawn/-/mock-spawn-0.2.3.tgz","integrity":"sha512-HtFEMnnq7o6kxY3OwJ6+A33KKf6U4ZPaEM03pjsEwEC1yriZRJFA9wHy/SHsVwLE9u5ITi/LHkelCYfBLUKIRQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDzSvUO9Yj4B39LOjtijhFeHq367YoALvXFUq3zUDE7TgIhANPXREoWT0rDJfdPL98o72HBZ+nN9N12Ma7PNoxdkAo7"}]}},"0.2.4":{"name":"mock-spawn","description":"A mock for child_process.spawn","version":"0.2.4","keywords":["child_process","child process","spawn","mock"],"author":{"name":"Krishnan Anantheswaran","email":"kananthmail-github@yahoo.com"},"contributors":[{"name":"Greg Cochard","email":"greg.cochard@gmail.com"}],"repository":{"type":"git","url":"git://github.com/gotwarlost/mock-spawn.git"},"scripts":{"pretest":"jshint --config ./jshint.json index.js examples/simple/*js examples/complete/*js","test":"./run-tests.sh"},"dependencies":{"through":"2.3.x"},"devDependencies":{"async":"0.2.x","mockery":"1.4.x","mocha":"1.x","istanbul":"0.x","jshint":"2.4.x"},"license":"BSD","gitHead":"ac3bf9650b12eaa08a50028127f16a5e0004e225","bugs":{"url":"https://github.com/gotwarlost/mock-spawn/issues"},"homepage":"https://github.com/gotwarlost/mock-spawn","_id":"mock-spawn@0.2.4","_shasum":"d35d4df6f94a4fe2787d6309660f631ffa3b071a","_from":".","_npmVersion":"1.4.25","_npmUser":{"name":"gotwarlost","email":"kananthmail-github@yahoo.com"},"maintainers":[{"name":"gotwarlost","email":"kananthmail-github@yahoo.com"}],"dist":{"shasum":"d35d4df6f94a4fe2787d6309660f631ffa3b071a","tarball":"https://registry.npmjs.org/mock-spawn/-/mock-spawn-0.2.4.tgz","integrity":"sha512-x+YujAS9R0RTjULrsxxhVO9jGZaKOo5s5pXYmDawVheIpx5pJqcW0GK4D6fj9ZWfIIi7u/Aj3UWouI9wwn27mQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIDnYP8Tftn+K/CvNVKW8egzLo/04C4E69Vo7fI/HhkBVAiAr9N/VX8dbGpW0MFa9xUtZv6bIugDQoP96f7HCX+W/LQ=="}]}},"0.2.5":{"name":"mock-spawn","description":"A mock for child_process.spawn","version":"0.2.5","keywords":["child_process","child process","spawn","mock"],"author":{"name":"Krishnan Anantheswaran","email":"kananthmail-github@yahoo.com"},"contributors":[{"name":"Greg Cochard","email":"greg.cochard@gmail.com"},{"name":"Shay Erlichmen @erlichmen"}],"repository":{"type":"git","url":"git://github.com/gotwarlost/mock-spawn.git"},"scripts":{"pretest":"jshint --config ./jshint.json index.js examples/simple/*js examples/complete/*js","test":"./run-tests.sh"},"dependencies":{"through":"2.3.x"},"devDependencies":{"async":"0.2.x","mockery":"1.4.x","mocha":"1.x","istanbul":"0.x","jshint":"2.4.x"},"license":"BSD","gitHead":"92c562967751bd2fd8f4c210dcb5a87b2de1df0f","bugs":{"url":"https://github.com/gotwarlost/mock-spawn/issues"},"homepage":"https://github.com/gotwarlost/mock-spawn","_id":"mock-spawn@0.2.5","_shasum":"a9def45fc159672e4433b63a2067a416c164ee80","_from":".","_npmVersion":"1.4.25","_npmUser":{"name":"gotwarlost","email":"kananthmail-github@yahoo.com"},"maintainers":[{"name":"gotwarlost","email":"kananthmail-github@yahoo.com"}],"dist":{"shasum":"a9def45fc159672e4433b63a2067a416c164ee80","tarball":"https://registry.npmjs.org/mock-spawn/-/mock-spawn-0.2.5.tgz","integrity":"sha512-rtXtnUo9R+U8Kn16um4UZ7oqZECYhnnG9vLRy0GtKEHW0rgx2dXb5993GS+66DqXU7QOgNUrJZ1kuQ5Z55EriA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDHFDzkJl0TL4Az34QAg35rIEdsgIp7e/gbQzjZugCHWQIhAJnltHt/ZM8mvJTWboEVSqDR4HVkjjFoiSuLxgVH9tgm"}]}},"0.2.6":{"name":"mock-spawn","description":"A mock for child_process.spawn","version":"0.2.6","keywords":["child_process","child process","spawn","mock"],"author":{"name":"Krishnan Anantheswaran","email":"kananthmail-github@yahoo.com"},"contributors":[{"name":"Greg Cochard","email":"greg.cochard@gmail.com"},{"name":"Shay Erlichmen @erlichmen"},{"name":"Leonid Beschasny @lbeschastny"}],"repository":{"type":"git","url":"git://github.com/gotwarlost/mock-spawn.git"},"scripts":{"pretest":"jshint --config ./jshint.json index.js examples/simple/*js examples/complete/*js","test":"./run-tests.sh"},"dependencies":{"through":"2.3.x"},"devDependencies":{"async":"0.2.x","mockery":"1.4.x","mocha":"1.x","istanbul":"0.x","jshint":"2.4.x"},"license":"BSD","gitHead":"0abcf12248a8a9eab9e316eee196749836ae1a81","bugs":{"url":"https://github.com/gotwarlost/mock-spawn/issues"},"homepage":"https://github.com/gotwarlost/mock-spawn#readme","_id":"mock-spawn@0.2.6","_shasum":"b39c15a1c067504310144151f2c1de344d03937f","_from":".","_npmVersion":"2.12.0","_nodeVersion":"0.10.26","_npmUser":{"name":"gotwarlost","email":"kananthmail-github@yahoo.com"},"maintainers":[{"name":"gotwarlost","email":"kananthmail-github@yahoo.com"}],"dist":{"shasum":"b39c15a1c067504310144151f2c1de344d03937f","tarball":"https://registry.npmjs.org/mock-spawn/-/mock-spawn-0.2.6.tgz","integrity":"sha512-cMSfGmQlTiCF54a7taY1cUVXuuEKqDR8vLrfN7pI4LCskxwRedupMQB7o5d5Hg5L6rctvtyZJwUxMl3czTd4tg==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIE5Rg4TyXug3Uoj4cRkkszU1U8SL4iCO8sTZUQR6mQA4AiBt/EAZuWC2Bcnk4f0HLijvDEJeGxzNzkEVcObQH+Y8nQ=="}]}}},"readme":"mock-spawn\n==========\n\n[![Build Status](https://secure.travis-ci.org/gotwarlost/mock-spawn.png)](http://travis-ci.org/gotwarlost/mock-spawn)\n\nAn easy-to-use mock for `child_process.spawn`.\n\n### Key ideas\n\n* All mock processes wrap a user-supplied, asynchronous \"runner function\"\nthat calls a callback to indicate that the process is \"done running\"\n* You can plug in a \"strategy function\" that returns runner functions for\nhandling specific spawn invocations.\n* When no specific runner function is found, a default function is used.\nThe baked-in default returns an exit code of 0 and returns immediately. The\ndefault function may be overridden for fancier behavior.\n* All the information on how many times `spawn` was invoked and the details\nof every invocation are available as attributes on the mock for later assertions\n* Testing simple cases requires no setup whatsoever\n* A simple \"sequence\" strategy for being able to say: do this on the first\ninvocation, do the other thing on the second invocation and so on is available\nfor use\n\n### Usage\n\n#### Common cases\n\n```javascript\nvar mockSpawn = require('mock-spawn');\n\n// override child_process.spawn\n// this is a simplistic example; you can use a library like `mockery` to\n// set a new instance for every test. See examples/complete/test.js\nvar mySpawn = mockSpawn();\nrequire('child_process').spawn = mySpawn;\n\n// at this point you have mocked child_process.spawn to always exit 0\n// and write nothing to stdout or stderr\n\n// let's change the default processing to exit 1 always and write something\n// to stdout\nmySpawn.setDefault(mySpawn.simple(1 /* exit code */, 'hello world' /* stdout */));\n\n// let's tell the mock to do specific things on sequential calls\n// in this case we exit 0 on the first call, 1 on the second call and so on\nmySpawn.sequence.add(mySpawn.simple(0));\nmySpawn.sequence.add(mySpawn.simple(1));\nmySpawn.sequence.add(function (cb) {\n    setTimeout(function () { return cb(2); }, 2000);\n});\nmySpawn.sequence.add(function (cb) {\n    // test the error handling of your library\n    this.emit('error', new Error('spawn ENOENT');\n    setTimeout(function() { return cb(8); }, 10);\n});\nmySpawn.sequence.add({throws:new Error('spawn ENOENT')});\n\n// the fourth call to spawn will use the default function we set up to exit 1\n\n// the fifth call to spawn will emit an error and emit exit with code 8 on the\n// next tick of the event loop\n\n// the sixth call to spawn will throw an error synchronously\n\n// call your test library here that invokes spawn the way you expect it to\nlib.doSomething(function (err) {\n    /* after the test is done running, you can make assertions like so */\n    assert.equal(6, mySpawn.calls.length);\n    var firstCall = mySpawn.calls[0];\n    assert.equal('ls', firstCall.command);\n    assert.deepEqual([ '-l' ], firstCall.args);\n    assert.equal(0, firstCall.exitCode);\n});\n\n```\n\n#### Getting fancy with custom strategies\n\n\n```javascript\nvar mockSpawn = require('mock-spawn');\n\n// basic stuff\nvar mySpawn = mockSpawn();\nrequire('child_process').spawn = mySpawn;\n\n// we are now testing if our library under test retries spawn commands on error\n// when executing the `foo` command\n\nvar count = 0;\nmySpawn.setStrategy(function (command, args, opts) {\n    if (command !== 'foo') { return null; } // use default\n    if (++count < 3) {\n        return mySpawn.simple(1); //exit 1 immediately\n    }\n    return function (cb) {\n        this.stdout.write('output data my library expects');\n        return cb(0); // and exit 0\n    };\n});\n\n```\n\n### API\n\n#### The runner function\n\nThe runner function accepts a single callback that needs to be called with an\nexit code and optionally a signal name. If you define a `throws` property on\nthe runner object, it will throw that error synchronously to mimic the\nbehavior of `child_process.spawn`. It will ignore everything else in this case,\nand it will not \"run\" at all. \n**CAVEAT**: The `throws` value *must* be an instanceof `Error`.\n\nThe runner function has access to the following attributes via `this`\n* `this.stdout` - the standard output of the process to which it can write\n* `this.stderr` - the standard error of the process to which it can write\n* `this.command` - the command for the `spawn` call\n* `this.args` - the args for the `spawn` call\n* `this.opts` - the options object passed to the `spawn` call\n* `this.emit` - the emit method of the underlying `EventEmitter`\n\nThe process \"runs\" until the runner calls the callback.\n\n#### The strategy function\n\nThe strategy function accepts 3 arguments: the command, args and options passed\nto the `spawn` invocation. It can inspect these to return a customized runner\nfor just that invocation.\n\nIt can also return a falsy value to indicate that the default function should\nbe used.\n\n####  var mySpawn = require('mock-spawn')([verbose])\n\nreturns a function that can be plugged into `child_process` as a replacement\nfor `spawn`\n\n* verbose - true to see additional debug messages from this library\n\n#### var fn = mySpawn.simple(exit-code, [output-data], [error-data])\n\nreturns a runner function that exits with the specified code and writes\nspecific data to the output and error streams\n\nArguments are:\n* exit-code: exit code for the process\n* output-data: the data to be written to standard output\n* error-data: the data to be written to standard error\n\n#### mySpawn.setDefault(fn)\n\nsets the default processing of all spawn invocations to use the runner function\nspecified\n\n* fn - a runner function to handler default processing\n\n#### mySpawn.sequence.add(fn)\n\nenables the `sequence` strategy and calls the runner function supplied at the\nspecific point in the sequence.\n\n* fn - the runner function to use. The nth call to `add` plugs a runner function\nfor the nth invocation to `spawn`\n\nDo **not** mix `sequence.add` and `setStrategy` calls for a specific run.\n\n#### mySpawn.setStrategy(fn)\n\nsets `fn` as the strategy that will return runner functions on demand.\n\n* fn - the function to be used as the strategy function.\n\nDo **not** mix `sequence.add` and `setStrategy` calls for a specific run.\n\n#### mySpawn.setSignals(obj)\n\nsets `obj` as a lookup table for whether to exit. If the value is `true`,\nthen the runner will emit `exit` with code `null` and signal `<signal>`.\n\n* obj - the object with signal names and whether to exit.\n\n#### mySpawn.calls\n\narray of mock process objects that you can use to inspect how your library\nunder test invoked `spawn`. Every object has the following properties available\n\n* `command` - the command\n* `args` - the command arguments\n* `opts` - the options passed to the spawn invocation\n* `exitCode` - the exit code of the process\n* `signal` - the signal delivered to the process (simulated via the runner)\n\n### License\n\nBSD. See accompanying LICENSE file.\n\n### Third-party libraries\n\nThe following third-party libraries are used by this module:\n\n* through: https://github.com/dominictarr/through\n\n### TODO\n\nPull requests welcome!\n\n * `child_process.fork` and `child_process.exec` processing\n * strategy functions on `process.kill`\n\n\n","maintainers":[{"name":"gotwarlost","email":"kananthmail-github@yahoo.com"}],"time":{"modified":"2022-06-20T02:11:44.135Z","created":"2014-03-28T05:10:54.596Z","0.2.1":"2014-03-28T05:10:54.596Z","0.2.2":"2014-10-31T19:55:19.895Z","0.2.3":"2015-01-07T05:30:08.577Z","0.2.4":"2015-02-28T04:13:08.193Z","0.2.5":"2015-05-17T22:16:18.211Z","0.2.6":"2015-07-01T15:35:25.600Z"},"homepage":"https://github.com/gotwarlost/mock-spawn#readme","keywords":["child_process","child process","spawn","mock"],"repository":{"type":"git","url":"git://github.com/gotwarlost/mock-spawn.git"},"contributors":[{"name":"Greg Cochard","email":"greg.cochard@gmail.com"},{"name":"Shay Erlichmen @erlichmen"},{"name":"Leonid Beschasny @lbeschastny"}],"author":{"name":"Krishnan Anantheswaran","email":"kananthmail-github@yahoo.com"},"bugs":{"url":"https://github.com/gotwarlost/mock-spawn/issues"},"license":"BSD","readmeFilename":"README.md","users":{"limulus":true,"lukaszczernal":true,"jmsherry":true}}