1
0
mirror of https://github.com/verdaccio/verdaccio.git synced 2024-11-13 03:35:52 +01:00
verdaccio/packages/search/test/index.spec.ts
Juan Picado 35cc57b79e
fix: local search keyword undefined errors (#3992)
* fix: local search keyword undefined errors

* Update indexer.ts
2023-08-26 15:24:00 +02:00

48 lines
1.1 KiB
TypeScript

import { expect, test } from 'vitest';
import { Logger } from '@verdaccio/types';
import { SearchMemoryIndexer } from '../src';
class MockStore {
getLocalDatabase(cb) {
return cb(null, [
{
name: 'verdaccio-search',
version: '1.0.0',
readme: 'foo',
description: 'foo',
keywords: ['foo', 'bar'],
},
{
name: 'verdaccio-utils',
version: '2.0.0',
readme: 'foo',
description: 'foo',
keywords: 'some',
},
]);
}
}
const logger = {
// eslint-disable-next-line no-console
error: (...arg) => console.error(...arg),
} as Logger;
test('should search', async () => {
const store = new MockStore();
SearchMemoryIndexer.configureStorage(store);
await SearchMemoryIndexer.init(logger);
// @ts-expect-error
await SearchMemoryIndexer.add({
name: 'verdaccio',
version: '2.0.0',
readme: 'foo',
description: '',
});
const query = await SearchMemoryIndexer.query('verdaccio');
expect(query.hits.map((item) => item.id)).toEqual(['verdaccio', 'verdaccio-utils']);
});