Skip to content

How to wait for a full sync? (How to test PowerSync-based app?) #694

@KazimirPodolski

Description

@KazimirPodolski

I'm trying to make some integraiton tests with Vitest. Some typical scenarios:

  • Call backend API affecting some tables in Sync Rules -> expect changes downloaded to the client
  • Write some data to client tables -> expect changes uploaded to the backend (-> expect changes downloaded to the client?)

Consider a test with Vitest and PowerSync Node SDK:

test('User signs up', async ({apiClient, kylesyDb, powersyncDb}) => {
  await apiClient.signUp({email: '...'});

  // HOW TO WAIT FOR A SYNC?
  // I could only come up with something like
  // await powersyncDb.disconnectAndClear();
  // await powersyncDb.connect(connector);
  // But it's not an honest test

  expect(await db.selectFrom('user').selectAll().executeTakeFirst()).toBeDefined()
});

So, how one awaits for client Sqlite to be in full sync with backend DB?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions