{"_id":"@atakama/capio","_rev":"1-944376fdebef85e6ebdd0e4a0ab78adc","name":"@atakama/capio","dist-tags":{"latest":"0.0.1"},"versions":{"0.0.1":{"name":"@atakama/capio","version":"0.0.1","description":"Capture logs and i/o in an async-safe way","main":"capio.js","scripts":{"lint":"eslint *.js","test":"node test.js","coverage":"nyc --reporter lcov --reporter text-summary yarn test","codecov":"codecov"},"devDependencies":{"@atakama/qtest":"^1.6.0","codecov":"^3.7.0","eslint":"^7.4.0","eslint-plugin-standard":"^4.0.1","nyc":"^15.1.0"},"engines":{"node":">=8"},"repository":{"type":"git","url":"git+https://github.com/AtakamaLLC/capio.git"},"keywords":["coverage","diffs","diff"],"author":{"name":"Erik Aronesty"},"license":"ISC","bugs":{"url":"https://github.com/AtakamaLLC/capio/issues"},"homepage":"https://github.com/AtakamaLLC/capio#readme","gitHead":"5b1bb9a0ba4a748895ea3106d943c0b7700c94ee","_id":"@atakama/capio@0.0.1","_nodeVersion":"10.21.0","_npmVersion":"6.14.4","dist":{"integrity":"sha512-ptv1iSgIuv1ihs5Visua5gleDZ8wafXlJ9Asp3UA/kptTZdD1tNSTEedAbgaJ7wkFBH4nCVY+YyhKE2V6RVPpw==","shasum":"759b8fb42a634124719faccf7b563596e30ceaaa","tarball":"https://registry.npmjs.org/@atakama/capio/-/capio-0.0.1.tgz","fileCount":5,"unpackedSize":8235,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJfAzBTCRA9TVsSAnZWagAAW18P/1PJ36kU90C338qqICcD\nKs5VbgjkaJ7t1BbeQMwa1ZLh0BBEisCr2qYJ7W/RRpnoDjb1k19jj0SgVPmw\nUQgHtVZ2Ka7RWsPYNRLLwSBcOX0hL9wSZ08H0BAbhqR7pXQ32LNk+LLdif3Q\nNphjUhQ/Q34RO2wOTJujvtu+kHahggnpEf69MdBJGwxGow2/SA+fD3LyauHE\ntUvMrt1E26QjtHj3i0mjyx+KGLOqz5mOwYQ28SVX6/3Mv+LHUXXXWrKYRwpM\nWnU/MGnQWd6ouN3qFt0vbs/w1chbIpp/NOfPrwZD8jBnv4rZqWaWspZaBvAD\n9Oe2fcCsysCuuWy9OfTJGol9bspNmcEIZDhvvDJuaozKDRWT6U8ssO95aFKX\nJGPAjdC3hp6SsV3teWSB8S177i7lBwHqc+2BsW3DKmW/Te/VGcgZZgzsGqxc\nnrPYSV6Lf97PCOPiY+c3xeypGCdKi9Y5brSh1Q98pvnLWaTjQUfnyF9tuJAn\nS0wQwaA6gN18W/BwOB8whQfPWE/2+cmyRRb8IdjsKWQEbrH7EnjrCdVCBWYt\n18aYKVOU5QlO1X/ePNphEU5ssE5m2ojyCI7mqiOQ4aeWgxCdEZzdssRYBn6j\n4hjU3mUR5IMi000MkRKWdQPX0E5FuPKt2cjC1wJTPtLiGyG3iFDnzPRz3sSP\njY9Z\r\n=brqQ\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIC2GPG5Ycgwd5VUZGS5QQhbjqr/lnDDdd2KyRGvl83ZnAiEAjVyT7FkuwwSXe50sonkQ5egD/r0Mep7jIsKt6tCRs5w="}]},"maintainers":[{"name":"alexanderpinkerton","email":"Alexpinkerton88@gmail.com"},{"name":"earonesty","email":"erik@atakama.com"}],"_npmUser":{"name":"earonesty","email":"erik@atakama.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/capio_0.0.1_1594044498757_0.40817207347125195"},"_hasShrinkwrap":false}},"time":{"created":"2020-07-06T14:08:16.133Z","0.0.1":"2020-07-06T14:08:18.981Z","modified":"2022-04-04T16:02:28.979Z"},"maintainers":[{"name":"alexanderpinkerton","email":"Alexpinkerton88@gmail.com"},{"name":"earonesty","email":"erik@atakama.com"}],"description":"Capture logs and i/o in an async-safe way","homepage":"https://github.com/AtakamaLLC/capio#readme","keywords":["coverage","diffs","diff"],"repository":{"type":"git","url":"git+https://github.com/AtakamaLLC/capio.git"},"author":{"name":"Erik Aronesty"},"bugs":{"url":"https://github.com/AtakamaLLC/capio/issues"},"license":"ISC","readme":"# Capio - async log, io and generic global state capture\n\nWhen writing unit test for complex async code it's somtimes difficult to isolate compoenent output.\n\nNode's [async_hooks](https://nodejs.org/api/async_hooks.html) library provides enough information to allow\nglobals to be swapped in and out.\n\nAlternately, the deprecated [domain](https://nodejs.org/api/domain.html) module is used if needed.\n\nCapio wraps both of these libraries, meaning you don't have to think about which version of node you're running.\n\n### Console log capture:\n\nConsider this:\n\n```node\ntest1 = async ()=>{\n    await thing1()\n}\n\ntest2 = async ()=>{\n    await thing2()\n}\n```\n\nWhen run linearly, we can use the simple [capture_console](https://www.npmjs.com/package/capture-console) hook to capture output:\n\nHowever, if we want to run `thing1` and `thing2` in parallel, the logs will get jumbled up.\n\nCapio injects a 'captio' member to errors, which allows this to work:\n\n```node\nrun1 = async (test) => {\n    try {\n        await capio.captureLog(test)\n    } except (e) {\n        for (args of e.capio) {\n            console.log(...args)\n        }\n    }\n}\n\nPromise.all(tests.map(t=>run1(t)))\n```\n\n### I/O Spies\n\nCapio can be used to 'spy' streams as well:\n\n```node\nspied = await capio.captureIo(test, [socket, process.stdout], {spy: true})\n\nconsole.log(\"socket\", spied[0])\nconsole.log(\"stdout\", spied[1])\n```\n\n\n### Low level tool for framework devs\n\nThis will call `swapIn` every time async execution contexts are run in the test, \nand will call `swapOut` evert time they are finished.\n\n```\nawait capio.capture(test, swapIn, swapOut)\n```\n","readmeFilename":"README.md"}