laika icon indicating copy to clipboard operation
laika copied to clipboard

Cleanup all interceptors - reset laika state

Open Wozniaxos opened this issue 2 years ago • 4 comments

Hi, do you plan to expose some cleanup function that can be run per test - basically resetting whole laika state to the fresh one? To allow to have each test completely separated from another. I've tried intercepting the same operation per test but it seems that it does not want to work. Reusing the same subscription across the tests also didn't work. I've did workaround that every cypress component test mounts component the new unique 'clientName' for laika is generated and used to create link but it does not sound as a perfect solution.

Edit: I've looked at the source code and the reason i guess is that laika is memoized, so i guess i get no new singleton per test when new apolloClient is created, maybe it could be optional? some prop like alwaysCreateNewInstance or testMode skipMemoisation

Wozniaxos avatar Jul 18 '23 12:07 Wozniaxos

+1

For now I used laika.behaviors.clear() as a hacky workaround

danielvanmil avatar Jun 24 '24 13:06 danielvanmil

Sounds like a good idea. I don't have time right now to work on this, but we're open to PRs.

niieani avatar Jul 12 '24 17:07 niieani

@Wozniaxos Are you guys having problems because of this behavior? We are experiencing the problem that sometimes the intercepting does not work. But often only for one browser (a random browser). Then the requests will be simply passed through, instead of returning the mocked data.

Surprisingly this also only happens in UI mode or in our CI. Running the tests locally with npx playwright test works all the time.

krechtern avatar Jul 15 '24 13:07 krechtern

@krechtern i don't remember exact issues - it was quote time ago. As far as i remember the laika.intercept({ clientName, operationName, variables }) couldn't be used second time for the same variables - it was problematic since we wanted to intercept with different subscriptions updates in different tests. Anyway, MSW finally supports websockets, so we are moving into that direction.

Wozniaxos avatar Jul 15 '24 13:07 Wozniaxos