Skip to content

Commit b60c673

Browse files
committed
feat: fix more tests
1 parent b123a45 commit b60c673

File tree

2 files changed

+39
-40
lines changed

2 files changed

+39
-40
lines changed

y-octo-node/tests/yjs/testHelper.ts

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as t from "lib0/testing";
1+
import assert, { deepEqual } from "node:assert";
22
import * as prng from "lib0/prng";
33
import * as encoding from "lib0/encoding";
44
import * as decoding from "lib0/decoding";
@@ -75,14 +75,14 @@ export class TestYOctoInstance extends Y.Doc {
7575
testConnector.allConns.add(this);
7676
this.updates = [];
7777
// set up observe on local model
78-
this.onUpdate((update) => {
79-
if (origin !== testConnector) {
80-
const encoder = encoding.createEncoder();
81-
syncProtocol.writeUpdate(encoder, update);
82-
broadcastMessage(this, encoding.toUint8Array(encoder));
83-
}
84-
this.updates.push(update);
85-
});
78+
// this.onUpdate((update) => {
79+
// // if (origin !== testConnector) {
80+
// // const encoder = encoding.createEncoder();
81+
// // syncProtocol.writeUpdate(encoder, update);
82+
// // broadcastMessage(this, encoding.toUint8Array(encoder));
83+
// // }
84+
// this.updates.push(update);
85+
// });
8686
this.connect();
8787
}
8888

@@ -154,6 +154,7 @@ export class TestConnector {
154154
* If this function was unable to flush a message, because there are no more messages to flush, it returns false. true otherwise.
155155
*/
156156
flushRandomMessage(): boolean {
157+
return false;
157158
const gen = this.prng;
158159
const conns = Array.from(this.onlineConns).filter(
159160
(conn) => conn.receiving.size > 0,
@@ -201,13 +202,11 @@ export class TestConnector {
201202
}
202203

203204
reconnectAll() {
204-
this.allConns.forEach((conn: { connect: () => any }) => conn.connect());
205+
this.allConns.forEach((conn) => conn.connect());
205206
}
206207

207208
disconnectAll() {
208-
this.allConns.forEach((conn: { disconnect: () => any }) =>
209-
conn.disconnect(),
210-
);
209+
this.allConns.forEach((conn) => conn.disconnect());
211210
}
212211

213212
syncAll() {
@@ -330,32 +329,32 @@ export const compare = (users: TestYOctoInstance[]) => {
330329
// t.assert(u.store.pendingStructs === null);
331330
// }
332331
// Test Array iterator
333-
t.compare(
332+
deepEqual(
334333
users[0].getOrCreateArray("array").toArray(),
335334
Array.from(users[0].getOrCreateArray("array").iter()),
336335
);
337336
// Test Map iterator
338337
const ymapkeys: any[] = Array.from(users[0].getOrCreateMap("map").keys());
339-
t.assert(ymapkeys.length === Object.keys(userMapValues[0]).length);
338+
assert(ymapkeys.length === Object.keys(userMapValues[0]).length);
340339
ymapkeys.forEach((key) =>
341-
t.assert(object.hasProperty(userMapValues[0], key)),
340+
assert(object.hasProperty(userMapValues[0], key)),
342341
);
343342

344343
const mapRes: Record<string, any> = {};
345344
for (const [k, v] of users[0].getOrCreateMap("map").entries()) {
346345
mapRes[k] = Y.isAbstractType(v) ? v.toJSON() : v;
347346
}
348-
t.compare(userMapValues[0], mapRes);
347+
deepEqual(userMapValues[0], mapRes);
349348
// Compare all users
350349
for (let i = 0; i < users.length - 1; i++) {
351-
t.compare(
350+
deepEqual(
352351
userArrayValues[i].length,
353352
users[i].getOrCreateArray("array").length,
354353
);
355-
t.compare(userArrayValues[i], userArrayValues[i + 1]);
356-
t.compare(userMapValues[i], userMapValues[i + 1]);
357-
// t.compare(userXmlValues[i], userXmlValues[i + 1]);
358-
// t.compare(
354+
deepEqual(userArrayValues[i], userArrayValues[i + 1]);
355+
deepEqual(userMapValues[i], userMapValues[i + 1]);
356+
// deepEqual(userXmlValues[i], userXmlValues[i + 1]);
357+
// deepEqual(
359358
// userTextValues[i]
360359
// .map(
361360
// /** @param {any} a */ (a: { insert: any }) =>
@@ -364,26 +363,26 @@ export const compare = (users: TestYOctoInstance[]) => {
364363
// .join("").length,
365364
// users[i].getOrCreateText("text").length,
366365
// );
367-
// t.compare(
366+
// deepEqual(
368367
// userTextValues[i],
369368
// userTextValues[i + 1],
370369
// "",
371370
// (_constructor, a, b) => {
372371
// if (Y.isAbstractType(a)) {
373-
// t.compare(a.toJSON(), b.toJSON());
372+
// deepEqual(a.toJSON(), b.toJSON());
374373
// } else if (a !== b) {
375374
// t.fail("Deltas dont match");
376375
// }
377376
// return true;
378377
// },
379378
// );
380-
t.compare(Y.encodeStateVector(users[i]), Y.encodeStateVector(users[i + 1]));
379+
deepEqual(Y.encodeStateVector(users[i]), Y.encodeStateVector(users[i + 1]));
381380
Y.equalDeleteSets(
382381
Y.createDeleteSetFromStructStore(users[i].store),
383382
Y.createDeleteSetFromStructStore(users[i + 1].store),
384383
);
385384
Y.compareStructStores(users[i].store, users[i + 1].store);
386-
t.compare(
385+
deepEqual(
387386
Y.encodeSnapshot(Y.snapshot(users[i])),
388387
Y.encodeSnapshot(Y.snapshot(users[i + 1])),
389388
);

y-octo-node/tests/yjs/y-map.spec.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,16 @@ test.beforeEach(() => {
1414
gen = prng.create(randomInt(0, 0xffffffff));
1515
});
1616

17-
test.skip("testIterators", (t) => {
17+
test("testIterators", (t) => {
1818
const ydoc = new Y.Doc();
1919
const ymap = ydoc.createMap();
2020
// we are only checking if the type assumptions are correct
2121
const vals = Array.from(ymap.values());
2222
const entries = Array.from(ymap.entries());
2323
const keys = Array.from(ymap.keys());
24-
console.log(vals, entries, keys);
24+
t.is(vals.length, 0);
25+
t.is(entries.length, 0);
26+
t.is(keys.length, 0);
2527
});
2628

2729
/**
@@ -30,22 +32,20 @@ test.skip("testIterators", (t) => {
3032
test.skip("testMapEventError", (t) => {
3133
const doc = new Y.Doc();
3234
const ymap = doc.createMap();
33-
/**
34-
* @type {any}
35-
*/
35+
3636
let event: any = null;
3737
ymap.observe((e) => {
3838
event = e;
3939
});
40-
t.fails(() => {
40+
t.throws(() => {
4141
t.info(event.keys);
4242
});
43-
t.fails(() => {
43+
t.throws(() => {
4444
t.info(event.keys);
4545
});
4646
});
4747

48-
test.skip("testMapHavingIterableAsConstructorParamTests", (t) => {
48+
test("testMapHavingIterableAsConstructorParamTests", (t) => {
4949
const { users, map0 } = init(gen, { users: 1 });
5050

5151
const m1 = users[0].createMap(Object.entries({ number: 1, string: "hello" }));
@@ -58,14 +58,14 @@ test.skip("testMapHavingIterableAsConstructorParamTests", (t) => {
5858
["boolean", true],
5959
]);
6060
map0.set("m2", m2);
61-
t.assert(m2.get("object").x === 1);
61+
t.assert(m2.get<any>("object").x === 1);
6262
t.assert(m2.get("boolean") === true);
6363

64-
const m3 = users[0].createMap([...m1, ...m2]);
64+
const m3 = users[0].createMap([...m1.entries(), ...m2.entries()]);
6565
map0.set("m3", m3);
6666
t.assert(m3.get("number") === 1);
6767
t.assert(m3.get("string") === "hello");
68-
t.assert(m3.get("object").x === 1);
68+
t.assert(m3.get<any>("object").x === 1);
6969
t.assert(m3.get("boolean") === true);
7070
});
7171

@@ -195,8 +195,8 @@ test.skip("testGetAndSetOfMapProperty", (t) => {
195195
test.skip("testYmapSetsYmap", (t) => {
196196
const { users, map0 } = init(gen, { users: 2 });
197197

198-
const map = map0.set("Map", new Y.Map());
199-
t.assert(map0.get("Map") === map);
198+
const map = map0.set("Map", users[0].createMap());
199+
t.assert(Y.compareIds(map0.get<Y.Map>("Map").itemId, map.itemId));
200200
map.set("one", 1);
201201
t.deepEqual(map.get("one"), 1);
202202
compare(users);
@@ -239,7 +239,7 @@ test.skip("testGetAndSetOfMapPropertyWithConflict", (t) => {
239239
compare(users);
240240
});
241241

242-
test.skip("testSizeAndDeleteOfMapProperty", (t) => {
242+
test("testSizeAndDeleteOfMapProperty", (t) => {
243243
const { map0 } = init(gen, { users: 1 });
244244

245245
map0.set("stuff", "c0");

0 commit comments

Comments
 (0)