Skip to content

Commit

Permalink
adds reproduction test
Browse files Browse the repository at this point in the history
  • Loading branch information
janthurau committed Jun 13, 2024
1 parent 70ef611 commit e0a6ea8
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions tests/server/openDirectConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,3 +218,49 @@ test('direct connection transact awaits until onStoreDocument has finished, even
resolve('done')
})
})

test('creating a websocket connection after transact but before debounce interval doesnt create different docs', async t => {
let onStoreDocumentFinished = false
let disconnected = false

await new Promise(async resolve => {
const server = await newHocuspocus({
onStoreDocument: async () => {
onStoreDocumentFinished = false
await sleep(200)
onStoreDocumentFinished = true
},
async afterUnloadDocument(data) {
console.log('called')
if (disconnected) {
t.fail('must not be called')
}
},
})

const direct = await server.openDirectConnection('hocuspocus-test')
t.is(server.getDocumentsCount(), 1)
t.is(server.getConnectionsCount(), 1)

t.is(onStoreDocumentFinished, false)
await direct.transact(document => {
document.transact(() => {
document.getArray('test').insert(0, ['value'])
}, 'testOrigin')
})
t.is(onStoreDocumentFinished, true)

await direct.disconnect()
disconnected = true

t.is(server.getConnectionsCount(), 0)
t.is(server.getDocumentsCount(), 0)
t.is(onStoreDocumentFinished, true)

const provider = newHocuspocusProvider(server)

await sleep(server.configuration.debounce * 2)

resolve('done')
})
})

0 comments on commit e0a6ea8

Please sign in to comment.