For an E2E test using Cypress we have to set chromeWebSecurity to false in order to prevent CORS issue when running requests out of the Gitlab runner against the deployed backend. Unfortunately disabling this flag also causes unexpected side-effects such as local storage and cookies not being cleared between tests, preserving state hence tests not running in isolation and even causing non-deterministic behavior depending on their order.
A possible fix was to add a beforeEach with the following content in ALL describe blocks:
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
// @ts-ignore
cy.clearCookies({ domain: null });
cy.clearLocalStorage();
Not only is this causing the tests to run longer, but having to manually add those multiple times across a single file is really cumbersome and prone to errors. Finally the first line is a hack as the domain option isn't documented and only internally available. I personally fear this option will be unavailable at some point and cause errors without a helpful error message and I really don't like to rely on internal implementation details.
Is there any other idiomatic and safe way to clean up the entire state while having chromeWebSecurity disabled?