From 7a362ab8438d390efa4c24e6a6d2999d35b3d463 Mon Sep 17 00:00:00 2001 From: James Woodall Date: Thu, 22 Dec 2022 21:50:36 +0100 Subject: [PATCH] Fixed "Cypress stops after 3 tests in Storybook" When running in Storybook, after 3 tests, Cypress will hang on "loading iframe.html". By ensuring that the EventSource is closed `onbeforeunload`, this fixes the issue. --- gatsby.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/gatsby.js b/gatsby.js index ff65ec9..4bd2307 100644 --- a/gatsby.js +++ b/gatsby.js @@ -37,6 +37,12 @@ Cypress.on('window:load', (win) => { break; } }); + + win.onbeforeunload = () => { + // Ensure that the source is closed if the window is unloaded + console.debug(LOG_TAG, `Close the HMR Connection`); + source.close(); + } }); function getUrl() {