Download this file
| 1 | // Independent browser replay of rule_wire_probe's synthetic incremental updates. |
| 2 | import assert from 'node:assert/strict' |
| 3 | import fs from 'node:fs' |
| 4 | import path from 'node:path' |
| 5 | import * as Y from '../../fixtures/node_modules/yjs/dist/yjs.mjs' |
| 6 | const directory = process.argv[2] |
| 7 | assert.ok(directory, 'usage: node native/scripts/check-rule-wire.mjs OUTPUT_DIRECTORY') |
| 8 | let comparisons = 0 |
| 9 | for (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 | } |
| 26 | console.log(`Rule wire replay passed ${comparisons} incremental/snapshot comparisons and four exact final bodies.`) |
| 27 | |