oficina / docs Public

Clone
git clone https://amadan.net/oficina/docs

Plain git — no account needed to clone.

Download

Download this file

1// Independent browser replay of rule_wire_probe's synthetic incremental updates.
2import assert from 'node:assert/strict'
3import fs from 'node:fs'
4import path from 'node:path'
5import * as Y from '../../fixtures/node_modules/yjs/dist/yjs.mjs'
6const directory = process.argv[2]
7assert.ok(directory, 'usage: node native/scripts/check-rule-wire.mjs OUTPUT_DIRECTORY')
8let comparisons = 0
9for (const variant of ['retained', 'fresh']) {
10 for (const gc of [true, false]) {
11 const base = path.join(directory, variant)
12 const remote = new Y.Doc({ gc })
13 for (let step = 0; step <= 6; step++) {
14 Y.applyUpdate(remote, fs.readFileSync(path.join(base, step + '.bin')))
15 if (step === 0) continue
16 const snapshot = new Y.Doc({ gc })
17 Y.applyUpdate(snapshot, fs.readFileSync(path.join(base, step + '.snapshot')))
18 assert.equal(remote.getXmlFragment('prosemirror').toString(), snapshot.getXmlFragment('prosemirror').toString(), `${variant}, gc=${gc}, step=${step}`)
19 comparisons++
20 snapshot.destroy()
21 }
22 assert.equal(remote.getXmlFragment('prosemirror').toString(), '<paragraph>- Alpha</paragraph><paragraph>Beta</paragraph>')
23 remote.destroy()
24 }
25}
26console.log(`Rule wire replay passed ${comparisons} incremental/snapshot comparisons and four exact final bodies.`)
27