Svish / cypress-hmr-restarter

A Cypress plugin which restarts tests on webpack-dev-server HMR updates
22 stars 6 forks source link

How do I get this working with Storybook? #19

Open Sawtaytoes opened 3 years ago

Sawtaytoes commented 3 years ago

Storybook is using Webpack Dev Server (or Express middleware) internally, but I'm not sure I have access to change it to WebSockets.

Based on your work with Gatsby, is there a way to get Storybook to work with this plugin as well?

Svish commented 3 years ago

No clue, sorry. The Gatsby variant was a PR from someone else. If you're able to figure out how to make this work with Storybook, feel free to make a PR and I'll check it out.

amannn commented 2 years ago

I'm currently using this approach in Storybook which seems to work:

Cypress.on('window:before:load', window => {
  const originalFetch = window.fetch;
  window.fetch = (request, ...rest) => {
    const url = typeof request === 'string' ? request : request.url;

    if (url.endsWith('hot-update.json')) {
      cy.$$('.stop', window.top.document).click();
      cy.$$('.restart', window.top.document).click();
    }

    return originalFetch(request, ...rest);
  };
});

Not sure if @Svish has some ideas on how to improve this based on the other code in this library? Potentially we could add it as a new entry point to this library as well.