Skip to content

Commit

Permalink
Use Cypress event listener for beforeunload globally (#38264)
Browse files Browse the repository at this point in the history
  • Loading branch information
nemanjaglumac authored and sloansparger committed Feb 5, 2024
1 parent 38ac89a commit d608d0c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 21 deletions.
21 changes: 21 additions & 0 deletions e2e/support/cypress.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,24 @@ Cypress.on("test:after:run", (test, runnable) => {
);
}
});

/**
* Our app registers beforeunload event listener e.g. when editing a native SQL question.
* Cypress does not automatically close the browser prompt and does not allow manually
* interacting with it (unlike with window.confirm). The test will hang forever with
* the prompt displayed and will eventually time out. We need to work around this by
* monkey-patching window.addEventListener to ignore beforeunload event handlers.
*
* @see https://github.com/cypress-io/cypress/issues/2118
*/
Cypress.on("window:load", window => {
const addEventListener = window.addEventListener;

window.addEventListener = function (event) {
if (event === "beforeunload") {
return;
}

return addEventListener.apply(this, arguments);
};
});
21 changes: 0 additions & 21 deletions e2e/test/scenarios/visualizations-tabular/pivot_tables.cy.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,27 +36,6 @@ const TEST_CASES = [
{ case: "dashboard", subject: DASHBOARD_NAME, confirmSave: false },
];

/**
* Our app registers beforeunload event listener e.g. when editing a native SQL question.
* Cypress does not automatically close the browser prompt and does not allow manually
* interacting with it (unlike with window.confirm). The test will hang forever with
* the prompt displayed and will eventually time out. We need to work around this by
* monkey-patching window.addEventListener to ignore beforeunload event handlers.
*
* @see https://github.com/cypress-io/cypress/issues/2118
*/
Cypress.on("window:load", window => {
const addEventListener = window.addEventListener;

window.addEventListener = function (event) {
if (event === "beforeunload") {
return;
}

return addEventListener.apply(this, arguments);
};
});

describe("scenarios > visualizations > pivot tables", { tags: "@slow" }, () => {
beforeEach(() => {
restore();
Expand Down

0 comments on commit d608d0c

Please sign in to comment.