msw icon indicating copy to clipboard operation
msw copied to clipboard

When running Cypress tests in Electron, MSW activation occurs after test completion, causing tests to fail

Open jolientb opened this issue 1 year ago • 0 comments

Prerequisites

Environment check

  • [X] I'm using the latest msw version
  • [X] I'm using Node.js version 18 or higher

Browsers

No response

Reproduction repository

https://github.com/jolientb/msw-cypress.git

Reproduction steps

  • Run: npx cypress open
  • Choose E2E testing
  • Choose the Electron browser
  • Click on: Start e2e Testing in Electron
  • Click on: spec.cy.ts

Current behavior

Cypress test fails in Electron browser When you run the cypress e2e test in the Electron browser for the first time the test fails, because msw is only enabled after the test has finished. When running the test again in the same session, msw is enabled on time and the test does succeed.

msw-cypress

Ps. When running the test in the chrome browser or in Electron 118 (headless) msw is enabled on time, and the test succeeds. And I tried adding an await before worker.start(), but this doesn't solve the problem.

Expected behavior

Electron browser: MSW should be enabled before test is completed When you run the cypress e2e test in the Electron browser for the first time, msw should be enabled before the test finishes and the test should succeed (just like in the Chrome browser).

jolientb avatar Mar 28 '24 14:03 jolientb