{"id":16834578,"url":"https://github.com/gobwas/cuculus","last_synced_at":"2025-03-18T02:23:43.214Z","repository":{"id":35089736,"uuid":"39248442","full_name":"gobwas/cuculus","owner":"gobwas","description":"Simplest require mocking","archived":false,"fork":false,"pushed_at":"2015-10-06T15:15:36.000Z","size":136,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-25T16:15:32.834Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gobwas.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-07-17T10:16:25.000Z","updated_at":"2015-07-17T10:17:29.000Z","dependencies_parsed_at":"2022-08-18T05:15:25.514Z","dependency_job_id":null,"html_url":"https://github.com/gobwas/cuculus","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gobwas%2Fcuculus","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gobwas%2Fcuculus/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gobwas%2Fcuculus/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gobwas%2Fcuculus/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gobwas","download_url":"https://codeload.github.com/gobwas/cuculus/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244142042,"owners_count":20404929,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-13T12:06:56.714Z","updated_at":"2025-03-18T02:23:43.192Z","avatar_url":"https://github.com/gobwas.png","language":"JavaScript","readme":"#  [![NPM version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Dependency Status][daviddm-image]][daviddm-url]\n\n\u003e Simplest require mocking\n\n## Whats up\n\nHey there!\n\nThis is a simple module mocking tool for your super clever unit testing.\n\n## Install\n\n```sh\n$ npm install --save-dev cuculus\n```\n\n\n## Usage\n\nThe simple case:\n\n```js\n    var cuculus = require(\"cuculus\");\n\n    cuculus.replace(\"fs\", {\n        writeFile: function(path, contents) {\n            // ...\n        }\n    });\n\n    // now fs is your object\n\n    cuculus.restore(\"fs\");\n\n    // now fs is original\n```\n\nOr:\n\n```js\n    var cuculus = require(\"cuculus\"),\n        restorer;\n\n    restorer = cuculus.replace(\"fs\", {\n        writeFile: function(path, contents) {\n            // ...\n        }\n    });\n\n    // now fs is your object\n\n    restorer();\n\n    // now fs is original\n```\n\nComplete case:\n\n```js\nvar cuculus = require(\"cuculus\");\n// mocking library\n// feel free to use your favorite\nvar sinon = require(\"sinon\");\n\ncuculus.modify(\"fs\", function(fs, onRestore) {\n    var stub;\n\n    stub = sinon.stub(fs, \"writeFile\", function(path, contents) {\n        // your actions here\n    });\n\n    // register restore middleware\n    onRestore(stub.restore.bind(stub));\n\n    return fs;\n});\n\n// your tests here\n\n// and after all, or, between each test\ncuculus.restore(\"fs\");\n\n// now fs is native and without stubs\n```\n\n## API\n\n##### cuculus.replace(name: string, stub: Any) : Function()\n\nComplete replace the module named `name` with `stub`. Returns function, that\nsimple proxy to `cuculus.restore(name)`.\n\n##### cuculus.modify(name: string, replacer: Function(current: Any, onRestore: Function(fn: Function))) : Function()\n\nModifies current module with `replacer` function. If `replacer` modifies object, then `restore`\nmethod will not restore the changes, until you not register the backupers with `onRestore` function.\n\n##### cuculus.restore(name: string[, steps: number])\n\nRestores module `name`. If it was modified multiple times, restores to the root, until the `steps` limit is not given.\n\n##### cuculus.drop(name: string)\n\nDrops the cached module from `require`. `name` should be a module name or a full path to the js file.\n\n## License\n\nMIT © [Sergey Kamardin](https://github.com/gobwas)\n\n\n[npm-image]: https://badge.fury.io/js/cuculus.svg\n[npm-url]: https://npmjs.org/package/cuculus\n[travis-image]: https://travis-ci.org/gobwas/cuculus.svg?branch=master\n[travis-url]: https://travis-ci.org/gobwas/cuculus\n[daviddm-image]: https://david-dm.org/gobwas/cuculus.svg?theme=shields.io\n[daviddm-url]: https://david-dm.org/gobwas/cuculus\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgobwas%2Fcuculus","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgobwas%2Fcuculus","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgobwas%2Fcuculus/lists"}