Package Exports
- @geek-fun/jest-search
- @geek-fun/jest-search/dist/src/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@geek-fun/jest-search) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
jest-search
Jest preset for running tests with local ElasticSearch, OpenSearch and ZincSearch.
Usage
Prerequisite:
ElasticSearch and OpenSearch relies on Java, please make sure you have Java installed and JAVA_HOME
is set.
1. install library
npm install --save-dev @geek-fun/jest-search
2. create config file jest-search-config.js
module.exports = () => {
return {
engine: 'elasticsearch', // or 'opensearch' or 'zincsearch'
version: '8.8.2',
port: 9200,
binaryLocation: '', // optional
clusterName: 'jest-search-local',
nodeName: 'jest-search-local',
indexes: [
{
name: 'index-name',
body: {
settings: {
number_of_shards: '1',
number_of_replicas: '1'
},
aliases: {
'your-alias': {}
},
mappings: {
dynamic: false,
properties: {
id: {
type: 'keyword'
}
}
}
}
}
]
};
};
3. modify the jest-config.js
module.exports = {
preset: '@geek-fun/jest-search',
};
3. play with your test
// tests/utils/helper.ts sample utils to add item for test
export const saveBook = async (bookDoc: { name: string; author: string }) => {
await esClient.index({ index, body: bookDoc, refresh: true });
};
// tests/book.test.ts sample test
beforeAll(async () => {
await saveBook(mockBook);
});