From 922ab92e8d3be7ea1ba9033fda96778380c5fd5f Mon Sep 17 00:00:00 2001 From: Hans Pagel Date: Fri, 7 Jan 2022 17:46:43 +0100 Subject: [PATCH] fix tests --- packages/server/src/Hocuspocus.ts | 1 - tests/extension-redis/onStoreDocument.js | 21 ++++++++++++++------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/packages/server/src/Hocuspocus.ts b/packages/server/src/Hocuspocus.ts index b5f02d7ee..333d0514a 100644 --- a/packages/server/src/Hocuspocus.ts +++ b/packages/server/src/Hocuspocus.ts @@ -520,7 +520,6 @@ export class Hocuspocus { */ private async createDocument(documentName: string, request: IncomingMessage, socketId: string, connection: ConnectionConfiguration, context?: any): Promise { if (this.documents.has(documentName)) { - console.log(`${this.configuration.name} Got ${documentName} already! No need to subscribe?`) const document = this.documents.get(documentName) return document } diff --git a/tests/extension-redis/onStoreDocument.js b/tests/extension-redis/onStoreDocument.js index 6f50e43bb..6dd91d7e4 100644 --- a/tests/extension-redis/onStoreDocument.js +++ b/tests/extension-redis/onStoreDocument.js @@ -24,33 +24,38 @@ context('extension-redis/onStoreDocument', () => { const ydoc = new Y.Doc() const anotherYdoc = new Y.Doc() - const onStoreDocument = async ({ document }) => { - assert.strictEqual(document.getArray('foo').get(0), anotherYdoc.getArray('foo').get(0)) - assert.strictEqual(document.getArray('foo').get(0), ydoc.getArray('foo').get(0)) - done() + class CustomStorageExtension { + async onStoreDocument({ document, instance }) { + console.log(`${instance.configuration.name} onStoreDocument`) + assert.strictEqual(document.getArray('foo').get(0), anotherYdoc.getArray('foo').get(0)) + assert.strictEqual(document.getArray('foo').get(0), ydoc.getArray('foo').get(0)) + done() + } } server.configure({ port: 4000, - onStoreDocument, + name: 'redis-1', extensions: [ new Redis({ ...redisConfiguration, identifier: 'server', prefix: 'extension-redis/onStoreDocument', }), + new CustomStorageExtension(), ], }).listen() anotherServer.configure({ port: 4001, - onStoreDocument, + name: 'redis-2', extensions: [ new Redis({ ...redisConfiguration, identifier: 'anotherServer', prefix: 'extension-redis/onStoreDocument', }), + new CustomStorageExtension(), ], }).listen() @@ -74,7 +79,9 @@ context('extension-redis/onStoreDocument', () => { // once we're setup make an edit on anotherClient, if all succeeds the onStoreDocument // callback will be called after the debounce period and all docs will // be identical - anotherYdoc.getArray('foo').insert(0, ['bar']) + // anotherYdoc.getArray('foo').insert(0, ['bar']) + client.destroy() + anotherClient.destroy() }, }) })