test: clean initial test state

This commit is contained in:
Eric Maciel 2021-03-03 12:53:03 -05:00
parent f985772afc
commit 513770336a
3 changed files with 24 additions and 15 deletions

View File

@ -254,9 +254,7 @@ export default class AutomergeCollaboration {
opCount: collabActions.length
}
if (collabActions.length > 10) {
console.log(JSON.stringify(data.payload.changes, null, 2))
}
console.log(JSON.stringify(data.payload, null, 2))
this.onTrace(metaData, () => {
switch (data.type) {

View File

@ -1,12 +1,14 @@
import AutomergeBackend from '../AutomergeBackend'
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
// for this docId.
// @ts-ignore
const activeConnectionsCount = backend.documentSetMap[docId]?.handlers.size
return activeConnectionsCount
return automergeDocument.handlers.size
}
export default getActiveConnections

View File

@ -278,7 +278,7 @@ describe('automerge editor client tests', () => {
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 editor2 = await createCollabEditor()
@ -288,17 +288,20 @@ describe('automerge editor client tests', () => {
return getActiveConnections(collabBackend.backend, docId) === 1
})
editor2.insertNode({ type: 'paragraph', children: [{ text: 'hi' }] })
await waitForCondition(() => {
return collabBackend.backend.getDocument(docId)?.children.length === 2
})
// editor2.insertNode({ type: 'paragraph', children: [{ text: 'hi' }] })
// await waitForCondition(() => {
// return collabBackend.backend.getDocument(docId)?.children.length === 1
// })
editor1.connect()
await waitForCondition(() => {
return editor1.children.length === 2
})
await waitForCondition(
() => getActiveConnections(collabBackend.backend, docId) === 2
)
// await waitForCondition(() => {
// return editor1.children.length === 1
// })
editor2.destroy()
@ -306,7 +309,13 @@ describe('automerge editor client tests', () => {
return getActiveConnections(collabBackend.backend, docId) === 1
})
console.log('destroying last editor')
editor1.destroy()
await waitForCondition(() => {
return getActiveConnections(collabBackend.backend, docId) === 0
})
})
afterAll(() => {