{"id":23720931,"url":"https://github.com/elonsalfati/jest-redis","last_synced_at":"2025-06-16T14:05:10.291Z","repository":{"id":57280435,"uuid":"430062883","full_name":"elonsalfati/jest-redis","owner":"elonsalfati","description":"Jest preset for Redis in-memory server","archived":false,"fork":false,"pushed_at":"2021-11-20T12:02:30.000Z","size":58,"stargazers_count":6,"open_issues_count":1,"forks_count":1,"subscribers_count":4,"default_branch":"main","last_synced_at":"2024-11-29T19:18:28.395Z","etag":null,"topics":["jest","jest-preset","jest-redis","redis"],"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/elonsalfati.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":["elonsalfati"]}},"created_at":"2021-11-20T09:41:03.000Z","updated_at":"2022-06-05T18:37:27.000Z","dependencies_parsed_at":"2022-09-19T17:21:09.684Z","dependency_job_id":null,"html_url":"https://github.com/elonsalfati/jest-redis","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elonsalfati%2Fjest-redis","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elonsalfati%2Fjest-redis/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elonsalfati%2Fjest-redis/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elonsalfati%2Fjest-redis/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/elonsalfati","download_url":"https://codeload.github.com/elonsalfati/jest-redis/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":231888982,"owners_count":18441362,"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":["jest","jest-preset","jest-redis","redis"],"created_at":"2024-12-30T22:15:42.867Z","updated_at":"2024-12-30T22:15:43.555Z","avatar_url":"https://github.com/elonsalfati.png","language":"JavaScript","funding_links":["https://github.com/sponsors/elonsalfati"],"categories":[],"sub_categories":[],"readme":"# jest-redis\nJest preset for Redis in-memory server\n\n# Usage\n## 1. Install\n```sh-session\n$ yarn add redis-memory-server jest-redis --dev\n```\n\n## 2. Create a `jest.config.js` file\n```javascript\nmodule.exports = {\n\tpreset: 'jest-redis',\n}\n```\n\n## 3. Customizing Redis Server, create a `jest-redis.config.js`\nSee [redis-memory-server](https://github.com/mhassan1/redis-memory-server#available-options-for-redismemoryserver) to learn more about the optional configuraitons.\n\n```javascript\nmodule.exports = {\n\tredisMemoryServerOptions: {\n\t\tinstance: {\n\t\t\tport: number, // by default, choose any free port\n\t\t\tip: string, // by default, '127.0.0.1'; for binding to all IP addresses set it to `::,0.0.0.0`,\n\t\t\targs: [], // by default, no additional arguments; any additional command line arguments for `redis-server`\n\t\t},\n\t\tbinary: {\n\t\t\tversion: string, // by default, 'stable'\n\t\t\tdownloadDir: string, // by default, 'node_modules/.cache/redis-memory-server/redis-binaries'\n\t\t\tsystemBinary: string, // by default, undefined\n\t\t},\n\t\tautoStart: boolean, // by default, true\n\t},\n\tuseSharedDBForAllJestWorkers: boolean, // enables seperated database for each test worker. This disables the exported environment variable.\n\tredisURLEnvName: string, // the exported environment variable name\n}\n```\n\n## 4. Configure Redis Client\nThis library sets the `process.env[options.redisURLEnvName]` (by default `process.env.REDIS_URL`) for your convenience. However, it's preferable to use `global.__REDIS_URL__` as is works with `useSharedDBForAllJestWorkers`.\n\n```javascript\nconst Redis = require('ioredis')\n\ndescribe('set', () =\u003e {\n\tlet client\n\n\tbeforeAll(async () =\u003e {\n\t\tclient = new Redis(global.__REDIS_URL__)\n\t\tawait client.connect()\n\t})\n\n\tafterAll(async () =\u003e {\n\t\tawait client.disconnect()\n\t})\n})\n```\n\n### Jest watch mode\nThis package creates the file `redisGlobals.json` in the project root when using jest `--watch` flag. Changes to this file can cause issues.\nIn order to avoid unwanted behaviour, add the `redisGlobals.json` to your ignore files and in `jest.config.js`, add:\n\n```javascript\n// jest.config.js\nmodule.exports = {\n\twatchPathIgnorePatterns: ['redisGlobals']\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felonsalfati%2Fjest-redis","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Felonsalfati%2Fjest-redis","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felonsalfati%2Fjest-redis/lists"}