Download this file
| 1 | // Generates the documents the suite conformance test seeds Docs with |
| 2 | // (internal/docs/suite_test.go): one real Yjs update per case of the suite |
| 3 | // contract's custody fixture, a single paragraph holding that case's |
| 4 | // s3_body, on the "prosemirror" root Store.Text reads. Run from fixtures/ |
| 5 | // with the fixture's path: |
| 6 | // |
| 7 | // node generate-suite.mjs "$(go list -m -f '{{.Dir}}' amadan.net/oficina/suite)/fixtures/custody.json" |
| 8 | // |
| 9 | // The client id is pinned so the bytes are reproducible, as in |
| 10 | // generate-fragment.mjs. A fixture whose text changes needs this rerun; the |
| 11 | // conformance test fails on the body until it is. |
| 12 | import * as Y from 'yjs' |
| 13 | import { writeFileSync, mkdirSync, readFileSync } from 'node:fs' |
| 14 | |
| 15 | const path = process.argv[2] |
| 16 | if (!path) { |
| 17 | console.error('usage: node generate-suite.mjs <custody.json>') |
| 18 | process.exit(2) |
| 19 | } |
| 20 | const fixture = JSON.parse(readFileSync(path, 'utf8')) |
| 21 | mkdirSync('vectors/suite', { recursive: true }) |
| 22 | for (const c of fixture.cases) { |
| 23 | if (!c.s3_body) continue |
| 24 | const doc = new Y.Doc() |
| 25 | doc.clientID = 1 |
| 26 | const p = new Y.XmlElement('paragraph') |
| 27 | const t = new Y.XmlText() |
| 28 | t.insert(0, c.s3_body) |
| 29 | p.insert(0, [t]) |
| 30 | doc.getXmlFragment('prosemirror').insert(0, [p]) |
| 31 | writeFileSync(`vectors/suite/${c.item_id}.update.bin`, Y.encodeStateAsUpdate(doc)) |
| 32 | } |
| 33 | |