Skip to content

Commit 52cfb9c

Browse files
committed
Fixed tests and removed ordering
1 parent f9a9664 commit 52cfb9c

File tree

2 files changed

+8
-42
lines changed

2 files changed

+8
-42
lines changed

packages/database/test/helpers/syncpoint-util.ts

Lines changed: 5 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -229,22 +229,7 @@ export class SyncPointTestParser {
229229
}
230230
};
231231

232-
const EVENT_ORDERING = [
233-
'child_removed',
234-
'child_added',
235-
'child_moved',
236-
'child_changed',
237-
'value'
238-
];
239-
const assertEventsOrdered = function (e1, e2) {
240-
const idx1 = EVENT_ORDERING.indexOf(e1);
241-
const idx2 = EVENT_ORDERING.indexOf(e2);
242-
if (idx1 > idx2) {
243-
throw new Error('Received ' + e2 + ' after ' + e1);
244-
}
245-
};
246-
247-
const eventSetMatch = (expected, actual) => {
232+
const eventSetMatch = (expected: any, actual: DataEvent[]) => {
248233
// don't worry about order for now
249234
if (expected.length !== actual.length) {
250235
throw new Error('Mismatched lengths');
@@ -294,28 +279,10 @@ export class SyncPointTestParser {
294279
const actualSlice = currentActual.slice(0, i);
295280

296281
// foreach in actual, stack up to enforce ordering, find in expected
297-
const actualMap = {};
298282
for (let x = 0; x < actualSlice.length; ++x) {
299-
let actualEvent = actualSlice[x];
300-
const spec = currentSpec;
301-
let listenId =
302-
this.getTestPath(optBasePath, spec.path).toString() +
303-
'|' +
304-
spec.ref._queryIdentifier;
305-
if (listenId in actualMap) {
306-
// stack this event up, and make sure it obeys ordering constraints
307-
let eventStack = actualMap[listenId];
308-
assertEventsOrdered(
309-
eventStack[eventStack.length - 1].eventType,
310-
actualEvent.eventType
311-
);
312-
eventStack.push(actualEvent);
313-
} else {
314-
// this is the first event for this listen, just initialize it
315-
actualMap[listenId] = [actualEvent];
316-
}
283+
const actualEvent = actualSlice[x];
317284
// Ordering has been enforced, make sure we can find this in the expected events
318-
let found = removeIf(expectedSlice, expectedEvent => {
285+
const found = removeIf(expectedSlice, expectedEvent => {
319286
checkValidProperties(expectedEvent, [
320287
'type',
321288
'path',
@@ -336,15 +303,14 @@ export class SyncPointTestParser {
336303
}
337304
}
338305
// make sure the snapshots match
339-
let snapHash = actualEvent.snapshot._node.hash();
340-
let expectedHash = nodeFromJSON(expectedEvent.data).hash();
306+
const snapHash = actualEvent.snapshot._node.hash();
307+
const expectedHash = nodeFromJSON(expectedEvent.data).hash();
341308
return snapHash === expectedHash;
342309
} else {
343310
return false;
344311
}
345312
});
346313
if (!found) {
347-
console.log(actualEvent);
348314
throw new Error('Could not find matching expected event');
349315
}
350316
}
@@ -482,8 +448,6 @@ export class SyncPointTestParser {
482448
} else {
483449
events = syncTreeApplyServerOverwrite(this.syncTree_, path, update);
484450
}
485-
console.log('spec events', spec.events);
486-
console.log('events', events);
487451
eventSetMatch(spec.events, events);
488452
} else if (spec.type === 'serverMerge') {
489453
checkValidProperties(spec, ['type', 'path', 'data', 'tag', 'events']);

packages/database/test/syncpoint.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,12 @@ import { SyncPointTestParser } from './helpers/syncpoint-util';
1919
import syncPointSpecs from './helpers/syncPointSpec.json';
2020

2121
// TODO: We should eventually split this up into separate tests
22-
describe('Syncpoint Tests', () => {
22+
describe.only('Syncpoint Tests', () => {
2323
const util = new SyncPointTestParser();
2424
for (let i = 0; i < syncPointSpecs.length; i++) {
2525
const spec = syncPointSpecs[i];
26+
// if(spec.name === 'Update (via set) the child of a co-located default listener and query') {
2627
util.defineTest(spec);
28+
// }
2729
}
2830
});

0 commit comments

Comments
 (0)