|
| 1 | +import assert from 'node:assert'; |
| 2 | +import { describe, it } from 'node:test'; |
| 3 | +import { ExportManager } from './exportManager.js'; |
| 4 | +import type { IExporter } from './types.js'; |
| 5 | + |
| 6 | +describe('ExportManager', () => { |
| 7 | + it('refreshes schema cache after the schema exporter loads', async () => { |
| 8 | + let schemaCacheCleared = false; |
| 9 | + let collectionCacheCleared = false; |
| 10 | + |
| 11 | + const schemaExporter: IExporter = { |
| 12 | + name: 'schema', |
| 13 | + load: async () => {}, |
| 14 | + export: async () => {}, |
| 15 | + }; |
| 16 | + |
| 17 | + const collectionExporter: IExporter = { |
| 18 | + name: 'custom_collection', |
| 19 | + load: async () => {}, |
| 20 | + export: async () => {}, |
| 21 | + clearCache: () => { |
| 22 | + collectionCacheCleared = true; |
| 23 | + }, |
| 24 | + }; |
| 25 | + |
| 26 | + const manager = new ExportManager(console as any, () => { |
| 27 | + schemaCacheCleared = true; |
| 28 | + }); |
| 29 | + manager.addExporter({ watch: [], exporter: schemaExporter }); |
| 30 | + manager.addExporter({ watch: [], exporter: collectionExporter }); |
| 31 | + |
| 32 | + await manager.loadAll(); |
| 33 | + |
| 34 | + assert.strictEqual(schemaCacheCleared, true); |
| 35 | + assert.strictEqual(collectionCacheCleared, true); |
| 36 | + }); |
| 37 | + |
| 38 | + it('does not refresh schema cache when loading data only', async () => { |
| 39 | + let schemaCacheCleared = false; |
| 40 | + let collectionCacheCleared = false; |
| 41 | + |
| 42 | + const collectionExporter: IExporter = { |
| 43 | + name: 'custom_collection', |
| 44 | + load: async () => {}, |
| 45 | + export: async () => {}, |
| 46 | + clearCache: () => { |
| 47 | + collectionCacheCleared = true; |
| 48 | + }, |
| 49 | + }; |
| 50 | + |
| 51 | + const manager = new ExportManager(console as any, () => { |
| 52 | + schemaCacheCleared = true; |
| 53 | + }); |
| 54 | + manager.addExporter({ watch: [], exporter: collectionExporter }); |
| 55 | + |
| 56 | + await manager.loadAll(); |
| 57 | + |
| 58 | + assert.strictEqual(schemaCacheCleared, false); |
| 59 | + assert.strictEqual(collectionCacheCleared, false); |
| 60 | + }); |
| 61 | +}); |
0 commit comments