fix(workspace): should avoid sending providers' update back (#3384)

This commit is contained in:
liuyi
2023-07-26 17:47:24 +08:00
committed by GitHub
parent 2c249781a2
commit 6bafa83cef
4 changed files with 33 additions and 11 deletions
@@ -1,6 +1,6 @@
import { setTimeout } from 'node:timers/promises';
import { describe, expect, test } from 'vitest';
import { describe, expect, test, vi } from 'vitest';
import { applyUpdate, Doc, encodeStateAsUpdate } from 'yjs';
import { createLazyProvider } from '../lazy-provider';
@@ -178,4 +178,19 @@ describe('y-provider', () => {
expect(provider.connected).toBe(false);
});
test('should not send remote update back', async () => {
const remoteRootDoc = new Doc(); // this is the remote doc lives in remote
const datasource = createMemoryDatasource(remoteRootDoc);
const spy = vi.spyOn(datasource, 'sendDocUpdate');
const rootDoc = new Doc({ guid: remoteRootDoc.guid }); // this is the doc that we want to sync
const provider = createLazyProvider(rootDoc, datasource);
provider.connect();
remoteRootDoc.getText('text').insert(0, 'test-value');
expect(spy).not.toBeCalled();
});
});