{"_id":"@atcodes/mockable","_rev":"7-b8aeaf052f6287851d08e781f085de20","name":"@atcodes/mockable","dist-tags":{"latest":"1.1.6"},"versions":{"1.0.0":{"name":"@atcodes/mockable","version":"1.0.0","keywords":["esm","mocking","testing"],"author":{"name":"Adam Tuttle","email":"https://adamtuttle.codes"},"license":"MIT","_id":"@atcodes/mockable@1.0.0","maintainers":[{"name":"atuttle","email":"adam@fusiongrokker.com"}],"dist":{"shasum":"d91aa6327a91c14bb6caccea8ed081bd87f1ca32","tarball":"https://registry.npmjs.org/@atcodes/mockable/-/mockable-1.0.0.tgz","fileCount":5,"integrity":"sha512-culFPlpkOZ2j1NFPax31G7YkEF20v2eGPrTAQla4jjGsfT4wyO9uppF2REWIPObUcWaL5JD5dC6wCyUE5OV9zw==","signatures":[{"sig":"MEUCIQCEAZj8bYzZrUvBGBD78yjxACNdNsLi5TYqIR84mcdILgIgWIDmW87F2IpE35XyoQO6krZV4S/Ml3VFYTJOg2/FRZM=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":4472},"main":"index.js","type":"module","engines":{"node":">=20.0.0"},"gitHead":"31042cbf4b37e86c86e83d4dc0c6371a67672c38","scripts":{"test":"node --test","test:watch":"node --test --watch"},"_npmUser":{"name":"atuttle","email":"adam@fusiongrokker.com"},"_npmVersion":"10.5.0","description":"A Higher Order Function that allows runtime overriding of functions, for testing purposes. Based on https://nalanj.dev/posts/mocking-without-loaders/","directories":{},"_nodeVersion":"20.12.2","_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/mockable_1.0.0_1713976148725_0.14134485073238068","host":"s3://npm-registry-packages"}},"1.1.0":{"name":"@atcodes/mockable","version":"1.1.0","keywords":["esm","mocking","testing"],"author":{"name":"Adam Tuttle","email":"https://adamtuttle.codes"},"license":"MIT","_id":"@atcodes/mockable@1.1.0","maintainers":[{"name":"atuttle","email":"adam@fusiongrokker.com"}],"dist":{"shasum":"3895e2b4e30b42210ae743668fe24313a67c58fa","tarball":"https://registry.npmjs.org/@atcodes/mockable/-/mockable-1.1.0.tgz","fileCount":6,"integrity":"sha512-7Is53RdHxAl97vlaf4ySm191WyMTi+/xhKEqMVYP98HvqhylTrLNWa1FoDT1P2U3mXDnE9g5wbxPM3zqeN4B3Q==","signatures":[{"sig":"MEYCIQCHeIb+EYs9wDalxZPB8l8EYWLMaukKNit1XTuD5DmiCwIhAI/DQx9d+ynkgW0WpsP8cEtTRkfoq3cr8iqpMz9VgYQx","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":4751},"main":"index.js","type":"module","engines":{"node":">=20.0.0"},"exports":{"import":"./dist/index.mjs","require":"./dist/index.js"},"gitHead":"324d59c4eac335527b549ce271b32d7ad1a32755","scripts":{"lint":"tsc","test":"pnpm run build && pnpm run test:run","build":"tsup index.ts","test:run":"node --test","test:watch":"node --test --watch","prepublishOnly":"pnpm run build"},"_npmUser":{"name":"atuttle","email":"adam@fusiongrokker.com"},"_npmVersion":"10.5.0","description":"A Higher Order Function that allows runtime overriding of functions, for testing purposes. Based on https://nalanj.dev/posts/mocking-without-loaders/","directories":{},"_nodeVersion":"20.12.2","_hasShrinkwrap":false,"devDependencies":{"tsup":"^8.0.2","typescript":"^5.4.5","@types/node":"^20.12.7"},"_npmOperationalInternal":{"tmp":"tmp/mockable_1.1.0_1714051738785_0.715262730322437","host":"s3://npm-registry-packages"}},"1.1.1":{"name":"@atcodes/mockable","version":"1.1.1","keywords":["esm","mocking","testing"],"author":{"name":"Adam Tuttle","email":"https://adamtuttle.codes"},"license":"MIT","_id":"@atcodes/mockable@1.1.1","maintainers":[{"name":"atuttle","email":"adam@fusiongrokker.com"}],"dist":{"shasum":"248f2c9a49d0829f4281981b49eafff0461873d4","tarball":"https://registry.npmjs.org/@atcodes/mockable/-/mockable-1.1.1.tgz","fileCount":6,"integrity":"sha512-O4jXkNYLYpVHxevlv6brezKyA9pfr0Ny45OqFvDghHrVeEhsOpBOJQLMhMyc9gWdI9PE6Iv9UpjDLkrD73R0Ug==","signatures":[{"sig":"MEUCIF/Jy6sjOrsV/I77wkvrgFVNwX3hSvkef8bSELzqbMuBAiEA+BzHZWmJ5mDlfFQ3OitYG+4RiyXPEGC43ykAAxTc7LE=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":4751},"main":"index.js","type":"module","engines":{"node":">=20.0.0"},"exports":{"import":"./dist/index.js","require":"./dist/index.cjs"},"gitHead":"5da127991d760a7615e0bd8f51d89e266147334e","scripts":{"lint":"tsc","test":"pnpm run build && pnpm run test:run","build":"tsup index.ts","test:run":"node --test","test:watch":"node --test --watch","prepublishOnly":"pnpm run build"},"_npmUser":{"name":"atuttle","email":"adam@fusiongrokker.com"},"_npmVersion":"10.5.0","description":"A Higher Order Function that allows runtime overriding of functions, for testing purposes. Based on https://nalanj.dev/posts/mocking-without-loaders/","directories":{},"_nodeVersion":"20.12.2","_hasShrinkwrap":false,"devDependencies":{"tsup":"^8.0.2","typescript":"^5.4.5","@types/node":"^20.12.7"},"_npmOperationalInternal":{"tmp":"tmp/mockable_1.1.1_1714052049629_0.16463214775600288","host":"s3://npm-registry-packages"}},"1.1.2":{"name":"@atcodes/mockable","version":"1.1.2","keywords":["esm","mocking","testing"],"author":{"name":"Adam Tuttle","email":"https://adamtuttle.codes"},"license":"MIT","_id":"@atcodes/mockable@1.1.2","maintainers":[{"name":"atuttle","email":"adam@fusiongrokker.com"}],"dist":{"shasum":"df44a10975875f1f20c5b35527f2d12f1e7fc091","tarball":"https://registry.npmjs.org/@atcodes/mockable/-/mockable-1.1.2.tgz","fileCount":6,"integrity":"sha512-AKX0/5rnx5mvPJeam+OEnxTgt6pDQhOzwZQIa31MsozH5/dCvVCKgLNPFu8fW2wiuciVw+g3NItD+67cR81Lpg==","signatures":[{"sig":"MEUCIH/Uzw7t3nMVqDNruhjlgYylcRylcZv3kv6QCsX6kCoRAiEAus9TFpDhSCRQPod2g1OgdspSTqeMBasXudypzGbzwA4=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":4858},"main":"index.js","type":"module","engines":{"node":">=20.0.0"},"exports":{"import":{"types":"./dist/index.d.ts","default":"./dist/index.js"},"require":{"types":"./dist/index.d.cts","default":"./dist/index.cjs"}},"gitHead":"7cb938786f105e63fc98f50de72227f3d01a143d","scripts":{"lint":"tsc","test":"pnpm run build && pnpm run test:run","build":"tsup index.ts","test:run":"node --test","test:watch":"node --test --watch","prepublishOnly":"pnpm run build"},"_npmUser":{"name":"atuttle","email":"adam@fusiongrokker.com"},"_npmVersion":"10.5.0","description":"A Higher Order Function that allows runtime overriding of functions, for testing purposes. Based on https://nalanj.dev/posts/mocking-without-loaders/","directories":{},"_nodeVersion":"20.12.2","_hasShrinkwrap":false,"devDependencies":{"tsup":"^8.0.2","typescript":"^5.4.5","@types/node":"^20.12.7"},"_npmOperationalInternal":{"tmp":"tmp/mockable_1.1.2_1714052628135_0.7136173033912299","host":"s3://npm-registry-packages"}},"1.1.3":{"name":"@atcodes/mockable","version":"1.1.3","keywords":["esm","mocking","testing"],"author":{"name":"Adam Tuttle","email":"https://adamtuttle.codes"},"license":"MIT","_id":"@atcodes/mockable@1.1.3","maintainers":[{"name":"atuttle","email":"adam@fusiongrokker.com"}],"dist":{"shasum":"2a736c33dbd80ea603f3b77521dd4904e3af9283","tarball":"https://registry.npmjs.org/@atcodes/mockable/-/mockable-1.1.3.tgz","fileCount":6,"integrity":"sha512-B1/I1EymyrchDrzrNrfZx5a1tVCz7d0jxnAL8xURjuUldyE9Rutey41CJgrH0xVJVEpk0/ZqMsFcYwS46mbXcA==","signatures":[{"sig":"MEUCIQCqtPDM1viulzbZ7XadpIwGrrzu2bceJaQA3pYZiE6/AwIgU+cXoiig81zx9cLno10bge3BNw0OF6sX74fWd8V07rk=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":4854},"main":"index.js","type":"module","engines":{"node":">=20.0.0"},"exports":{"import":{"types":"./dist/index.d.ts","default":"./dist/index.js"},"require":{"types":"./dist/index.d.cts","default":"./dist/index.cjs"}},"gitHead":"1709efdb98c2155c722b420345e5d2caed4f2e8e","scripts":{"lint":"tsc","test":"pnpm run build && pnpm run test:run","build":"tsup index.ts","test:run":"node --test","test:watch":"node --test --watch","prepublishOnly":"pnpm run build"},"_npmUser":{"name":"atuttle","email":"adam@fusiongrokker.com"},"_npmVersion":"10.5.0","description":"A Higher Order Function that allows runtime overriding of functions, for testing purposes. Based on https://nalanj.dev/posts/mocking-without-loaders/","directories":{},"_nodeVersion":"20.12.2","_hasShrinkwrap":false,"devDependencies":{"tsup":"^8.0.2","typescript":"^5.4.5","@types/node":"^20.12.7"},"_npmOperationalInternal":{"tmp":"tmp/mockable_1.1.3_1714053190504_0.052311497038694865","host":"s3://npm-registry-packages"}},"1.1.4":{"name":"@atcodes/mockable","version":"1.1.4","keywords":["esm","mocking","testing"],"author":{"name":"Adam Tuttle","email":"https://adamtuttle.codes"},"license":"MIT","_id":"@atcodes/mockable@1.1.4","maintainers":[{"name":"atuttle","email":"adam@fusiongrokker.com"}],"dist":{"shasum":"1a3a8bcee1dcdff17ef96fedb3d8ef259a4b92c8","tarball":"https://registry.npmjs.org/@atcodes/mockable/-/mockable-1.1.4.tgz","fileCount":6,"integrity":"sha512-62mbAeZXQHbKRd7oqhWSCGd6Gw+UhA7t2/gz80xvZlnbqZwATzcroyruwNf8T+pRjyVPbYX0pfBJgBAbupmewA==","signatures":[{"sig":"MEYCIQCaUa89i+kJKKyf8PYSqD1O2cNqgafiAjPdy/bvvDvciAIhAPCTyFsiDe0FgBSLvz4qsmWG+5QeyE48ypcVT7krQqTU","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":5256},"main":"index.js","type":"module","engines":{"node":">=20.0.0"},"exports":{"import":{"types":"./dist/index.d.ts","default":"./dist/index.js"},"require":{"types":"./dist/index.d.cts","default":"./dist/index.cjs"}},"gitHead":"f3c64d78a82060af66100cc631227a4ef1e33f63","scripts":{"lint":"tsc","test":"pnpm run build && pnpm run test:run","build":"tsup index.ts","test:run":"node --test","test:watch":"node --test --watch","prepublishOnly":"pnpm run build"},"_npmUser":{"name":"atuttle","email":"adam@fusiongrokker.com"},"_npmVersion":"10.5.0","description":"A Higher Order Function that allows runtime overriding of functions, for testing purposes. Based on https://nalanj.dev/posts/mocking-without-loaders/","directories":{},"_nodeVersion":"20.12.2","_hasShrinkwrap":false,"devDependencies":{"tsup":"^8.0.2","typescript":"^5.4.5","@types/node":"^20.12.7"},"_npmOperationalInternal":{"tmp":"tmp/mockable_1.1.4_1716233375804_0.6155767265436229","host":"s3://npm-registry-packages"}},"1.1.5":{"name":"@atcodes/mockable","version":"1.1.5","keywords":["esm","mocking","testing"],"author":{"name":"Adam Tuttle","email":"https://adamtuttle.codes"},"license":"MIT","_id":"@atcodes/mockable@1.1.5","maintainers":[{"name":"atuttle","email":"adam@fusiongrokker.com"}],"dist":{"shasum":"9ae1ece07be6b2a1eab8193561b354e23f403f41","tarball":"https://registry.npmjs.org/@atcodes/mockable/-/mockable-1.1.5.tgz","fileCount":6,"integrity":"sha512-rby5W1364H6gQsLnqrJ2AUau8hB3GZOT8vI1CW55EfyZgflb6ENYf0FXmD0aKvLDvZWGGM3yA4YlN8+OzYW10g==","signatures":[{"sig":"MEYCIQD3hjL/0448iT/Q1OE6PQ5yLD8PGLsBNcSo3y4Sf0yswQIhAMXrDFRbFD1HYvDohSvoSBr3QLTlt2w0JEiDpgpBmIvg","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":5920},"main":"index.js","type":"module","engines":{"node":">=20.0.0"},"exports":{"import":{"types":"./dist/index.d.ts","default":"./dist/index.js"},"require":{"types":"./dist/index.d.cts","default":"./dist/index.cjs"}},"gitHead":"412eea4ca3c74f97fb04ad860b3e7f6618375bc2","scripts":{"lint":"tsc","test":"pnpm run build && pnpm run test:run","build":"tsup index.ts","test:run":"node --test","test:watch":"node --test --watch","prepublishOnly":"pnpm run build"},"_npmUser":{"name":"atuttle","email":"adam@fusiongrokker.com"},"_npmVersion":"10.5.0","description":"A Higher Order Function that allows runtime overriding of functions, for testing purposes. Based on https://nalanj.dev/posts/mocking-without-loaders/","directories":{},"_nodeVersion":"20.17.0","_hasShrinkwrap":false,"devDependencies":{"tsup":"^8.0.2","typescript":"^5.4.5","@types/node":"^20.12.7"},"_npmOperationalInternal":{"tmp":"tmp/mockable_1.1.5_1730816477982_0.6887607267975444","host":"s3://npm-registry-packages"}},"1.1.6":{"name":"@atcodes/mockable","version":"1.1.6","type":"module","description":"A Higher Order Function that allows runtime overriding of functions, for testing purposes. Based on https://nalanj.dev/posts/mocking-without-loaders/","homepage":"https://github.com/atuttle/mockable","main":"index.js","engines":{"node":">=20.0.0"},"exports":{"import":{"types":"./dist/index.d.ts","default":"./dist/index.js"},"require":{"types":"./dist/index.d.cts","default":"./dist/index.cjs"}},"scripts":{"build":"tsup index.ts","lint":"tsc","prepublishOnly":"pnpm run build","test:run":"node --test","test:watch":"node --test --watch","test":"pnpm run build && pnpm run test:run"},"keywords":["esm","mocking","testing"],"author":{"name":"Adam Tuttle","email":"https://adamtuttle.codes"},"license":"MIT","devDependencies":{"@types/node":"^20.12.7","tsup":"^8.0.2","typescript":"^5.4.5"},"_id":"@atcodes/mockable@1.1.6","gitHead":"a64e721c2196b6cbc36a04a373e13efcdb996798","_nodeVersion":"20.17.0","_npmVersion":"10.5.0","dist":{"integrity":"sha512-/PM0bgL23G24jNyCLUBE8lKAdlB/yaHyBpTkCu5iCih1YlSIDZbBc0Yn+/df6Uk6GzT+K1Zo9U/2/V1kju92eQ==","shasum":"f94657e0717d65729468f2944b67e8b179e07a78","tarball":"https://registry.npmjs.org/@atcodes/mockable/-/mockable-1.1.6.tgz","fileCount":6,"unpackedSize":5972,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDSpyR65oaKlrAKChcR4a93Or7MhrQ1d7osivVGvbxEeQIhAMO8hg2jXZEwfcus+/3Ca32ty1VLu0DG2HgSvOLzoS3L"}]},"_npmUser":{"name":"atuttle","email":"adam@fusiongrokker.com"},"directories":{},"maintainers":[{"name":"atuttle","email":"adam@fusiongrokker.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/mockable_1.1.6_1730816784872_0.05077037739890966"},"_hasShrinkwrap":false}},"time":{"created":"2024-04-24T16:29:08.612Z","modified":"2024-11-05T14:26:25.235Z","1.0.0":"2024-04-24T16:29:08.909Z","1.1.0":"2024-04-25T13:28:58.980Z","1.1.1":"2024-04-25T13:34:09.841Z","1.1.2":"2024-04-25T13:43:48.289Z","1.1.3":"2024-04-25T13:53:10.668Z","1.1.4":"2024-05-20T19:29:35.955Z","1.1.5":"2024-11-05T14:21:18.223Z","1.1.6":"2024-11-05T14:26:25.046Z"},"author":{"name":"Adam Tuttle","email":"https://adamtuttle.codes"},"license":"MIT","keywords":["esm","mocking","testing"],"description":"A Higher Order Function that allows runtime overriding of functions, for testing purposes. Based on https://nalanj.dev/posts/mocking-without-loaders/","maintainers":[{"name":"atuttle","email":"adam@fusiongrokker.com"}],"readme":"# Mockable\n\n[![Tests](https://github.com/atuttle/mockable/actions/workflows/pr-tests.yml/badge.svg?branch=main)](https://github.com/atuttle/mockable/actions/workflows/pr-tests.yml)\n\nBased on: https://nalanj.dev/posts/mocking-without-loaders/\n\ntl;dr: it's still too hard/annoying to mock ESM modules. Export mockable-wrapped functions, and your tests can override them as needed, with near-zero overhead in production.\n\n🚨 🚨 **NOTE: Only works on functions.** 🚨 🚨\n\n## Install\n\n```sh\nnpm install @atcodes/mockable\n```\n\n## Usage\n\n### 1A: Export mockable resources\n\nWhen writing your own libraries and utilities, export them as mockable resources:\n\n```js\nimport { mockable } from '@atcodes/mockable';\n\nexport const getDBConnection = mockable(_getDBConnection);\n\nasync function _getDBConnection(){ /* ... */ };\n```\n\n### 1B: Proxy 3rd party libraries as mockable\n\nNeed to mock a 3rd party library that you don't control? Proxy it as a mockable resource:\n\n```js\nimport { doSomethingUseful as doSomethingUseful_ } from 'something-useful';\nimport { mockable } from '@atcodes/mockable';\n\nexport const doSomethingUseful = mockable(doSomethingUseful_);\n```\n\n### 2: Override in tests\n\n```js\nimport { test } from \"node:test\";\nimport { assert } from \"node:assert/strict\";\n\n//the function that we want to mock\nimport { getDBConnection } from \"./get-db.js\";\n\n//the module that we're going to execute and which uses the mocked function\nimport { handleRequest } from \"./handle-request.js\";\n\ntest(\"success\", async (t) => {\n\t// override findUser for this test\n\tgetDBConnection.override(() => {\n\t\treturn {\n\t\t\tquery: (id) => {\n\t\t\t\treturn {\n\t\t\t\t\tid,\n\t\t\t\t\tname: \"Test Tester\",\n\t\t\t\t\temail: \"test@test.com\",\n\t\t\t\t\tcreatedAt: new Date(),\n\t\t\t\t\tupdatedAt: new Date(),\n\t\t\t\t};\n\t\t\t}\n\t\t};\n\t});\n\n\t// clear the override after the test runs\n\tt.after(() => getDBConnection.clear());\n\n\tconst resp = await handleRequest(\"/users/12\");\n\tassert.equal(resp.statusCode, 200);\n});\n```\n\nBonus points: Override with mocks/fakes from a library like [Sinon.js](https://sinonjs.org) to get access to lots of useful tracking on your mock implementations.\n","readmeFilename":"readme.md","homepage":"https://github.com/atuttle/mockable"}