use scheduler and fix tests

Signed-off-by: Emma Indal <emma.indahl@gmail.com>
This commit is contained in:
Emma Indal
2021-04-26 16:43:58 +02:00
parent 0b9eac3a81
commit 9dff1a9839
2 changed files with 14 additions and 6 deletions
+4 -1
View File
@@ -34,7 +34,10 @@ export default async function createPlugin({
collator: new DefaultCatalogCollator(discovery),
});
indexBuilder.build();
const { scheduler } = await indexBuilder.build();
scheduler.start();
useHotCleanup(module, () => scheduler.stop());
return await createRouter({
engine: indexBuilder.getSearchEngine(),
+10 -5
View File
@@ -65,7 +65,8 @@ describe('IndexBuilder', () => {
});
// Build the index and ensure the collator was invoked.
await testIndexBuilder.build();
const { scheduler } = await testIndexBuilder.build();
scheduler.start();
jest.advanceTimersByTime(6000);
expect(collatorSpy).toHaveBeenCalled();
});
@@ -89,7 +90,8 @@ describe('IndexBuilder', () => {
});
// Build the index and ensure the decorator was invoked.
await testIndexBuilder.build();
const { scheduler } = await testIndexBuilder.build();
scheduler.start();
jest.advanceTimersByTime(6000);
// wait for async decorator execution
await Promise.resolve();
@@ -123,7 +125,8 @@ describe('IndexBuilder', () => {
});
// Build the index and ensure the decorator was invoked.
await testIndexBuilder.build();
const { scheduler } = await testIndexBuilder.build();
scheduler.start();
jest.advanceTimersByTime(6000);
// wait for async decorator execution
await Promise.resolve();
@@ -138,7 +141,7 @@ describe('IndexBuilder', () => {
text: 'Test text.',
location: '/test/location',
};
jest
const collatorSpy = jest
.spyOn(testCollator, 'execute')
.mockImplementation(async () => [docFixture]);
const decoratorSpy = jest.spyOn(testDecorator, 'execute');
@@ -157,8 +160,10 @@ describe('IndexBuilder', () => {
});
// Build the index and ensure the decorator was not invoked.
await testIndexBuilder.build();
const { scheduler } = await testIndexBuilder.build();
scheduler.start();
jest.advanceTimersByTime(6000);
expect(collatorSpy).toHaveBeenCalled();
expect(decoratorSpy).not.toHaveBeenCalled();
});
});