diff --git a/packages/core/__e2e__/sync.test.js b/packages/core/__e2e__/sync.test.js index c3ddddf3e..56c3f2593 100644 --- a/packages/core/__e2e__/sync.test.js +++ b/packages/core/__e2e__/sync.test.js @@ -32,7 +32,7 @@ const TEST_TIMEOUT = 30 * 1000; test( "case 1: device A & B should only download the changes from device C (no uploading)", - async () => { + async (t) => { const types = []; function onSyncProgress({ type }) { types.push(type); @@ -44,31 +44,38 @@ test( initializeDevice("deviceC") ]); + t.onTestFinished(async () => { + console.log(`${t.task.name} log out`); + await cleanup(deviceA, deviceB, deviceC); + }); + deviceA.eventManager.subscribe(EVENTS.syncProgress, onSyncProgress); deviceB.eventManager.subscribe(EVENTS.syncProgress, onSyncProgress); await deviceC.notes.add({ title: "new note 1" }); - await deviceC.sync(true); - await deviceA.sync(true); - await deviceB.sync(true); + await deviceC.sync({ type: "full" }); + await deviceA.sync({ type: "full" }); + await deviceB.sync({ type: "full" }); expect(types.every((t) => t === "download")).toBe(true); - - console.log("Case 1 log out"); - await cleanup(deviceA, deviceB, deviceC); }, TEST_TIMEOUT ); test( "case 3: Device A & B have unsynced changes but server has nothing", - async () => { + async (t) => { const [deviceA, deviceB] = await Promise.all([ initializeDevice("deviceA"), initializeDevice("deviceB") ]); + t.onTestFinished(async (r) => { + console.log(`${t.task.name} log out`); + await cleanup(deviceA, deviceB); + }); + const note1Id = await deviceA.notes.add({ title: "Test note from device A" }); @@ -77,15 +84,13 @@ test( }); await syncAndWait(deviceA, deviceB); - await deviceA.sync(true); + await deviceA.sync({ type: "fetch" }); + console.log(note2Id, note1Id); expect(await deviceA.notes.note(note2Id)).toBeTruthy(); expect(await deviceB.notes.note(note1Id)).toBeTruthy(); expect(await deviceA.notes.note(note1Id)).toBeTruthy(); expect(await deviceB.notes.note(note2Id)).toBeTruthy(); - - console.log("Case 3 log out"); - await cleanup(deviceA, deviceB); }, TEST_TIMEOUT ); @@ -217,12 +222,17 @@ test( test( "issue: running force sync from device A makes device B always download everything", - async () => { + async (t) => { const [deviceA, deviceB] = await Promise.all([ initializeDevice("deviceA"), initializeDevice("deviceB") ]); + t.onTestFinished(async () => { + console.log(`${t.task.name} log out`); + await cleanup(deviceA, deviceB); + }); + for (let i = 0; i < 3; ++i) { await deviceA.notes.add({ content: { @@ -240,21 +250,23 @@ test( await deviceB.sync({ type: "full" }); expect(handler).not.toHaveBeenCalled(); - - console.log("issue force sync log out"); - await cleanup(deviceA, deviceB); }, TEST_TIMEOUT ); test( "issue: colors are not properly created if multiple notes are synced together", - async () => { + async (t) => { const [deviceA, deviceB] = await Promise.all([ initializeDevice("deviceA", [CHECK_IDS.noteColor]), initializeDevice("deviceB", [CHECK_IDS.noteColor]) ]); + t.onTestFinished(async () => { + console.log(`${t.task.name} log out`); + await cleanup(deviceA, deviceB); + }); + const noteIds = []; for (let i = 0; i < 3; ++i) { const id = await deviceA.notes.add({ @@ -295,9 +307,6 @@ test( expect( noteIds.every((id) => purpleNotes.findIndex((p) => p.id === id) > -1) ).toBe(true); - - console.log("issue colors log out"); - await cleanup(deviceA, deviceB); }, TEST_TIMEOUT ); @@ -359,6 +368,7 @@ async function cleanup(...devices) { await device.syncer.stop(); await device.user.logout(); device.eventManager.unsubscribeAll(); + await device.reset(); } EV.unsubscribeAll(); } @@ -382,6 +392,7 @@ function syncAndWait(deviceA, deviceB, force = false) { type: full ? "full" : "send", force }) + .then(resolve) .catch(reject); } );