{"name":"mutate-fs","version":"1.0.0","description":"Mutate the filesystem behavior for tests.","main":"index.js","devDependencies":{"tap":"^10.3.2"},"scripts":{"test":"tap test/*.js --100","preversion":"npm test","postversion":"npm publish","postpublish":"git push origin --all; git push origin --tags"},"repository":{"type":"git","url":"git+https://github.com/isaacs/mutate-fs.git"},"keywords":["file system","munge","mutate","mock","fs"],"author":{"name":"Isaac Z. Schlueter","email":"i@izs.me","url":"http://blog.izs.me/"},"license":"ISC","files":["index.js"],"gitHead":"c1a49d0f4ca7d1eff90942818491ea8bf0fb5d65","bugs":{"url":"https://github.com/isaacs/mutate-fs/issues"},"homepage":"https://github.com/isaacs/mutate-fs#readme","_id":"mutate-fs@1.0.0","_shasum":"480ab5acd47d74058c8524602f19652453cda9ef","_from":".","_npmVersion":"4.5.0","_nodeVersion":"8.0.0-pre","_npmUser":{"name":"isaacs","email":"i@izs.me"},"dist":{"shasum":"480ab5acd47d74058c8524602f19652453cda9ef","tarball":"http://registry-npm.ywwl.com/mutate-fs/download/mutate-fs-1.0.0.tgz","integrity":"sha512-UF3TI8na70PGE6YKUNas8yMn0u3hEtnnZPrHXgxo6hs4m/xi2J/ssGJStSAN//3wgCkyCASa6XURpLLmYSl/bg==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCWC2xO18nxHB3u07cVMgjTM/+D0hkn9f3MPIzmw9zUxQIgFtoktZxaCdIrjTBqkHkeXJgdb4sikMn9/UG+rJOSEN8="}],"size":3341,"noattachment":false,"key":"/mutate-fs/-/mutate-fs-1.0.0.tgz"},"maintainers":[{"name":"isaacs","email":"i@izs.me"}],"_npmOperationalInternal":{"host":"packages-18-east.internal.npmjs.com","tmp":"tmp/mutate-fs-1.0.0.tgz_1492104957249_0.8368437893223017"},"directories":{},"readme":"# mutate-fs\n\nMutate the filesystem behavior for tests.\n\n![X-Men](xmen.gif \"mutants\")\n\nThis is not a full-fledged filesystem mock library as much as it is a\nway to just modify the data that's returned, especially to trigger\ncases where the fs is a bit of a jerk, and you want to make sure your\ncode handles it properly.\n\nAll of the methods return a function that restores the default\nbehavior.\n\nYou should probably not use this module outside of a test environment.\nBy design, it does bad things that will probably break stuff.\n\n## USAGE\n\n```js\nconst mutateFS = require('mutate-fs')\n\n// you can of course us this with any test harness,\n// including \"plain old assert\", but showing TAP because I like it.\n\nconst t = require('tap')\n\nt.test('test what happens when stat fails', t => {\n  // restore normalcy after this test\n  t.tearDown(mutateFS.statFail(new Error('pwn')))\n\n  // verify that statting this file (which exists) throws our error\n  t.throws(_ => {\n    fs.statSync(__filename)\n  }, new Error('pwn'))\n\n  t.end()\n})\n\n// plain-old-assert example\n// make stat lie\nconst restore = mutateFS.statType('Directory')\nconst assert = require('assert')\nassert(fs.statSync(__filename).isDirectory())\nrestore()\nassert(fs.statSync(__filename).isFile())\n```\n\n## METHODS\n\n### fail(method, error)\n\nWhenever `fs[method]` is called, call the callback with the supplied\nerror.  Whenever `fs[methodSync]` is called, throw the supplied error.\n\nNote that this means that the actual underlying fs method is not called.\n\nError is decorated with a `callstack` string, which is the stack where\nthe fail method was actually called from.\n\n### pass(method, data)\n\nThe oppose of `fail`.  Whenever `fs[method]` is called, call the\ncallback with the supplied data and no error.  Whenever\n`fs[methodSync]` is called, return the supplied data.\n\nNote that this means that the actual underlying fs method is not called.\n\n### mutate(method, fn)\n\nWhenever `fs[method]` or `fs[methodSync]` is called, apply the\n`fn(error, data)` to the results.\n\n`fn` can either mutate the data in-place (and return nothing) or can\nreturn a `[error, data]` array which is treated as the new result.\n\n### mutateArgs(method, fn)\n\nMutate the arguments passed _into_ the fs method specified.\n\n`fn` takes an array of arguments, and should return the munged set of\narguments to call the method with.\n\n### zenoRead()\n\nMake all `read()` calls appear to return half as many bytes.  This\nexercises frequently overlooked edge cases in many programs that call\n`fs.read()` directly.\n\nAs of version 2, this works by modifying the `length` argument passed\nto `fs.read` and `fs.readSync'.  In version 1.x of this library, it\nonly modified the _reported_ number of bytes read, limiting its\nutility for testing shortened non-positioned (file-scanning) reads.\n\nThe name is a reference to [Zeno's Paradox of Achilles and the\nTortoise](https://en.wikipedia.org/wiki/Zeno%27s_paradoxes#Achilles_and_the_tortoise).\n\n### delay(method, ms)\n\nDelay calls to fs[method] by the specified number of milliseconds.\n\nDelays sync calls by doing a bunch of unnecessary file reads in a\nbusy-loop.\n\n### statFail(error)\n\nLike `fail()`, but called on all three of fstat, lstat, and stat.\n\n### statMutate(fn)\n\nLike `mutate()`, but called on all three of fstat, lstat, and stat.\n\n### statType(type)\n\nMutate stat, lstat, and fstat return values to make them appear to be\nthe provided type.  That is, `stat.is<Type>` will return true.\n\nType must be one of: `'File'`, `'Directory'`, `'CharacterDevice'`,\n`'BlockDevice'`, `'FIFO'`, `'SymbolicLink'`, or `'Socket'`.\n","publish_time":1492104959151,"_cnpm_publish_time":1492104959151,"dist-tags":{"latest":"2.1.1"}}