How to e2e test multiple client synchronization?

412 Views Asked by At

I am writing e2e tests where I want to test that when I add an entity on one client, the other online client will be synced and see the added entity. (Think google docs when you type and the words appear on the other users' screens).

My question is: how can I e2e test client synchronization through WebSockets?

Should I mock WebSockets if possible? Should I find an e2e framework that allows multiple tabs/ browser instances and test that the clients sync like that? Is there another way?

I have looked at applications that also use synchronization like these: https://github.com/automerge/trellis/blob/master/test/application.js and https://github.com/automerge/pixelpusher. Unfortunately, they either don't have tests or don't use WebSockets.

1

There are 1 best solutions below

1
On

I think the simplest way would be to start two tests simultaneously like this:

create a new script entry in the scripts section of the package.json file:

"scripts" : {
  "testcafe": testcafe chrome,   
  "test-synchro": npm run testcafe -- test1.js & npm run testcafe -- test2.js

}

in test1.js you add one entity then create a json file that contains all information on the new entity.

in test2.js you wait for this file to be present and stable in the file system and then you act on it. Maybe you could use package wait-on to achieve this.