{"id":16366414,"url":"https://github.com/steebchen/flush-cache","last_synced_at":"2025-07-23T13:34:20.994Z","repository":{"id":57239084,"uuid":"78430104","full_name":"steebchen/flush-cache","owner":"steebchen","description":"Flushes the internal node cache, useful when testing apps","archived":false,"fork":false,"pushed_at":"2017-01-09T14:22:48.000Z","size":14,"stargazers_count":3,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-06-21T05:50:51.543Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/steebchen.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-01-09T13:13:37.000Z","updated_at":"2020-05-16T09:02:13.000Z","dependencies_parsed_at":"2022-09-05T08:21:44.876Z","dependency_job_id":null,"html_url":"https://github.com/steebchen/flush-cache","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/steebchen/flush-cache","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/steebchen%2Fflush-cache","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/steebchen%2Fflush-cache/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/steebchen%2Fflush-cache/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/steebchen%2Fflush-cache/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/steebchen","download_url":"https://codeload.github.com/steebchen/flush-cache/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/steebchen%2Fflush-cache/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266689266,"owners_count":23969142,"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","status":"online","status_checked_at":"2025-07-23T02:00:09.312Z","response_time":66,"last_error":null,"robots_txt_status":null,"robots_txt_updated_at":null,"robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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-11T02:46:22.518Z","updated_at":"2025-07-23T13:34:20.948Z","avatar_url":"https://github.com/steebchen.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# flush-cache\nFlushes the internal node cache, useful (and recommended) when testing apps.\n\nThe node cache itself is useful and often needed, but when it comes to test you\ndon't want to cache your modules which you are testing. This forces you to write\nisolated tests, which is a good thing.\n\n## usage\n### install\n\nWe'll install and save flush-cache so we can use it locally for our tests:\n\n```\nnpm i flush-cache --save-dev\n```\n\nor, if you use [yarn](https://yarnpkg.com/):\n\n```\nyarn add flush-cache --dev\n```\n\n### common\n\nRequire flush-cache and invoke the function to clear the whole cache.\n\nsomething.js\n```js\nconsole.log('such logs, much wows!')\n```\n\ntest.js\n```js\nconst flush = require('flush-cache')\n\nrequire('./something') // such logs, much wows!\n\nflush()\n\n// completely uncached \u0026 fresh object here:\nrequire('./something') // such logs, much wows!\n```\n\nflush-cache deletes every require cache object, so when you require modules\nrecursively, their cache gets flushed too.\n\n## examples\n### mocha\n\nYou should add the flush method in a `beforeEach` in a `describe` or in a separate test file when you want to flush the cache in every single `it`.\n\n```js\nconst flush = require('flush-cache')\n\nbeforeEach(flush)\nbeforeEach(function () {\n  this.myObject = require('...')\n})\n\n// or put both methods in a single method\n\nbeforeEach(function () {\n  flush()\n\n  this.myObject = require('...')\n})\n\nit('should test my object', function () {\n  // this.myObject is now a fresh object in every single test case!\n})\n```\n\n### ava\nYou should add the flush method in a `beforeEach`.\n\n```js\nimport test from 'ava'\nimport flush from 'flush-cache'\n\ntest.beforeEach(flush)\ntest.beforeEach(t =\u003e {\n  t.context.myObject = require('...')\n})\n\ntest('first', t =\u003e {\n  // t.context.myObject is now a fresh object in every single test case!\n})\n```\n\n## gotchas\nMost modules expect the `require` command to always be cached, so some modules\nmay break. If you detect modules which break this module, create an issue or a\nPR.\n\nCurrent require caches which are ignored:\n- deasync\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsteebchen%2Fflush-cache","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsteebchen%2Fflush-cache","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsteebchen%2Fflush-cache/lists"}