Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hanspagel committed Jan 7, 2022
1 parent 279a2f2 commit 922ab92
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
1 change: 0 additions & 1 deletion packages/server/src/Hocuspocus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,6 @@ export class Hocuspocus {
*/
private async createDocument(documentName: string, request: IncomingMessage, socketId: string, connection: ConnectionConfiguration, context?: any): Promise<Document> {
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
}
Expand Down
21 changes: 14 additions & 7 deletions tests/extension-redis/onStoreDocument.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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()
},
})
})
Expand Down

0 comments on commit 922ab92

Please sign in to comment.