Not sure how to clean up the database in a beforeEach()
See original GitHub issueI’m submitting a…
- Bug report
- Content update
- Process update (build, deployment, … )
Type of bug / changes
In Using after or afterEach hooks, it is recommended to clean up server/db state in beforeEach
or before
. I understand the rationale but I believe the text lacks some real use case. Here is a use case that I don’t know how to solve following the best practice.
Imagine I’m testing my own clone of github. To have a clean environment for my tests, I want Cypress to use a clean temporary user and a clean temporary repository. To avoid conflicts between multiple Cypress instances targeting the same server (e.g., multiple front-end developers testing their changes in parallel), there should be one user and one repository dedicated to each Cypress instance. This can be implemented by generating users and repositories with well-known random ids (e.g., temp-user-13432481
and temp-repo-134234
). Cleaning up the mess in the database is just a removal of temp-*
databases away.
The problem is when to clean up. If the clean up is done in a beforeEach()
as is recommended, running a test in a Cypress instance will delete the data of other Cypress instances running in parallel.
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (2 by maintainers)
Top GitHub Comments
Yes, the section does naively not really mention how this should be handled when running Cypress tests in parallel. Each specfile will run independently, so you’d likely need to create a new temp-user per specfile - make sure you do not overwrite any of the same data being generated in any other specfile that could be running.
Our team is also running into a similar scenario and would love to better understand recommendations for creating test data that can be properly cleaned up in the before / beforeEach hooks while still supporting parallel test runs. This includes unique test users as well as other data models for each user.
@amirrustam is said data initialization guide located anywhere?