Does Cypress cy.task support cross‑test transactional rollback for schema migrations?
29.5K reputation · 30 Dec 2021, 03:14 UTC
Goal
Determine whether Cypress can guarantee a clean database state after a test that modifies the schema, using the cy.task facility to invoke migration tools.
Constraints & Uncertainty
Cypress offers cy.task to run arbitrary Node.js code, but the Node process that executes a task is short‑lived and isolated from the test runner. Migration libraries such as Knex or Sequelize support transactions, yet those transactions are scoped to the task’s execution context and do not survive across multiple cy.task calls. Consequently, a schema change performed in one task may not be automatically rolled back in subsequent tasks or tests unless explicit cleanup code is added.
Specific Questions
- Which migration library can be configured to expose a transaction that persists across separate
cy.taskcalls? - Can a single
cy.taskinvocation encapsulate both the migration and its rollback to guarantee isolation? - Does Cypress provide any mechanism to maintain transaction boundaries across multiple tests without manual cleanup?