Skip to content

Commit d6f81a5

Browse files
committed
test: add typing-in-a-large-document perf baseline
1 parent 2c7c6f1 commit d6f81a5

1 file changed

Lines changed: 48 additions & 0 deletions

File tree

packages/editor/tests/performance.test.tsx

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React from 'react'
22
import {describe, expect, test, vi} from 'vitest'
3+
import {userEvent} from 'vitest/browser'
34
import {defineSchema} from '../src'
45
import {InternalEditorEngineRefPlugin} from '../src/plugins/plugin.internal.editor-engine-ref'
56
import {NodePlugin} from '../src/plugins/plugin.node'
@@ -36,6 +37,53 @@ describe('Performance', () => {
3637
console.warn(`Inserted 1000 blocks in ${duration.toFixed(2)}ms`)
3738
})
3839

40+
test('Typing 20 characters in a 1000-block document', async () => {
41+
const {editor, locator} = await createTestEditor()
42+
43+
editor.send({
44+
type: 'insert.blocks',
45+
blocks: Array.from({length: 1000}, (_, i) => ({
46+
_type: 'block',
47+
_key: `b${i}`,
48+
children: [
49+
{_type: 'span', _key: `s${i}`, text: `block ${i}`, marks: []},
50+
],
51+
markDefs: [],
52+
style: 'normal',
53+
})),
54+
placement: 'auto',
55+
})
56+
57+
await vi.waitFor(() => {
58+
expect(editor.getSnapshot().context.value.length).toBe(1000)
59+
60+
expect(locator.getByText('block 999')).toBeInTheDocument()
61+
})
62+
63+
await userEvent.click(locator.getByText('block 500'))
64+
65+
const start = performance.now()
66+
67+
await userEvent.keyboard('performance!!!!!!!!!')
68+
69+
await vi.waitFor(() => {
70+
const children = (
71+
editor.getSnapshot().context.value[500] as {
72+
children?: Array<{text?: string}>
73+
}
74+
).children
75+
expect(
76+
children?.some((child) => child.text?.includes('performance')),
77+
).toBe(true)
78+
})
79+
80+
const duration = performance.now() - start
81+
82+
console.warn(
83+
`Typed 20 characters in a 1000-block document in ${duration.toFixed(2)}ms`,
84+
)
85+
})
86+
3987
test('Inserting 1000 blocks before an existing block', async () => {
4088
const {editor, locator} = await createTestEditor()
4189

0 commit comments

Comments
 (0)