snapshot of https://github.com/ueberdosis/hocuspocus.git @ cf3cfa355b4d3bb61c6b6c80071f71783e32470e (2026-09-15)
Some checks failed
build / lint (22) (push) Failing after 17s
build / test (22) (push) Failing after 8s
build / lint (23) (push) Failing after 2s
build / build (22) (push) Has been skipped
build / build (23) (push) Has been skipped
build / test (23) (push) Failing after 4s
docsearch / docsearch (push) Failing after 1s
Some checks failed
build / lint (22) (push) Failing after 17s
build / test (22) (push) Failing after 8s
build / lint (23) (push) Failing after 2s
build / build (22) (push) Has been skipped
build / build (23) (push) Has been skipped
build / test (23) (push) Failing after 4s
docsearch / docsearch (push) Failing after 1s
This commit is contained in:
82
tests/provider/observeDeep.ts
Normal file
82
tests/provider/observeDeep.ts
Normal file
@@ -0,0 +1,82 @@
|
||||
import test from 'ava'
|
||||
import * as Y from 'yjs'
|
||||
import { newHocuspocus, newHocuspocusProvider } from '../utils/index.ts'
|
||||
import { retryableAssertion } from '../utils/retryableAssertion.ts'
|
||||
|
||||
test('observeDeep is called just once', async t => {
|
||||
let count = 0
|
||||
|
||||
const server = await newHocuspocus(t)
|
||||
const provider = newHocuspocusProvider(t, server)
|
||||
|
||||
const type = provider.document.get(
|
||||
'xmlText',
|
||||
Y.XmlText,
|
||||
) as unknown as Y.XmlText
|
||||
|
||||
// Count how often observeDeep is called …
|
||||
type.observeDeep((events, transaction) => {
|
||||
count += 1
|
||||
})
|
||||
|
||||
// Insert something …
|
||||
type.insert(1, 'a')
|
||||
|
||||
await retryableAssertion(t, tt => {
|
||||
tt.is(count, 1)
|
||||
})
|
||||
})
|
||||
|
||||
test('observeDeep is called for every single change', async t => {
|
||||
let count = 0
|
||||
|
||||
const server = await newHocuspocus(t)
|
||||
const provider = newHocuspocusProvider(t, server)
|
||||
|
||||
const type = provider.document.get(
|
||||
'xmlText',
|
||||
Y.XmlText,
|
||||
) as unknown as Y.XmlText
|
||||
|
||||
// Count how often observeDeep is called …
|
||||
type.observeDeep((events, transaction) => {
|
||||
count += 1
|
||||
})
|
||||
|
||||
// Insert something …
|
||||
type.insert(1, 'a')
|
||||
type.insert(2, 'b')
|
||||
type.insert(3, 'c')
|
||||
|
||||
await retryableAssertion(t, tt => {
|
||||
tt.is(count, 3)
|
||||
})
|
||||
})
|
||||
|
||||
test('observeDeep is called once for a single transaction', async t => {
|
||||
let count = 0
|
||||
|
||||
const server = await newHocuspocus(t)
|
||||
const provider = newHocuspocusProvider(t, server)
|
||||
|
||||
const type = provider.document.get(
|
||||
'xmlText',
|
||||
Y.XmlText,
|
||||
) as unknown as Y.XmlText
|
||||
|
||||
// Count how often observeDeep is called …
|
||||
type.observeDeep((events, transaction) => {
|
||||
count += 1
|
||||
})
|
||||
|
||||
// Insert something …
|
||||
Y.transact(provider.document, () => {
|
||||
type.insert(1, 'a')
|
||||
type.insert(2, 'b')
|
||||
type.insert(3, 'c')
|
||||
})
|
||||
|
||||
await retryableAssertion(t, tt => {
|
||||
tt.is(count, 1)
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user