Co-authored-by: Serhii Dziupin <serkraser@gmail.com> Co-authored-by: Alan Chen <2144783+alanzchen@users.noreply.github.com>
39 lines
1.1 KiB
TypeScript
39 lines
1.1 KiB
TypeScript
import { describe, expect, test } from 'bun:test';
|
|
|
|
import {
|
|
notifyFileContentInvalidated,
|
|
subscribeToFileContentInvalidation,
|
|
} from './fileContentInvalidation';
|
|
|
|
describe('fileContentInvalidation', () => {
|
|
test('publishes normalized paths within the captured runtime', () => {
|
|
const received: Array<{ runtimeKey: string; paths: readonly string[] }> = [];
|
|
const unsubscribe = subscribeToFileContentInvalidation((invalidation) => {
|
|
received.push(invalidation);
|
|
});
|
|
|
|
notifyFileContentInvalidated({
|
|
runtimeKey: ' runtime-a ',
|
|
paths: [' /repo/a.txt ', '/repo/a.txt', '', '/repo/b.txt'],
|
|
});
|
|
unsubscribe();
|
|
|
|
expect(received).toEqual([{
|
|
runtimeKey: 'runtime-a',
|
|
paths: ['/repo/a.txt', '/repo/b.txt'],
|
|
}]);
|
|
});
|
|
|
|
test('stops publishing after unsubscribe', () => {
|
|
let calls = 0;
|
|
const unsubscribe = subscribeToFileContentInvalidation(() => {
|
|
calls += 1;
|
|
});
|
|
unsubscribe();
|
|
|
|
notifyFileContentInvalidated({ runtimeKey: 'runtime-a', paths: ['/repo/a.txt'] });
|
|
|
|
expect(calls).toBe(0);
|
|
});
|
|
});
|