{"id":13770223,"url":"https://github.com/geek-fun/jest-search","last_synced_at":"2025-12-30T01:16:22.127Z","repository":{"id":179637223,"uuid":"572982239","full_name":"geek-fun/jest-search","owner":"geek-fun","description":"Jest preset for running tests with local ElasticSearch, OpenSearch and ZincSearch.","archived":false,"fork":false,"pushed_at":"2025-04-02T11:15:36.000Z","size":733,"stargazers_count":17,"open_issues_count":6,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-30T04:39:42.889Z","etag":null,"topics":["elasticsearch","elasticsearch-local","es","es-local","integration-test","jest","jest-elasticsearch","jest-environment","jest-opensearch","jest-preset","jest-zincsearch","opensearch","opensearch-local","tdd","tdd-javascript","tdd-typescript","zincsearch","zincsearch-local"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/@geek-fun/jest-search","language":"TypeScript","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/geek-fun.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2022-12-01T12:58:49.000Z","updated_at":"2025-04-02T11:15:38.000Z","dependencies_parsed_at":"2023-07-14T06:45:41.777Z","dependency_job_id":"42e215f0-1412-487a-8f24-150b9de3a1d4","html_url":"https://github.com/geek-fun/jest-search","commit_stats":{"total_commits":81,"total_committers":1,"mean_commits":81.0,"dds":0.0,"last_synced_commit":"d5143b768637acc1f1684768281ca85568aaa9d3"},"previous_names":["geek-fun/jest-search"],"tags_count":22,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/geek-fun%2Fjest-search","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/geek-fun%2Fjest-search/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/geek-fun%2Fjest-search/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/geek-fun%2Fjest-search/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/geek-fun","download_url":"https://codeload.github.com/geek-fun/jest-search/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253509775,"owners_count":21919588,"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":["elasticsearch","elasticsearch-local","es","es-local","integration-test","jest","jest-elasticsearch","jest-environment","jest-opensearch","jest-preset","jest-zincsearch","opensearch","opensearch-local","tdd","tdd-javascript","tdd-typescript","zincsearch","zincsearch-local"],"created_at":"2024-08-03T17:00:35.376Z","updated_at":"2025-12-30T01:16:22.088Z","avatar_url":"https://github.com/geek-fun.png","language":"TypeScript","funding_links":[],"categories":["Packages","TypeScript"],"sub_categories":["Presets"],"readme":"# jest-search\n[![Node.js CI](https://github.com/geek-fun/jest-search/actions/workflows/node.yml/badge.svg)](https://github.com/geek-fun/jest-search/actions/workflows/node.yml)\n[![.github/workflows/release.yml](https://github.com/geek-fun/jest-search/actions/workflows/release.yml/badge.svg)](https://github.com/geek-fun/jest-search/actions/workflows/release.yml)\n[![Known Vulnerabilities](https://snyk.io/test/github/geek-fun/jest-search/badge.svg)](https://snyk.io/test/github/geek-fun/jest-search)\n[![codecov](https://codecov.io/gh/geek-fun/jest-search/branch/master/graph/badge.svg?token=KYTVHHKCI5)](https://codecov.io/gh/geek-fun/jest-search)\n[![npm version](https://badge.fury.io/js/@geek-fun%2Fjest-search.svg)](https://badge.fury.io/js/@geek-fun%2Fjest-search)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n\nJest preset for running tests with local ElasticSearch, OpenSearch and ZincSearch.\n\n## Usage\n**Prerequisite:**\n\nElasticSearch and OpenSearch relies on Java, please make sure you have Java installed and `JAVA_HOME` is set.\n\n`jest-search` provide two ways to set up, one is two set up globally, another is running in specific test only\n\n###  set up globally\n**1. install library** \n\n```bash\nnpm install --save-dev @geek-fun/jest-search\n```\n\n**2. create config file `jest-search-config.js`** \n\n\u003e all configuration items are optional, but it still requires you to `module. exports` the function in `jest-search-config.js`,  there aren't any indexes created without passing the indexes configuration,\n\n```javascript\nmodule.exports = () =\u003e {\n  return {\n    engine: 'elasticsearch', // or 'opensearch' or 'zincsearch'\n    version: '8.8.2',\n    port: 9200,\n    binaryLocation: '', // optional\n    clusterName: 'jest-search-local',\n    nodeName: 'jest-search-local',\n    zincAdmin: 'admin',\n    zincPassword: 'Complexpass#123',\n    indexes: [\n      {\n        name: 'index-name',\n        body: {\n          settings: {\n            number_of_shards: '1',\n            number_of_replicas: '1'\n          },\n          aliases: {\n            'your-alias': {}\n          },\n          mappings: {\n            dynamic: false,\n            properties: {\n              id: {\n                type: 'keyword'\n              }\n            }\n          }\n        }\n      }\n    ]\n  };\n};\n```\n\n- engine: \u003cstring\u003e specify startup search engine platform\n\n  \u003e allowed value: `elasticsearch`, `opensearch`, `zincsearch`\n  \u003e\n  \u003e default: `elasticsearch`\n\n- version:  \u003cstring\u003e specify startup search engine version\n\n  \u003e allowed value: check the versions in each platform's release page\n  \u003e\n  \u003e default: `8.8.2`\n\n- port: \u003cnumber\u003e specify startup search engine port number\n\n  \u003e allowed value: 1024 ~ 2147483647\n  \u003e\n  \u003e default: `9200`\n\n- binaryLocation:\u003cstring\u003e use downloaded  engine instead default: `undefined`\n\n- clusterName:\u003cstring\u003e engine's clusterName default: `jest-search-local`\n\n- nodeName: engine's nodeName default: `jest-search-local`\n\n- indexes: specify the configuration like index name, and mapping of  indexes that you want to create during the startup, and indexes will get deleted once test is finished: default: `[]`\n\n- zincAdmin:\u003cstring\u003e zincsearch requires pass env `ZINC_FIRST_ADMIN_USER` when starting zincsearch, default:  `admin`,\n\n- zincPassword: \u003cstring\u003e :  zincsearch requires pass env `ZINC_FIRST_ADMIN_PASSWORD` when starting zincsearch, default:  `Complexpass#123`\n\n\n\n\n**3. create  `jest-global-setup.js`**\n\n```javascript\nconst { globalSetup } = require('@geek-fun/jest-search');\nmodule.exports = async () =\u003e {\n  await Promise.all([globalSetup()]);\n};\n```\n\n\n\n**4. create  `jest-global-teardown.js`**\n\n```javascript\nconst { globalTeardown } = require('@geek-fun/jest-search');\nmodule.exports = async () =\u003e {\n  await Promise.all([globalTeardown()]);\n};\n```\n\n\n\n**4. modify the `jest-config.js`**\n\n```javascript\nmodule.exports = {\n\t...\n  globalSetup: '\u003crootDir\u003e/jest-global-setup.js',\n  globalTeardown: '\u003crootDir\u003e/jest-global-teardown.js',\n};\n```\n\n**3. play with your tests**\n\n```typescript\n// tests/utils/helper.ts sample utils to add item for test\nexport const saveBook = async (bookDoc: { name: string; author: string }) =\u003e {\n  await esClient.index({ index, body: bookDoc, refresh: true });\n};\n\n// tests/book.test.ts sample test\nbeforeAll(async () =\u003e {\n  await saveBook(mockBook);\n});\n```\n### specific test only\nthe step 1 and 2 are the same as above, `jest-search` export two methods `startEngine` and `stopEngine` to start and stop the search engine, you can manually call them in your test file, the `startEngine` accepts same argument object as defined in `jest-search-config.js` file\n```typescript\nimport { startEngine, stopEngine } from '@geek-fun/jest-search';\n// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n// @ts-ignore\nimport loadConfig from '../jest-search-config.js';\n\n\ndescribe('integration test for elasticsearch', () =\u003e {\n  beforeAll(async () =\u003e {\n    await startEngine(loadConfig());\n    await saveBook(mockBook);\n  });\n  afterAll(async () =\u003e {\n    await stopEngine();\n  });\n  it('should get book when search with valid book name', async () =\u003e {\n    // ...\n  });\n});\n\n```\n\n### Known issues\n\n1. Windows is not on the support list yet, I didn't see the necessity of it yet, feel free to reach out if you have the needs to use it on Windows, then will prioritize it\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgeek-fun%2Fjest-search","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgeek-fun%2Fjest-search","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgeek-fun%2Fjest-search/lists"}