mirror of
https://github.com/cudr/slate-collaborative.git
synced 2024-10-27 20:34:06 +00:00
test: clean initial test state
This commit is contained in:
parent
f985772afc
commit
513770336a
@ -254,9 +254,7 @@ export default class AutomergeCollaboration {
|
|||||||
opCount: collabActions.length
|
opCount: collabActions.length
|
||||||
}
|
}
|
||||||
|
|
||||||
if (collabActions.length > 10) {
|
console.log(JSON.stringify(data.payload, null, 2))
|
||||||
console.log(JSON.stringify(data.payload.changes, null, 2))
|
|
||||||
}
|
|
||||||
|
|
||||||
this.onTrace(metaData, () => {
|
this.onTrace(metaData, () => {
|
||||||
switch (data.type) {
|
switch (data.type) {
|
||||||
|
@ -1,12 +1,14 @@
|
|||||||
import AutomergeBackend from '../AutomergeBackend'
|
import AutomergeBackend from '../AutomergeBackend'
|
||||||
|
|
||||||
const getActiveConnections = (backend: AutomergeBackend, docId: string) => {
|
const getActiveConnections = (backend: AutomergeBackend, docId: string) => {
|
||||||
|
const automergeDocument = backend.documentSetMap[docId]
|
||||||
|
|
||||||
|
if (!automergeDocument) return 0
|
||||||
|
|
||||||
// This is the only way to synchronously check the number of active Automerge.Connections
|
// This is the only way to synchronously check the number of active Automerge.Connections
|
||||||
// for this docId.
|
// for this docId.
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
const activeConnectionsCount = backend.documentSetMap[docId]?.handlers.size
|
return automergeDocument.handlers.size
|
||||||
|
|
||||||
return activeConnectionsCount
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default getActiveConnections
|
export default getActiveConnections
|
||||||
|
@ -278,7 +278,7 @@ describe('automerge editor client tests', () => {
|
|||||||
expect(target).toEqual(null)
|
expect(target).toEqual(null)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should work with concurrent insert text operations', async () => {
|
it.only('should work with concurrent insert text operations', async () => {
|
||||||
const editor1 = await createCollabEditor()
|
const editor1 = await createCollabEditor()
|
||||||
const editor2 = await createCollabEditor()
|
const editor2 = await createCollabEditor()
|
||||||
|
|
||||||
@ -288,17 +288,20 @@ describe('automerge editor client tests', () => {
|
|||||||
return getActiveConnections(collabBackend.backend, docId) === 1
|
return getActiveConnections(collabBackend.backend, docId) === 1
|
||||||
})
|
})
|
||||||
|
|
||||||
editor2.insertNode({ type: 'paragraph', children: [{ text: 'hi' }] })
|
// editor2.insertNode({ type: 'paragraph', children: [{ text: 'hi' }] })
|
||||||
|
// await waitForCondition(() => {
|
||||||
await waitForCondition(() => {
|
// return collabBackend.backend.getDocument(docId)?.children.length === 1
|
||||||
return collabBackend.backend.getDocument(docId)?.children.length === 2
|
// })
|
||||||
})
|
|
||||||
|
|
||||||
editor1.connect()
|
editor1.connect()
|
||||||
|
|
||||||
await waitForCondition(() => {
|
await waitForCondition(
|
||||||
return editor1.children.length === 2
|
() => getActiveConnections(collabBackend.backend, docId) === 2
|
||||||
})
|
)
|
||||||
|
|
||||||
|
// await waitForCondition(() => {
|
||||||
|
// return editor1.children.length === 1
|
||||||
|
// })
|
||||||
|
|
||||||
editor2.destroy()
|
editor2.destroy()
|
||||||
|
|
||||||
@ -306,7 +309,13 @@ describe('automerge editor client tests', () => {
|
|||||||
return getActiveConnections(collabBackend.backend, docId) === 1
|
return getActiveConnections(collabBackend.backend, docId) === 1
|
||||||
})
|
})
|
||||||
|
|
||||||
|
console.log('destroying last editor')
|
||||||
|
|
||||||
editor1.destroy()
|
editor1.destroy()
|
||||||
|
|
||||||
|
await waitForCondition(() => {
|
||||||
|
return getActiveConnections(collabBackend.backend, docId) === 0
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
afterAll(() => {
|
afterAll(() => {
|
||||||
|
Loading…
Reference in New Issue
Block a user